mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-09-18 17:17:55 +08:00
go fmt
This commit is contained in:
@@ -3,63 +3,78 @@
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
/*
|
||||
Package flag implements command-line flag parsing.
|
||||
Package flag implements command-line flag parsing.
|
||||
|
||||
Usage:
|
||||
Usage:
|
||||
|
||||
Define flags using flag.String(), Bool(), Int(), etc.
|
||||
Define flags using flag.String(), Bool(), Int(), etc.
|
||||
|
||||
This declares an integer flag, -flagname, stored in the pointer ip, with type *int.
|
||||
import "flag"
|
||||
var ip = flag.Int("flagname", 1234, "help message for flagname")
|
||||
If you like, you can bind the flag to a variable using the Var() functions.
|
||||
var flagvar int
|
||||
func init() {
|
||||
flag.IntVar(&flagvar, "flagname", 1234, "help message for flagname")
|
||||
}
|
||||
Or you can create custom flags that satisfy the Value interface (with
|
||||
pointer receivers) and couple them to flag parsing by
|
||||
flag.Var(&flagVal, "name", "help message for flagname")
|
||||
For such flags, the default value is just the initial value of the variable.
|
||||
This declares an integer flag, -flagname, stored in the pointer ip, with type *int.
|
||||
|
||||
After all flags are defined, call
|
||||
flag.Parse()
|
||||
to parse the command line into the defined flags.
|
||||
import "flag"
|
||||
var ip = flag.Int("flagname", 1234, "help message for flagname")
|
||||
|
||||
Flags may then be used directly. If you're using the flags themselves,
|
||||
they are all pointers; if you bind to variables, they're values.
|
||||
fmt.Println("ip has value ", *ip)
|
||||
fmt.Println("flagvar has value ", flagvar)
|
||||
If you like, you can bind the flag to a variable using the Var() functions.
|
||||
|
||||
After parsing, the arguments following the flags are available as the
|
||||
slice flag.Args() or individually as flag.Arg(i).
|
||||
The arguments are indexed from 0 through flag.NArg()-1.
|
||||
var flagvar int
|
||||
func init() {
|
||||
flag.IntVar(&flagvar, "flagname", 1234, "help message for flagname")
|
||||
}
|
||||
|
||||
Command line flag syntax:
|
||||
-flag
|
||||
-flag=x
|
||||
-flag x // non-boolean flags only
|
||||
One or two minus signs may be used; they are equivalent.
|
||||
The last form is not permitted for boolean flags because the
|
||||
meaning of the command
|
||||
cmd -x *
|
||||
will change if there is a file called 0, false, etc. You must
|
||||
use the -flag=false form to turn off a boolean flag.
|
||||
Or you can create custom flags that satisfy the Value interface (with
|
||||
pointer receivers) and couple them to flag parsing by
|
||||
|
||||
Flag parsing stops just before the first non-flag argument
|
||||
("-" is a non-flag argument) or after the terminator "--".
|
||||
flag.Var(&flagVal, "name", "help message for flagname")
|
||||
|
||||
Integer flags accept 1234, 0664, 0x1234 and may be negative.
|
||||
Boolean flags may be:
|
||||
1, 0, t, f, T, F, true, false, TRUE, FALSE, True, False
|
||||
Duration flags accept any input valid for time.ParseDuration.
|
||||
For such flags, the default value is just the initial value of the variable.
|
||||
|
||||
The default set of command-line flags is controlled by
|
||||
top-level functions. The FlagSet type allows one to define
|
||||
independent sets of flags, such as to implement subcommands
|
||||
in a command-line interface. The methods of FlagSet are
|
||||
analogous to the top-level functions for the command-line
|
||||
flag set.
|
||||
After all flags are defined, call
|
||||
|
||||
flag.Parse()
|
||||
|
||||
to parse the command line into the defined flags.
|
||||
|
||||
Flags may then be used directly. If you're using the flags themselves,
|
||||
they are all pointers; if you bind to variables, they're values.
|
||||
|
||||
fmt.Println("ip has value ", *ip)
|
||||
fmt.Println("flagvar has value ", flagvar)
|
||||
|
||||
After parsing, the arguments following the flags are available as the
|
||||
slice flag.Args() or individually as flag.Arg(i).
|
||||
The arguments are indexed from 0 through flag.NArg()-1.
|
||||
|
||||
Command line flag syntax:
|
||||
|
||||
-flag
|
||||
-flag=x
|
||||
-flag x // non-boolean flags only
|
||||
|
||||
One or two minus signs may be used; they are equivalent.
|
||||
The last form is not permitted for boolean flags because the
|
||||
meaning of the command
|
||||
|
||||
cmd -x *
|
||||
|
||||
will change if there is a file called 0, false, etc. You must
|
||||
use the -flag=false form to turn off a boolean flag.
|
||||
|
||||
Flag parsing stops just before the first non-flag argument
|
||||
("-" is a non-flag argument) or after the terminator "--".
|
||||
|
||||
Integer flags accept 1234, 0664, 0x1234 and may be negative.
|
||||
Boolean flags may be:
|
||||
|
||||
1, 0, t, f, T, F, true, false, TRUE, FALSE, True, False
|
||||
|
||||
Duration flags accept any input valid for time.ParseDuration.
|
||||
|
||||
The default set of command-line flags is controlled by
|
||||
top-level functions. The FlagSet type allows one to define
|
||||
independent sets of flags, such as to implement subcommands
|
||||
in a command-line interface. The methods of FlagSet are
|
||||
analogous to the top-level functions for the command-line
|
||||
flag set.
|
||||
*/
|
||||
package fla9
|
||||
|
||||
@@ -458,8 +473,10 @@ func (f *FlagSet) PrintDefaults() {
|
||||
// a usage message showing the default settings of all defined
|
||||
// command-line flags.
|
||||
// For an integer valued flag x, the default output has the form
|
||||
//
|
||||
// -x int
|
||||
// usage-message-for-x (default 7)
|
||||
//
|
||||
// The usage message will appear on a separate line for anything but
|
||||
// a bool flag with a one-byte name. For bool flags, the type is
|
||||
// omitted and if the flag name is one byte the usage message appears
|
||||
@@ -469,8 +486,11 @@ func (f *FlagSet) PrintDefaults() {
|
||||
// string; the first such item in the message is taken to be a parameter
|
||||
// name to show in the message and the back quotes are stripped from
|
||||
// the message when displayed. For instance, given
|
||||
//
|
||||
// flag.String("I", "", "search `directory` for include files")
|
||||
//
|
||||
// the output will be
|
||||
//
|
||||
// -I directory
|
||||
// search directory for include files.
|
||||
func PrintDefaults() { CommandLine.PrintDefaults() }
|
||||
|
@@ -21,42 +21,43 @@ Be reluctant to create new nodes. Try to fit into either previous node or next n
|
||||
Prefer to add to previous node.
|
||||
|
||||
There are multiple cases after finding the name for greater or equal node
|
||||
|
||||
1. found and node.Key == name
|
||||
The node contains a batch with leading key the same as the name
|
||||
nothing to do
|
||||
|
||||
2. no such node found or node.Key > name
|
||||
|
||||
if no such node found
|
||||
prevNode = list.LargestNode
|
||||
prevNode = list.LargestNode
|
||||
|
||||
// case 2.1
|
||||
// case 2.1
|
||||
if previousNode contains name
|
||||
nothing to do
|
||||
nothing to do
|
||||
|
||||
// prefer to add to previous node
|
||||
if prevNode != nil {
|
||||
// case 2.2
|
||||
if prevNode has capacity
|
||||
prevNode.add name, and save
|
||||
return
|
||||
// case 2.3
|
||||
split prevNode by name
|
||||
// case 2.2
|
||||
if prevNode has capacity
|
||||
prevNode.add name, and save
|
||||
return
|
||||
// case 2.3
|
||||
split prevNode by name
|
||||
}
|
||||
|
||||
// case 2.4
|
||||
// merge into next node. Avoid too many nodes if adding data in reverse order.
|
||||
if nextNode is not nil and nextNode has capacity
|
||||
delete nextNode.Key
|
||||
nextNode.Key = name
|
||||
nextNode.batch.add name
|
||||
insert nodeNode.Key
|
||||
return
|
||||
// case 2.4
|
||||
// merge into next node. Avoid too many nodes if adding data in reverse order.
|
||||
if nextNode is not nil and nextNode has capacity
|
||||
delete nextNode.Key
|
||||
nextNode.Key = name
|
||||
nextNode.batch.add name
|
||||
insert nodeNode.Key
|
||||
return
|
||||
|
||||
// case 2.5
|
||||
// case 2.5
|
||||
if prevNode is nil
|
||||
insert new node with key = name, value = batch{name}
|
||||
return
|
||||
|
||||
insert new node with key = name, value = batch{name}
|
||||
return
|
||||
*/
|
||||
func (nl *NameList) WriteName(name string) error {
|
||||
|
||||
@@ -160,36 +161,45 @@ func (nl *NameList) WriteName(name string) error {
|
||||
|
||||
/*
|
||||
// case 1: exists in nextNode
|
||||
if nextNode != nil && nextNode.Key == name {
|
||||
remove from nextNode, update nextNode
|
||||
// TODO: merge with prevNode if possible?
|
||||
return
|
||||
}
|
||||
|
||||
if nextNode != nil && nextNode.Key == name {
|
||||
remove from nextNode, update nextNode
|
||||
// TODO: merge with prevNode if possible?
|
||||
return
|
||||
}
|
||||
|
||||
if nextNode is nil
|
||||
|
||||
prevNode = list.Largestnode
|
||||
|
||||
if prevNode == nil and nextNode.Prev != nil
|
||||
|
||||
prevNode = load(nextNode.Prev)
|
||||
|
||||
// case 2: does not exist
|
||||
// case 2.1
|
||||
if prevNode == nil {
|
||||
return
|
||||
}
|
||||
|
||||
if prevNode == nil {
|
||||
return
|
||||
}
|
||||
|
||||
// case 2.2
|
||||
if prevNameBatch does not contain name {
|
||||
return
|
||||
}
|
||||
|
||||
if prevNameBatch does not contain name {
|
||||
return
|
||||
}
|
||||
|
||||
// case 3
|
||||
delete from prevNameBatch
|
||||
if prevNameBatch + nextNode < capacityList
|
||||
|
||||
// case 3.1
|
||||
merge
|
||||
|
||||
else
|
||||
|
||||
// case 3.2
|
||||
update prevNode
|
||||
|
||||
|
||||
*/
|
||||
func (nl *NameList) DeleteName(name string) error {
|
||||
lookupKey := []byte(name)
|
||||
|
Reference in New Issue
Block a user