repo
stringlengths
5
67
path
stringlengths
4
218
func_name
stringlengths
0
151
original_string
stringlengths
52
373k
language
stringclasses
6 values
code
stringlengths
52
373k
code_tokens
listlengths
10
512
docstring
stringlengths
3
47.2k
docstring_tokens
listlengths
3
234
sha
stringlengths
40
40
url
stringlengths
85
339
partition
stringclasses
3 values
fcavani/text
validation.go
CleanUrl
func CleanUrl(rawurl string, min, max int) (string, error) { err := CheckUrl(rawurl, min, max) if err != nil { return "", e.Forward(err) } u, err := url.Parse(rawurl) if err != nil { return "", e.Push(e.New(ErrInvUrl), err) } if u.Scheme == "" { return u.String(), e.New(ErrNoScheme) } return u.String(), nil }
go
func CleanUrl(rawurl string, min, max int) (string, error) { err := CheckUrl(rawurl, min, max) if err != nil { return "", e.Forward(err) } u, err := url.Parse(rawurl) if err != nil { return "", e.Push(e.New(ErrInvUrl), err) } if u.Scheme == "" { return u.String(), e.New(ErrNoScheme) } return u.String(), nil }
[ "func", "CleanUrl", "(", "rawurl", "string", ",", "min", ",", "max", "int", ")", "(", "string", ",", "error", ")", "{", "err", ":=", "CheckUrl", "(", "rawurl", ",", "min", ",", "max", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"\"", ",", "e", ".", "Forward", "(", "err", ")", "\n", "}", "\n", "u", ",", "err", ":=", "url", ".", "Parse", "(", "rawurl", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"\"", ",", "e", ".", "Push", "(", "e", ".", "New", "(", "ErrInvUrl", ")", ",", "err", ")", "\n", "}", "\n", "if", "u", ".", "Scheme", "==", "\"\"", "{", "return", "u", ".", "String", "(", ")", ",", "e", ".", "New", "(", "ErrNoScheme", ")", "\n", "}", "\n", "return", "u", ".", "String", "(", ")", ",", "nil", "\n", "}" ]
// CleanUrl check the characteres in url and parser it with url.Parse. // If url is ok return one string with it or if the scheme is missing // return the url and an error.
[ "CleanUrl", "check", "the", "characteres", "in", "url", "and", "parser", "it", "with", "url", ".", "Parse", ".", "If", "url", "is", "ok", "return", "one", "string", "with", "it", "or", "if", "the", "scheme", "is", "missing", "return", "the", "url", "and", "an", "error", "." ]
023e76809b57fc8cfc80c855ba59537720821cb5
https://github.com/fcavani/text/blob/023e76809b57fc8cfc80c855ba59537720821cb5/validation.go#L193-L206
test
mota/klash
parameter.go
NewParameter
func NewParameter(name string, value reflect.Value) *Parameter { parameter := Parameter{ Name: name, Value: value, } return &parameter }
go
func NewParameter(name string, value reflect.Value) *Parameter { parameter := Parameter{ Name: name, Value: value, } return &parameter }
[ "func", "NewParameter", "(", "name", "string", ",", "value", "reflect", ".", "Value", ")", "*", "Parameter", "{", "parameter", ":=", "Parameter", "{", "Name", ":", "name", ",", "Value", ":", "value", ",", "}", "\n", "return", "&", "parameter", "\n", "}" ]
// A capacity of 2 seems to be a good guess for the number of aliases.
[ "A", "capacity", "of", "2", "seems", "to", "be", "a", "good", "guess", "for", "the", "number", "of", "aliases", "." ]
ca6c37a4c8c2e69831c428cf0c6daac80ab56c22
https://github.com/mota/klash/blob/ca6c37a4c8c2e69831c428cf0c6daac80ab56c22/parameter.go#L21-L27
test
mota/klash
params.go
MakeParams
func MakeParams(fieldCount int) *Params { return &Params{ make(map[string]*Parameter), make([]*Parameter, 0, fieldCount), } }
go
func MakeParams(fieldCount int) *Params { return &Params{ make(map[string]*Parameter), make([]*Parameter, 0, fieldCount), } }
[ "func", "MakeParams", "(", "fieldCount", "int", ")", "*", "Params", "{", "return", "&", "Params", "{", "make", "(", "map", "[", "string", "]", "*", "Parameter", ")", ",", "make", "(", "[", "]", "*", "Parameter", ",", "0", ",", "fieldCount", ")", ",", "}", "\n", "}" ]
// Params store the mapping of ParamName -> Parameter for the given structure. // Since multiple names can be affected to a single parameter, multiple // keys can be associated with a single parameter.
[ "Params", "store", "the", "mapping", "of", "ParamName", "-", ">", "Parameter", "for", "the", "given", "structure", ".", "Since", "multiple", "names", "can", "be", "affected", "to", "a", "single", "parameter", "multiple", "keys", "can", "be", "associated", "with", "a", "single", "parameter", "." ]
ca6c37a4c8c2e69831c428cf0c6daac80ab56c22
https://github.com/mota/klash/blob/ca6c37a4c8c2e69831c428cf0c6daac80ab56c22/params.go#L17-L22
test
mota/klash
params.go
Parse
func (p *Params) Parse(pvalue *reflect.Value) error { vtype := pvalue.Type().Elem() for idx := 0; idx < vtype.NumField(); idx++ { field := vtype.Field(idx) value := pvalue.Elem().Field(idx) if value.Kind() == reflect.Slice { value.Set(reflect.MakeSlice(value.Type(), 0, 0)) } parameter := NewParameter(field.Name, value) if err := parameter.DiscoverProperties(field.Tag); err != nil { return err } if err := p.Set(parameter.Name, parameter); err != nil { return err } if parameter.Alias != "" { if err := p.Set(parameter.Alias, parameter); err != nil { return err } } p.Listing = append(p.Listing, parameter) } return nil }
go
func (p *Params) Parse(pvalue *reflect.Value) error { vtype := pvalue.Type().Elem() for idx := 0; idx < vtype.NumField(); idx++ { field := vtype.Field(idx) value := pvalue.Elem().Field(idx) if value.Kind() == reflect.Slice { value.Set(reflect.MakeSlice(value.Type(), 0, 0)) } parameter := NewParameter(field.Name, value) if err := parameter.DiscoverProperties(field.Tag); err != nil { return err } if err := p.Set(parameter.Name, parameter); err != nil { return err } if parameter.Alias != "" { if err := p.Set(parameter.Alias, parameter); err != nil { return err } } p.Listing = append(p.Listing, parameter) } return nil }
[ "func", "(", "p", "*", "Params", ")", "Parse", "(", "pvalue", "*", "reflect", ".", "Value", ")", "error", "{", "vtype", ":=", "pvalue", ".", "Type", "(", ")", ".", "Elem", "(", ")", "\n", "for", "idx", ":=", "0", ";", "idx", "<", "vtype", ".", "NumField", "(", ")", ";", "idx", "++", "{", "field", ":=", "vtype", ".", "Field", "(", "idx", ")", "\n", "value", ":=", "pvalue", ".", "Elem", "(", ")", ".", "Field", "(", "idx", ")", "\n", "if", "value", ".", "Kind", "(", ")", "==", "reflect", ".", "Slice", "{", "value", ".", "Set", "(", "reflect", ".", "MakeSlice", "(", "value", ".", "Type", "(", ")", ",", "0", ",", "0", ")", ")", "\n", "}", "\n", "parameter", ":=", "NewParameter", "(", "field", ".", "Name", ",", "value", ")", "\n", "if", "err", ":=", "parameter", ".", "DiscoverProperties", "(", "field", ".", "Tag", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "err", ":=", "p", ".", "Set", "(", "parameter", ".", "Name", ",", "parameter", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "parameter", ".", "Alias", "!=", "\"\"", "{", "if", "err", ":=", "p", ".", "Set", "(", "parameter", ".", "Alias", ",", "parameter", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "p", ".", "Listing", "=", "append", "(", "p", ".", "Listing", ",", "parameter", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Parse discovers the given parameters structure and associates the structure's // field names with their values into the Params structure.
[ "Parse", "discovers", "the", "given", "parameters", "structure", "and", "associates", "the", "structure", "s", "field", "names", "with", "their", "values", "into", "the", "Params", "structure", "." ]
ca6c37a4c8c2e69831c428cf0c6daac80ab56c22
https://github.com/mota/klash/blob/ca6c37a4c8c2e69831c428cf0c6daac80ab56c22/params.go#L41-L70
test
blacksails/cgp
forwarder.go
Email
func (f Forwarder) Email() string { return fmt.Sprintf("%s@%s", f.Name, f.Domain.Name) }
go
func (f Forwarder) Email() string { return fmt.Sprintf("%s@%s", f.Name, f.Domain.Name) }
[ "func", "(", "f", "Forwarder", ")", "Email", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"%s@%s\"", ",", "f", ".", "Name", ",", "f", ".", "Domain", ".", "Name", ")", "\n", "}" ]
// Email returns the forwarder email on the primary domain
[ "Email", "returns", "the", "forwarder", "email", "on", "the", "primary", "domain" ]
570ac705cf2d7a9235d911d00b6f976ab3386c2f
https://github.com/blacksails/cgp/blob/570ac705cf2d7a9235d911d00b6f976ab3386c2f/forwarder.go#L16-L18
test
blacksails/cgp
forwarder.go
Forwarder
func (dom *Domain) Forwarder(name, to string) *Forwarder { return &Forwarder{Domain: dom, Name: name, To: to} }
go
func (dom *Domain) Forwarder(name, to string) *Forwarder { return &Forwarder{Domain: dom, Name: name, To: to} }
[ "func", "(", "dom", "*", "Domain", ")", "Forwarder", "(", "name", ",", "to", "string", ")", "*", "Forwarder", "{", "return", "&", "Forwarder", "{", "Domain", ":", "dom", ",", "Name", ":", "name", ",", "To", ":", "to", "}", "\n", "}" ]
// Forwarder returns a forwarder type with the given from and dest
[ "Forwarder", "returns", "a", "forwarder", "type", "with", "the", "given", "from", "and", "dest" ]
570ac705cf2d7a9235d911d00b6f976ab3386c2f
https://github.com/blacksails/cgp/blob/570ac705cf2d7a9235d911d00b6f976ab3386c2f/forwarder.go#L21-L23
test
blacksails/cgp
forwarder.go
Forwarders
func (dom *Domain) Forwarders() ([]*Forwarder, error) { var vl valueList err := dom.cgp.request(listForwarders{Param: dom.Name}, &vl) if err != nil { return []*Forwarder{}, err } vals := vl.compact() fs := make([]*Forwarder, len(vals)) for i, v := range vals { f, err := dom.GetForwarder(v) if err != nil { return fs, err } fs[i] = f } return fs, err }
go
func (dom *Domain) Forwarders() ([]*Forwarder, error) { var vl valueList err := dom.cgp.request(listForwarders{Param: dom.Name}, &vl) if err != nil { return []*Forwarder{}, err } vals := vl.compact() fs := make([]*Forwarder, len(vals)) for i, v := range vals { f, err := dom.GetForwarder(v) if err != nil { return fs, err } fs[i] = f } return fs, err }
[ "func", "(", "dom", "*", "Domain", ")", "Forwarders", "(", ")", "(", "[", "]", "*", "Forwarder", ",", "error", ")", "{", "var", "vl", "valueList", "\n", "err", ":=", "dom", ".", "cgp", ".", "request", "(", "listForwarders", "{", "Param", ":", "dom", ".", "Name", "}", ",", "&", "vl", ")", "\n", "if", "err", "!=", "nil", "{", "return", "[", "]", "*", "Forwarder", "{", "}", ",", "err", "\n", "}", "\n", "vals", ":=", "vl", ".", "compact", "(", ")", "\n", "fs", ":=", "make", "(", "[", "]", "*", "Forwarder", ",", "len", "(", "vals", ")", ")", "\n", "for", "i", ",", "v", ":=", "range", "vals", "{", "f", ",", "err", ":=", "dom", ".", "GetForwarder", "(", "v", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fs", ",", "err", "\n", "}", "\n", "fs", "[", "i", "]", "=", "f", "\n", "}", "\n", "return", "fs", ",", "err", "\n", "}" ]
// Forwarders lists the forwarders of a domain
[ "Forwarders", "lists", "the", "forwarders", "of", "a", "domain" ]
570ac705cf2d7a9235d911d00b6f976ab3386c2f
https://github.com/blacksails/cgp/blob/570ac705cf2d7a9235d911d00b6f976ab3386c2f/forwarder.go#L31-L47
test
blacksails/cgp
forwarder.go
GetForwarder
func (dom *Domain) GetForwarder(name string) (*Forwarder, error) { var f string err := dom.cgp.request(getForwarder{Param: fmt.Sprintf("%s@%s", name, dom.Name)}, &f) if err != nil { return &Forwarder{}, err } return &Forwarder{Domain: dom, Name: name, To: f}, nil }
go
func (dom *Domain) GetForwarder(name string) (*Forwarder, error) { var f string err := dom.cgp.request(getForwarder{Param: fmt.Sprintf("%s@%s", name, dom.Name)}, &f) if err != nil { return &Forwarder{}, err } return &Forwarder{Domain: dom, Name: name, To: f}, nil }
[ "func", "(", "dom", "*", "Domain", ")", "GetForwarder", "(", "name", "string", ")", "(", "*", "Forwarder", ",", "error", ")", "{", "var", "f", "string", "\n", "err", ":=", "dom", ".", "cgp", ".", "request", "(", "getForwarder", "{", "Param", ":", "fmt", ".", "Sprintf", "(", "\"%s@%s\"", ",", "name", ",", "dom", ".", "Name", ")", "}", ",", "&", "f", ")", "\n", "if", "err", "!=", "nil", "{", "return", "&", "Forwarder", "{", "}", ",", "err", "\n", "}", "\n", "return", "&", "Forwarder", "{", "Domain", ":", "dom", ",", "Name", ":", "name", ",", "To", ":", "f", "}", ",", "nil", "\n", "}" ]
// GetForwarder retreives a forwarder with the given name
[ "GetForwarder", "retreives", "a", "forwarder", "with", "the", "given", "name" ]
570ac705cf2d7a9235d911d00b6f976ab3386c2f
https://github.com/blacksails/cgp/blob/570ac705cf2d7a9235d911d00b6f976ab3386c2f/forwarder.go#L55-L62
test
blacksails/cgp
cgp.go
New
func New(url, user, pass string) *CGP { return &CGP{url: url, user: user, pass: pass} }
go
func New(url, user, pass string) *CGP { return &CGP{url: url, user: user, pass: pass} }
[ "func", "New", "(", "url", ",", "user", ",", "pass", "string", ")", "*", "CGP", "{", "return", "&", "CGP", "{", "url", ":", "url", ",", "user", ":", "user", ",", "pass", ":", "pass", "}", "\n", "}" ]
// New returns a new Communigate Pro client
[ "New", "returns", "a", "new", "Communigate", "Pro", "client" ]
570ac705cf2d7a9235d911d00b6f976ab3386c2f
https://github.com/blacksails/cgp/blob/570ac705cf2d7a9235d911d00b6f976ab3386c2f/cgp.go#L11-L13
test
fcavani/text
escape.go
EscapeCommaSeparated
func EscapeCommaSeparated(in ...string) string { var out string for i, str := range in { escaped := strings.Replace(url.QueryEscape(str), "%2F", "%252F", -1) escaped = strings.Replace(escaped, "\"", "%22", -1) escaped = strings.Replace(escaped, " ", "%20", -1) out += escaped if i < len(in)-1 { out += "," } } return out }
go
func EscapeCommaSeparated(in ...string) string { var out string for i, str := range in { escaped := strings.Replace(url.QueryEscape(str), "%2F", "%252F", -1) escaped = strings.Replace(escaped, "\"", "%22", -1) escaped = strings.Replace(escaped, " ", "%20", -1) out += escaped if i < len(in)-1 { out += "," } } return out }
[ "func", "EscapeCommaSeparated", "(", "in", "...", "string", ")", "string", "{", "var", "out", "string", "\n", "for", "i", ",", "str", ":=", "range", "in", "{", "escaped", ":=", "strings", ".", "Replace", "(", "url", ".", "QueryEscape", "(", "str", ")", ",", "\"%2F\"", ",", "\"%252F\"", ",", "-", "1", ")", "\n", "escaped", "=", "strings", ".", "Replace", "(", "escaped", ",", "\"\\\"\"", ",", "\\\"", ",", "\"%22\"", ")", "\n", "-", "1", "\n", "escaped", "=", "strings", ".", "Replace", "(", "escaped", ",", "\" \"", ",", "\"%20\"", ",", "-", "1", ")", "\n", "out", "+=", "escaped", "\n", "}", "\n", "if", "i", "<", "len", "(", "in", ")", "-", "1", "{", "out", "+=", "\",\"", "\n", "}", "\n", "}" ]
//EscapeCommaSeparated escapes the args and make a comma separeted list with it.
[ "EscapeCommaSeparated", "escapes", "the", "args", "and", "make", "a", "comma", "separeted", "list", "with", "it", "." ]
023e76809b57fc8cfc80c855ba59537720821cb5
https://github.com/fcavani/text/blob/023e76809b57fc8cfc80c855ba59537720821cb5/escape.go#L15-L27
test
blacksails/cgp
alias.go
Alias
func (acc *Account) Alias(name string) *Alias { return &Alias{account: acc, Name: name} }
go
func (acc *Account) Alias(name string) *Alias { return &Alias{account: acc, Name: name} }
[ "func", "(", "acc", "*", "Account", ")", "Alias", "(", "name", "string", ")", "*", "Alias", "{", "return", "&", "Alias", "{", "account", ":", "acc", ",", "Name", ":", "name", "}", "\n", "}" ]
// Alias creates an Alias type from an account
[ "Alias", "creates", "an", "Alias", "type", "from", "an", "account" ]
570ac705cf2d7a9235d911d00b6f976ab3386c2f
https://github.com/blacksails/cgp/blob/570ac705cf2d7a9235d911d00b6f976ab3386c2f/alias.go#L15-L17
test
blacksails/cgp
alias.go
Email
func (a Alias) Email() string { return fmt.Sprintf("%s@%s", a.Name, a.account.Domain.Name) }
go
func (a Alias) Email() string { return fmt.Sprintf("%s@%s", a.Name, a.account.Domain.Name) }
[ "func", "(", "a", "Alias", ")", "Email", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"%s@%s\"", ",", "a", ".", "Name", ",", "a", ".", "account", ".", "Domain", ".", "Name", ")", "\n", "}" ]
// Email returns the alias email on the primary domain name
[ "Email", "returns", "the", "alias", "email", "on", "the", "primary", "domain", "name" ]
570ac705cf2d7a9235d911d00b6f976ab3386c2f
https://github.com/blacksails/cgp/blob/570ac705cf2d7a9235d911d00b6f976ab3386c2f/alias.go#L20-L22
test
blacksails/cgp
alias.go
Aliases
func (acc *Account) Aliases() ([]*Alias, error) { var vl valueList err := acc.Domain.cgp.request(listAliases{Param: fmt.Sprintf("%s@%s", acc.Name, acc.Domain.Name)}, &vl) if err != nil { return []*Alias{}, err } vals := vl.compact() as := make([]*Alias, len(vals)) for i, v := range vals { as[i] = acc.Alias(v) } return as, nil }
go
func (acc *Account) Aliases() ([]*Alias, error) { var vl valueList err := acc.Domain.cgp.request(listAliases{Param: fmt.Sprintf("%s@%s", acc.Name, acc.Domain.Name)}, &vl) if err != nil { return []*Alias{}, err } vals := vl.compact() as := make([]*Alias, len(vals)) for i, v := range vals { as[i] = acc.Alias(v) } return as, nil }
[ "func", "(", "acc", "*", "Account", ")", "Aliases", "(", ")", "(", "[", "]", "*", "Alias", ",", "error", ")", "{", "var", "vl", "valueList", "\n", "err", ":=", "acc", ".", "Domain", ".", "cgp", ".", "request", "(", "listAliases", "{", "Param", ":", "fmt", ".", "Sprintf", "(", "\"%s@%s\"", ",", "acc", ".", "Name", ",", "acc", ".", "Domain", ".", "Name", ")", "}", ",", "&", "vl", ")", "\n", "if", "err", "!=", "nil", "{", "return", "[", "]", "*", "Alias", "{", "}", ",", "err", "\n", "}", "\n", "vals", ":=", "vl", ".", "compact", "(", ")", "\n", "as", ":=", "make", "(", "[", "]", "*", "Alias", ",", "len", "(", "vals", ")", ")", "\n", "for", "i", ",", "v", ":=", "range", "vals", "{", "as", "[", "i", "]", "=", "acc", ".", "Alias", "(", "v", ")", "\n", "}", "\n", "return", "as", ",", "nil", "\n", "}" ]
// Aliases lists the aliases of an account
[ "Aliases", "lists", "the", "aliases", "of", "an", "account" ]
570ac705cf2d7a9235d911d00b6f976ab3386c2f
https://github.com/blacksails/cgp/blob/570ac705cf2d7a9235d911d00b6f976ab3386c2f/alias.go#L30-L42
test
blacksails/cgp
account.go
RealName
func (a Account) RealName() (string, error) { var d dictionary err := a.Domain.cgp.request(getAccountSettings{Account: a.Email()}, &d) if err != nil { return "", err } return d.toMap()["RealName"], nil }
go
func (a Account) RealName() (string, error) { var d dictionary err := a.Domain.cgp.request(getAccountSettings{Account: a.Email()}, &d) if err != nil { return "", err } return d.toMap()["RealName"], nil }
[ "func", "(", "a", "Account", ")", "RealName", "(", ")", "(", "string", ",", "error", ")", "{", "var", "d", "dictionary", "\n", "err", ":=", "a", ".", "Domain", ".", "cgp", ".", "request", "(", "getAccountSettings", "{", "Account", ":", "a", ".", "Email", "(", ")", "}", ",", "&", "d", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"\"", ",", "err", "\n", "}", "\n", "return", "d", ".", "toMap", "(", ")", "[", "\"RealName\"", "]", ",", "nil", "\n", "}" ]
// RealName return the real name of the account as registered
[ "RealName", "return", "the", "real", "name", "of", "the", "account", "as", "registered" ]
570ac705cf2d7a9235d911d00b6f976ab3386c2f
https://github.com/blacksails/cgp/blob/570ac705cf2d7a9235d911d00b6f976ab3386c2f/account.go#L20-L27
test
blacksails/cgp
account.go
Email
func (a Account) Email() string { return fmt.Sprintf("%s@%s", a.Name, a.Domain.Name) }
go
func (a Account) Email() string { return fmt.Sprintf("%s@%s", a.Name, a.Domain.Name) }
[ "func", "(", "a", "Account", ")", "Email", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"%s@%s\"", ",", "a", ".", "Name", ",", "a", ".", "Domain", ".", "Name", ")", "\n", "}" ]
// Email returns the primary email of the account
[ "Email", "returns", "the", "primary", "email", "of", "the", "account" ]
570ac705cf2d7a9235d911d00b6f976ab3386c2f
https://github.com/blacksails/cgp/blob/570ac705cf2d7a9235d911d00b6f976ab3386c2f/account.go#L30-L32
test
blacksails/cgp
account.go
Account
func (dom *Domain) Account(name string) *Account { return &Account{Domain: dom, Name: name} }
go
func (dom *Domain) Account(name string) *Account { return &Account{Domain: dom, Name: name} }
[ "func", "(", "dom", "*", "Domain", ")", "Account", "(", "name", "string", ")", "*", "Account", "{", "return", "&", "Account", "{", "Domain", ":", "dom", ",", "Name", ":", "name", "}", "\n", "}" ]
// Account returns an account type with the given name
[ "Account", "returns", "an", "account", "type", "with", "the", "given", "name" ]
570ac705cf2d7a9235d911d00b6f976ab3386c2f
https://github.com/blacksails/cgp/blob/570ac705cf2d7a9235d911d00b6f976ab3386c2f/account.go#L35-L37
test
blacksails/cgp
account.go
Accounts
func (dom *Domain) Accounts() ([]*Account, error) { var al accountList err := dom.cgp.request(listAccounts{Domain: dom.Name}, &al) if err != nil { return []*Account{}, err } keys := al.SubKeys as := make([]*Account, len(keys)) for i, k := range keys { as[i] = dom.Account(k.Name) } return as, nil }
go
func (dom *Domain) Accounts() ([]*Account, error) { var al accountList err := dom.cgp.request(listAccounts{Domain: dom.Name}, &al) if err != nil { return []*Account{}, err } keys := al.SubKeys as := make([]*Account, len(keys)) for i, k := range keys { as[i] = dom.Account(k.Name) } return as, nil }
[ "func", "(", "dom", "*", "Domain", ")", "Accounts", "(", ")", "(", "[", "]", "*", "Account", ",", "error", ")", "{", "var", "al", "accountList", "\n", "err", ":=", "dom", ".", "cgp", ".", "request", "(", "listAccounts", "{", "Domain", ":", "dom", ".", "Name", "}", ",", "&", "al", ")", "\n", "if", "err", "!=", "nil", "{", "return", "[", "]", "*", "Account", "{", "}", ",", "err", "\n", "}", "\n", "keys", ":=", "al", ".", "SubKeys", "\n", "as", ":=", "make", "(", "[", "]", "*", "Account", ",", "len", "(", "keys", ")", ")", "\n", "for", "i", ",", "k", ":=", "range", "keys", "{", "as", "[", "i", "]", "=", "dom", ".", "Account", "(", "k", ".", "Name", ")", "\n", "}", "\n", "return", "as", ",", "nil", "\n", "}" ]
// Accounts lists the acounts of a domain
[ "Accounts", "lists", "the", "acounts", "of", "a", "domain" ]
570ac705cf2d7a9235d911d00b6f976ab3386c2f
https://github.com/blacksails/cgp/blob/570ac705cf2d7a9235d911d00b6f976ab3386c2f/account.go#L53-L65
test
blacksails/cgp
domain.go
Exists
func (dom Domain) Exists() (bool, error) { var d dictionary err := dom.cgp.request(getDomainSettings{Domain: dom.Name}, &d) if _, ok := err.(SOAPNotFoundError); ok { return false, nil } if err != nil { return false, err } return true, nil }
go
func (dom Domain) Exists() (bool, error) { var d dictionary err := dom.cgp.request(getDomainSettings{Domain: dom.Name}, &d) if _, ok := err.(SOAPNotFoundError); ok { return false, nil } if err != nil { return false, err } return true, nil }
[ "func", "(", "dom", "Domain", ")", "Exists", "(", ")", "(", "bool", ",", "error", ")", "{", "var", "d", "dictionary", "\n", "err", ":=", "dom", ".", "cgp", ".", "request", "(", "getDomainSettings", "{", "Domain", ":", "dom", ".", "Name", "}", ",", "&", "d", ")", "\n", "if", "_", ",", "ok", ":=", "err", ".", "(", "SOAPNotFoundError", ")", ";", "ok", "{", "return", "false", ",", "nil", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n", "return", "true", ",", "nil", "\n", "}" ]
// Exists returns true if the domain
[ "Exists", "returns", "true", "if", "the", "domain" ]
570ac705cf2d7a9235d911d00b6f976ab3386c2f
https://github.com/blacksails/cgp/blob/570ac705cf2d7a9235d911d00b6f976ab3386c2f/domain.go#L17-L27
test
blacksails/cgp
domain.go
Aliases
func (dom Domain) Aliases() ([]string, error) { var vl valueList err := dom.cgp.request(getDomainAliases{Domain: dom.Name}, &vl) if err != nil { return []string{}, err } return vl.compact(), nil }
go
func (dom Domain) Aliases() ([]string, error) { var vl valueList err := dom.cgp.request(getDomainAliases{Domain: dom.Name}, &vl) if err != nil { return []string{}, err } return vl.compact(), nil }
[ "func", "(", "dom", "Domain", ")", "Aliases", "(", ")", "(", "[", "]", "string", ",", "error", ")", "{", "var", "vl", "valueList", "\n", "err", ":=", "dom", ".", "cgp", ".", "request", "(", "getDomainAliases", "{", "Domain", ":", "dom", ".", "Name", "}", ",", "&", "vl", ")", "\n", "if", "err", "!=", "nil", "{", "return", "[", "]", "string", "{", "}", ",", "err", "\n", "}", "\n", "return", "vl", ".", "compact", "(", ")", ",", "nil", "\n", "}" ]
// Aliases returns a list of domain aliases
[ "Aliases", "returns", "a", "list", "of", "domain", "aliases" ]
570ac705cf2d7a9235d911d00b6f976ab3386c2f
https://github.com/blacksails/cgp/blob/570ac705cf2d7a9235d911d00b6f976ab3386c2f/domain.go#L35-L42
test
blacksails/cgp
domain.go
Domain
func (cgp *CGP) Domain(name string) *Domain { return &Domain{cgp: cgp, Name: name} }
go
func (cgp *CGP) Domain(name string) *Domain { return &Domain{cgp: cgp, Name: name} }
[ "func", "(", "cgp", "*", "CGP", ")", "Domain", "(", "name", "string", ")", "*", "Domain", "{", "return", "&", "Domain", "{", "cgp", ":", "cgp", ",", "Name", ":", "name", "}", "\n", "}" ]
// Domain creates a domain type with the given name
[ "Domain", "creates", "a", "domain", "type", "with", "the", "given", "name" ]
570ac705cf2d7a9235d911d00b6f976ab3386c2f
https://github.com/blacksails/cgp/blob/570ac705cf2d7a9235d911d00b6f976ab3386c2f/domain.go#L49-L51
test
blacksails/cgp
domain.go
Domains
func (cgp *CGP) Domains() ([]*Domain, error) { var vl valueList err := cgp.request(listDomains{}, &vl) if err != nil { return []*Domain{}, err } vals := vl.SubValues ds := make([]*Domain, len(vals)) for i, d := range vals { ds[i] = cgp.Domain(d) } return ds, nil }
go
func (cgp *CGP) Domains() ([]*Domain, error) { var vl valueList err := cgp.request(listDomains{}, &vl) if err != nil { return []*Domain{}, err } vals := vl.SubValues ds := make([]*Domain, len(vals)) for i, d := range vals { ds[i] = cgp.Domain(d) } return ds, nil }
[ "func", "(", "cgp", "*", "CGP", ")", "Domains", "(", ")", "(", "[", "]", "*", "Domain", ",", "error", ")", "{", "var", "vl", "valueList", "\n", "err", ":=", "cgp", ".", "request", "(", "listDomains", "{", "}", ",", "&", "vl", ")", "\n", "if", "err", "!=", "nil", "{", "return", "[", "]", "*", "Domain", "{", "}", ",", "err", "\n", "}", "\n", "vals", ":=", "vl", ".", "SubValues", "\n", "ds", ":=", "make", "(", "[", "]", "*", "Domain", ",", "len", "(", "vals", ")", ")", "\n", "for", "i", ",", "d", ":=", "range", "vals", "{", "ds", "[", "i", "]", "=", "cgp", ".", "Domain", "(", "d", ")", "\n", "}", "\n", "return", "ds", ",", "nil", "\n", "}" ]
// Domains lists the domains on the server
[ "Domains", "lists", "the", "domains", "on", "the", "server" ]
570ac705cf2d7a9235d911d00b6f976ab3386c2f
https://github.com/blacksails/cgp/blob/570ac705cf2d7a9235d911d00b6f976ab3386c2f/domain.go#L54-L66
test
marcuswestin/go-errs
errs.go
New
func New(info Info, publicMsg ...interface{}) Err { return newErr(debug.Stack(), nil, false, info, publicMsg) }
go
func New(info Info, publicMsg ...interface{}) Err { return newErr(debug.Stack(), nil, false, info, publicMsg) }
[ "func", "New", "(", "info", "Info", ",", "publicMsg", "...", "interface", "{", "}", ")", "Err", "{", "return", "newErr", "(", "debug", ".", "Stack", "(", ")", ",", "nil", ",", "false", ",", "info", ",", "publicMsg", ")", "\n", "}" ]
// New creates a new Err with the given Info and optional public message
[ "New", "creates", "a", "new", "Err", "with", "the", "given", "Info", "and", "optional", "public", "message" ]
b09b17aacd5a8213690bc30f9ccfe7400be7b380
https://github.com/marcuswestin/go-errs/blob/b09b17aacd5a8213690bc30f9ccfe7400be7b380/errs.go#L79-L81
test
marcuswestin/go-errs
errs.go
Wrap
func Wrap(wrapErr error, info Info, publicMsg ...interface{}) Err { if wrapErr == nil { return nil } if info == nil { info = Info{} } if errsErr, isErr := IsErr(wrapErr); isErr { if errStructErr, isErrsErr := errsErr.(*err); isErrsErr { errStructErr.mergeIn(info, publicMsg) return errStructErr } return errsErr } return newErr(debug.Stack(), wrapErr, false, info, publicMsg) }
go
func Wrap(wrapErr error, info Info, publicMsg ...interface{}) Err { if wrapErr == nil { return nil } if info == nil { info = Info{} } if errsErr, isErr := IsErr(wrapErr); isErr { if errStructErr, isErrsErr := errsErr.(*err); isErrsErr { errStructErr.mergeIn(info, publicMsg) return errStructErr } return errsErr } return newErr(debug.Stack(), wrapErr, false, info, publicMsg) }
[ "func", "Wrap", "(", "wrapErr", "error", ",", "info", "Info", ",", "publicMsg", "...", "interface", "{", "}", ")", "Err", "{", "if", "wrapErr", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "if", "info", "==", "nil", "{", "info", "=", "Info", "{", "}", "\n", "}", "\n", "if", "errsErr", ",", "isErr", ":=", "IsErr", "(", "wrapErr", ")", ";", "isErr", "{", "if", "errStructErr", ",", "isErrsErr", ":=", "errsErr", ".", "(", "*", "err", ")", ";", "isErrsErr", "{", "errStructErr", ".", "mergeIn", "(", "info", ",", "publicMsg", ")", "\n", "return", "errStructErr", "\n", "}", "\n", "return", "errsErr", "\n", "}", "\n", "return", "newErr", "(", "debug", ".", "Stack", "(", ")", ",", "wrapErr", ",", "false", ",", "info", ",", "publicMsg", ")", "\n", "}" ]
// Wrap the given error in an errs.Err. If err is nil, Wrap returns nil. // Use Err.WrappedError for direct access to the wrapped error.
[ "Wrap", "the", "given", "error", "in", "an", "errs", ".", "Err", ".", "If", "err", "is", "nil", "Wrap", "returns", "nil", ".", "Use", "Err", ".", "WrappedError", "for", "direct", "access", "to", "the", "wrapped", "error", "." ]
b09b17aacd5a8213690bc30f9ccfe7400be7b380
https://github.com/marcuswestin/go-errs/blob/b09b17aacd5a8213690bc30f9ccfe7400be7b380/errs.go#L85-L100
test
marcuswestin/go-errs
errs.go
mergeIn
func (e *err) mergeIn(info Info, publicMsgParts []interface{}) { for key, val := range info { for e.info[key] != nil { key = key + "_duplicate" } e.info[key] = val } publicMsgPrefix := concatArgs(publicMsgParts...) if publicMsgPrefix == "" { // do nothing } else if e.publicMsg == "" { e.publicMsg = publicMsgPrefix } else { e.publicMsg = publicMsgPrefix + " - " + e.publicMsg } }
go
func (e *err) mergeIn(info Info, publicMsgParts []interface{}) { for key, val := range info { for e.info[key] != nil { key = key + "_duplicate" } e.info[key] = val } publicMsgPrefix := concatArgs(publicMsgParts...) if publicMsgPrefix == "" { // do nothing } else if e.publicMsg == "" { e.publicMsg = publicMsgPrefix } else { e.publicMsg = publicMsgPrefix + " - " + e.publicMsg } }
[ "func", "(", "e", "*", "err", ")", "mergeIn", "(", "info", "Info", ",", "publicMsgParts", "[", "]", "interface", "{", "}", ")", "{", "for", "key", ",", "val", ":=", "range", "info", "{", "for", "e", ".", "info", "[", "key", "]", "!=", "nil", "{", "key", "=", "key", "+", "\"_duplicate\"", "\n", "}", "\n", "e", ".", "info", "[", "key", "]", "=", "val", "\n", "}", "\n", "publicMsgPrefix", ":=", "concatArgs", "(", "publicMsgParts", "...", ")", "\n", "if", "publicMsgPrefix", "==", "\"\"", "{", "}", "else", "if", "e", ".", "publicMsg", "==", "\"\"", "{", "e", ".", "publicMsg", "=", "publicMsgPrefix", "\n", "}", "else", "{", "e", ".", "publicMsg", "=", "publicMsgPrefix", "+", "\" - \"", "+", "e", ".", "publicMsg", "\n", "}", "\n", "}" ]
// Merge in the given info and public message parts into this error
[ "Merge", "in", "the", "given", "info", "and", "public", "message", "parts", "into", "this", "error" ]
b09b17aacd5a8213690bc30f9ccfe7400be7b380
https://github.com/marcuswestin/go-errs/blob/b09b17aacd5a8213690bc30f9ccfe7400be7b380/errs.go#L173-L188
test
marcuswestin/go-errs
errs.go
wrappedErrStr
func (e *err) wrappedErrStr() string { if e == nil { return "" } if e.wrappedErr == nil { return "" } return e.wrappedErr.Error() }
go
func (e *err) wrappedErrStr() string { if e == nil { return "" } if e.wrappedErr == nil { return "" } return e.wrappedErr.Error() }
[ "func", "(", "e", "*", "err", ")", "wrappedErrStr", "(", ")", "string", "{", "if", "e", "==", "nil", "{", "return", "\"\"", "\n", "}", "\n", "if", "e", ".", "wrappedErr", "==", "nil", "{", "return", "\"\"", "\n", "}", "\n", "return", "e", ".", "wrappedErr", ".", "Error", "(", ")", "\n", "}" ]
// Get the string representation of the wrapper error, // or an empty string if wrappedErr is nil
[ "Get", "the", "string", "representation", "of", "the", "wrapper", "error", "or", "an", "empty", "string", "if", "wrappedErr", "is", "nil" ]
b09b17aacd5a8213690bc30f9ccfe7400be7b380
https://github.com/marcuswestin/go-errs/blob/b09b17aacd5a8213690bc30f9ccfe7400be7b380/errs.go#L192-L200
test
marcuswestin/go-errs
errs.go
concatArgs
func concatArgs(args ...interface{}) string { res := fmt.Sprintln(args...) return res[0 : len(res)-1] // Remove newline at the end }
go
func concatArgs(args ...interface{}) string { res := fmt.Sprintln(args...) return res[0 : len(res)-1] // Remove newline at the end }
[ "func", "concatArgs", "(", "args", "...", "interface", "{", "}", ")", "string", "{", "res", ":=", "fmt", ".", "Sprintln", "(", "args", "...", ")", "\n", "return", "res", "[", "0", ":", "len", "(", "res", ")", "-", "1", "]", "\n", "}" ]
// Helper to concatenate arguments into a string, // with spaces between the arguments
[ "Helper", "to", "concatenate", "arguments", "into", "a", "string", "with", "spaces", "between", "the", "arguments" ]
b09b17aacd5a8213690bc30f9ccfe7400be7b380
https://github.com/marcuswestin/go-errs/blob/b09b17aacd5a8213690bc30f9ccfe7400be7b380/errs.go#L204-L207
test
blacksails/cgp
mailing_list.go
MailingList
func (dom *Domain) MailingList(name string) *MailingList { return &MailingList{Domain: dom, Name: name} }
go
func (dom *Domain) MailingList(name string) *MailingList { return &MailingList{Domain: dom, Name: name} }
[ "func", "(", "dom", "*", "Domain", ")", "MailingList", "(", "name", "string", ")", "*", "MailingList", "{", "return", "&", "MailingList", "{", "Domain", ":", "dom", ",", "Name", ":", "name", "}", "\n", "}" ]
// MailingList creates a MailingList type from a domain, with the given name
[ "MailingList", "creates", "a", "MailingList", "type", "from", "a", "domain", "with", "the", "given", "name" ]
570ac705cf2d7a9235d911d00b6f976ab3386c2f
https://github.com/blacksails/cgp/blob/570ac705cf2d7a9235d911d00b6f976ab3386c2f/mailing_list.go#L15-L17
test
blacksails/cgp
mailing_list.go
Subscriber
func (ml *MailingList) Subscriber(email, name string) *Subscriber { return &Subscriber{MailingList: ml, Email: email, RealName: name} }
go
func (ml *MailingList) Subscriber(email, name string) *Subscriber { return &Subscriber{MailingList: ml, Email: email, RealName: name} }
[ "func", "(", "ml", "*", "MailingList", ")", "Subscriber", "(", "email", ",", "name", "string", ")", "*", "Subscriber", "{", "return", "&", "Subscriber", "{", "MailingList", ":", "ml", ",", "Email", ":", "email", ",", "RealName", ":", "name", "}", "\n", "}" ]
// Subscriber create a Subscriber type from a MalingList, with the given email // and name
[ "Subscriber", "create", "a", "Subscriber", "type", "from", "a", "MalingList", "with", "the", "given", "email", "and", "name" ]
570ac705cf2d7a9235d911d00b6f976ab3386c2f
https://github.com/blacksails/cgp/blob/570ac705cf2d7a9235d911d00b6f976ab3386c2f/mailing_list.go#L28-L30
test
blacksails/cgp
mailing_list.go
Subscribers
func (ml *MailingList) Subscribers() ([]*Subscriber, error) { var res readSubscribersResponse err := ml.Domain.cgp.request(readSubscribers{Name: fmt.Sprintf("%s@%s", ml.Name, ml.Domain.Name)}, &res) if err != nil { return []*Subscriber{}, err } ds := res.SubValues[1].SubValues subs := make([]*Subscriber, len(ds)) for i, d := range ds { m := d.toMap() subs[i] = ml.Subscriber(m["Sub"], m["RealName"]) } return subs, nil }
go
func (ml *MailingList) Subscribers() ([]*Subscriber, error) { var res readSubscribersResponse err := ml.Domain.cgp.request(readSubscribers{Name: fmt.Sprintf("%s@%s", ml.Name, ml.Domain.Name)}, &res) if err != nil { return []*Subscriber{}, err } ds := res.SubValues[1].SubValues subs := make([]*Subscriber, len(ds)) for i, d := range ds { m := d.toMap() subs[i] = ml.Subscriber(m["Sub"], m["RealName"]) } return subs, nil }
[ "func", "(", "ml", "*", "MailingList", ")", "Subscribers", "(", ")", "(", "[", "]", "*", "Subscriber", ",", "error", ")", "{", "var", "res", "readSubscribersResponse", "\n", "err", ":=", "ml", ".", "Domain", ".", "cgp", ".", "request", "(", "readSubscribers", "{", "Name", ":", "fmt", ".", "Sprintf", "(", "\"%s@%s\"", ",", "ml", ".", "Name", ",", "ml", ".", "Domain", ".", "Name", ")", "}", ",", "&", "res", ")", "\n", "if", "err", "!=", "nil", "{", "return", "[", "]", "*", "Subscriber", "{", "}", ",", "err", "\n", "}", "\n", "ds", ":=", "res", ".", "SubValues", "[", "1", "]", ".", "SubValues", "\n", "subs", ":=", "make", "(", "[", "]", "*", "Subscriber", ",", "len", "(", "ds", ")", ")", "\n", "for", "i", ",", "d", ":=", "range", "ds", "{", "m", ":=", "d", ".", "toMap", "(", ")", "\n", "subs", "[", "i", "]", "=", "ml", ".", "Subscriber", "(", "m", "[", "\"Sub\"", "]", ",", "m", "[", "\"RealName\"", "]", ")", "\n", "}", "\n", "return", "subs", ",", "nil", "\n", "}" ]
// Subscribers returns a list of subscriber of a mailing list.
[ "Subscribers", "returns", "a", "list", "of", "subscriber", "of", "a", "mailing", "list", "." ]
570ac705cf2d7a9235d911d00b6f976ab3386c2f
https://github.com/blacksails/cgp/blob/570ac705cf2d7a9235d911d00b6f976ab3386c2f/mailing_list.go#L42-L55
test
blacksails/cgp
mailing_list.go
MailingLists
func (dom *Domain) MailingLists() ([]*MailingList, error) { var vl valueList err := dom.cgp.request(listLists{Domain: dom.Name}, &vl) if err != nil { return []*MailingList{}, err } vals := vl.compact() mls := make([]*MailingList, len(vals)) for i, v := range vals { mls[i] = dom.MailingList(v) } return mls, nil }
go
func (dom *Domain) MailingLists() ([]*MailingList, error) { var vl valueList err := dom.cgp.request(listLists{Domain: dom.Name}, &vl) if err != nil { return []*MailingList{}, err } vals := vl.compact() mls := make([]*MailingList, len(vals)) for i, v := range vals { mls[i] = dom.MailingList(v) } return mls, nil }
[ "func", "(", "dom", "*", "Domain", ")", "MailingLists", "(", ")", "(", "[", "]", "*", "MailingList", ",", "error", ")", "{", "var", "vl", "valueList", "\n", "err", ":=", "dom", ".", "cgp", ".", "request", "(", "listLists", "{", "Domain", ":", "dom", ".", "Name", "}", ",", "&", "vl", ")", "\n", "if", "err", "!=", "nil", "{", "return", "[", "]", "*", "MailingList", "{", "}", ",", "err", "\n", "}", "\n", "vals", ":=", "vl", ".", "compact", "(", ")", "\n", "mls", ":=", "make", "(", "[", "]", "*", "MailingList", ",", "len", "(", "vals", ")", ")", "\n", "for", "i", ",", "v", ":=", "range", "vals", "{", "mls", "[", "i", "]", "=", "dom", ".", "MailingList", "(", "v", ")", "\n", "}", "\n", "return", "mls", ",", "nil", "\n", "}" ]
// MailingLists lists the mailing lists of a domain
[ "MailingLists", "lists", "the", "mailing", "lists", "of", "a", "domain" ]
570ac705cf2d7a9235d911d00b6f976ab3386c2f
https://github.com/blacksails/cgp/blob/570ac705cf2d7a9235d911d00b6f976ab3386c2f/mailing_list.go#L63-L75
test
t3rm1n4l/nitro
skiplist/item.go
NewByteKeyItem
func NewByteKeyItem(k []byte) unsafe.Pointer { itm := byteKeyItem(k) return unsafe.Pointer(&itm) }
go
func NewByteKeyItem(k []byte) unsafe.Pointer { itm := byteKeyItem(k) return unsafe.Pointer(&itm) }
[ "func", "NewByteKeyItem", "(", "k", "[", "]", "byte", ")", "unsafe", ".", "Pointer", "{", "itm", ":=", "byteKeyItem", "(", "k", ")", "\n", "return", "unsafe", ".", "Pointer", "(", "&", "itm", ")", "\n", "}" ]
// NewByteKeyItem creates a new item from bytes
[ "NewByteKeyItem", "creates", "a", "new", "item", "from", "bytes" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/skiplist/item.go#L46-L49
test
t3rm1n4l/nitro
skiplist/item.go
CompareBytes
func CompareBytes(this, that unsafe.Pointer) int { thisItem := (*byteKeyItem)(this) thatItem := (*byteKeyItem)(that) return bytes.Compare([]byte(*thisItem), []byte(*thatItem)) }
go
func CompareBytes(this, that unsafe.Pointer) int { thisItem := (*byteKeyItem)(this) thatItem := (*byteKeyItem)(that) return bytes.Compare([]byte(*thisItem), []byte(*thatItem)) }
[ "func", "CompareBytes", "(", "this", ",", "that", "unsafe", ".", "Pointer", ")", "int", "{", "thisItem", ":=", "(", "*", "byteKeyItem", ")", "(", "this", ")", "\n", "thatItem", ":=", "(", "*", "byteKeyItem", ")", "(", "that", ")", "\n", "return", "bytes", ".", "Compare", "(", "[", "]", "byte", "(", "*", "thisItem", ")", ",", "[", "]", "byte", "(", "*", "thatItem", ")", ")", "\n", "}" ]
// CompareBytes is a byte item comparator
[ "CompareBytes", "is", "a", "byte", "item", "comparator" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/skiplist/item.go#L52-L56
test
t3rm1n4l/nitro
skiplist/item.go
CompareInt
func CompareInt(this, that unsafe.Pointer) int { thisItem := (*intKeyItem)(this) thatItem := (*intKeyItem)(that) return int(*thisItem - *thatItem) }
go
func CompareInt(this, that unsafe.Pointer) int { thisItem := (*intKeyItem)(this) thatItem := (*intKeyItem)(that) return int(*thisItem - *thatItem) }
[ "func", "CompareInt", "(", "this", ",", "that", "unsafe", ".", "Pointer", ")", "int", "{", "thisItem", ":=", "(", "*", "intKeyItem", ")", "(", "this", ")", "\n", "thatItem", ":=", "(", "*", "intKeyItem", ")", "(", "that", ")", "\n", "return", "int", "(", "*", "thisItem", "-", "*", "thatItem", ")", "\n", "}" ]
// CompareInt is a helper integer item comparator
[ "CompareInt", "is", "a", "helper", "integer", "item", "comparator" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/skiplist/item.go#L69-L73
test
t3rm1n4l/nitro
mm/malloc.go
Malloc
func Malloc(l int) unsafe.Pointer { if Debug { atomic.AddUint64(&stats.allocs, 1) } return C.mm_malloc(C.size_t(l)) }
go
func Malloc(l int) unsafe.Pointer { if Debug { atomic.AddUint64(&stats.allocs, 1) } return C.mm_malloc(C.size_t(l)) }
[ "func", "Malloc", "(", "l", "int", ")", "unsafe", ".", "Pointer", "{", "if", "Debug", "{", "atomic", ".", "AddUint64", "(", "&", "stats", ".", "allocs", ",", "1", ")", "\n", "}", "\n", "return", "C", ".", "mm_malloc", "(", "C", ".", "size_t", "(", "l", ")", ")", "\n", "}" ]
// Malloc implements C like memory allocator
[ "Malloc", "implements", "C", "like", "memory", "allocator" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/mm/malloc.go#L36-L41
test
t3rm1n4l/nitro
mm/malloc.go
Free
func Free(p unsafe.Pointer) { if Debug { atomic.AddUint64(&stats.frees, 1) } C.mm_free(p) }
go
func Free(p unsafe.Pointer) { if Debug { atomic.AddUint64(&stats.frees, 1) } C.mm_free(p) }
[ "func", "Free", "(", "p", "unsafe", ".", "Pointer", ")", "{", "if", "Debug", "{", "atomic", ".", "AddUint64", "(", "&", "stats", ".", "frees", ",", "1", ")", "\n", "}", "\n", "C", ".", "mm_free", "(", "p", ")", "\n", "}" ]
// Free implements C like memory deallocator
[ "Free", "implements", "C", "like", "memory", "deallocator" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/mm/malloc.go#L44-L49
test
t3rm1n4l/nitro
mm/malloc.go
Stats
func Stats() string { mu.Lock() defer mu.Unlock() buf := C.mm_stats() s := "==== Stats ====\n" if Debug { s += fmt.Sprintf("Mallocs = %d\n"+ "Frees = %d\n", stats.allocs, stats.frees) } if buf != nil { s += C.GoString(buf) C.free(unsafe.Pointer(buf)) } return s }
go
func Stats() string { mu.Lock() defer mu.Unlock() buf := C.mm_stats() s := "==== Stats ====\n" if Debug { s += fmt.Sprintf("Mallocs = %d\n"+ "Frees = %d\n", stats.allocs, stats.frees) } if buf != nil { s += C.GoString(buf) C.free(unsafe.Pointer(buf)) } return s }
[ "func", "Stats", "(", ")", "string", "{", "mu", ".", "Lock", "(", ")", "\n", "defer", "mu", ".", "Unlock", "(", ")", "\n", "buf", ":=", "C", ".", "mm_stats", "(", ")", "\n", "s", ":=", "\"==== Stats ====\\n\"", "\n", "\\n", "\n", "if", "Debug", "{", "s", "+=", "fmt", ".", "Sprintf", "(", "\"Mallocs = %d\\n\"", "+", "\\n", ",", "\"Frees = %d\\n\"", ",", "\\n", ")", "\n", "}", "\n", "stats", ".", "allocs", "\n", "}" ]
// Stats returns allocator statistics // Returns jemalloc stats
[ "Stats", "returns", "allocator", "statistics", "Returns", "jemalloc", "stats" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/mm/malloc.go#L53-L70
test
t3rm1n4l/nitro
mm/malloc.go
FreeOSMemory
func FreeOSMemory() error { errCode := int(C.mm_free2os()) if errCode != 0 { return fmt.Errorf("status: %d", errCode) } return nil }
go
func FreeOSMemory() error { errCode := int(C.mm_free2os()) if errCode != 0 { return fmt.Errorf("status: %d", errCode) } return nil }
[ "func", "FreeOSMemory", "(", ")", "error", "{", "errCode", ":=", "int", "(", "C", ".", "mm_free2os", "(", ")", ")", "\n", "if", "errCode", "!=", "0", "{", "return", "fmt", ".", "Errorf", "(", "\"status: %d\"", ",", "errCode", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// FreeOSMemory forces jemalloc to scrub memory and release back to OS
[ "FreeOSMemory", "forces", "jemalloc", "to", "scrub", "memory", "and", "release", "back", "to", "OS" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/mm/malloc.go#L78-L85
test
t3rm1n4l/nitro
skiplist/builder.go
Add
func (s *Segment) Add(itm unsafe.Pointer) { itemLevel := s.builder.store.NewLevel(s.rand.Float32) x := s.builder.store.newNode(itm, itemLevel) s.sts.AddInt64(&s.sts.nodeAllocs, 1) s.sts.AddInt64(&s.sts.levelNodesCount[itemLevel], 1) s.sts.AddInt64(&s.sts.usedBytes, int64(s.builder.store.Size(x))) for l := 0; l <= itemLevel; l++ { if s.tail[l] != nil { s.tail[l].setNext(l, x, false) } else { s.head[l] = x } s.tail[l] = x } if s.callb != nil { s.callb(x) } }
go
func (s *Segment) Add(itm unsafe.Pointer) { itemLevel := s.builder.store.NewLevel(s.rand.Float32) x := s.builder.store.newNode(itm, itemLevel) s.sts.AddInt64(&s.sts.nodeAllocs, 1) s.sts.AddInt64(&s.sts.levelNodesCount[itemLevel], 1) s.sts.AddInt64(&s.sts.usedBytes, int64(s.builder.store.Size(x))) for l := 0; l <= itemLevel; l++ { if s.tail[l] != nil { s.tail[l].setNext(l, x, false) } else { s.head[l] = x } s.tail[l] = x } if s.callb != nil { s.callb(x) } }
[ "func", "(", "s", "*", "Segment", ")", "Add", "(", "itm", "unsafe", ".", "Pointer", ")", "{", "itemLevel", ":=", "s", ".", "builder", ".", "store", ".", "NewLevel", "(", "s", ".", "rand", ".", "Float32", ")", "\n", "x", ":=", "s", ".", "builder", ".", "store", ".", "newNode", "(", "itm", ",", "itemLevel", ")", "\n", "s", ".", "sts", ".", "AddInt64", "(", "&", "s", ".", "sts", ".", "nodeAllocs", ",", "1", ")", "\n", "s", ".", "sts", ".", "AddInt64", "(", "&", "s", ".", "sts", ".", "levelNodesCount", "[", "itemLevel", "]", ",", "1", ")", "\n", "s", ".", "sts", ".", "AddInt64", "(", "&", "s", ".", "sts", ".", "usedBytes", ",", "int64", "(", "s", ".", "builder", ".", "store", ".", "Size", "(", "x", ")", ")", ")", "\n", "for", "l", ":=", "0", ";", "l", "<=", "itemLevel", ";", "l", "++", "{", "if", "s", ".", "tail", "[", "l", "]", "!=", "nil", "{", "s", ".", "tail", "[", "l", "]", ".", "setNext", "(", "l", ",", "x", ",", "false", ")", "\n", "}", "else", "{", "s", ".", "head", "[", "l", "]", "=", "x", "\n", "}", "\n", "s", ".", "tail", "[", "l", "]", "=", "x", "\n", "}", "\n", "if", "s", ".", "callb", "!=", "nil", "{", "s", ".", "callb", "(", "x", ")", "\n", "}", "\n", "}" ]
// Add an item into skiplist segment
[ "Add", "an", "item", "into", "skiplist", "segment" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/skiplist/builder.go#L36-L55
test
t3rm1n4l/nitro
skiplist/builder.go
NewSegment
func (b *Builder) NewSegment() *Segment { seg := &Segment{tail: make([]*Node, MaxLevel+1), head: make([]*Node, MaxLevel+1), builder: b, rand: rand.New(rand.NewSource(int64(rand.Int()))), } seg.sts.IsLocal(true) return seg }
go
func (b *Builder) NewSegment() *Segment { seg := &Segment{tail: make([]*Node, MaxLevel+1), head: make([]*Node, MaxLevel+1), builder: b, rand: rand.New(rand.NewSource(int64(rand.Int()))), } seg.sts.IsLocal(true) return seg }
[ "func", "(", "b", "*", "Builder", ")", "NewSegment", "(", ")", "*", "Segment", "{", "seg", ":=", "&", "Segment", "{", "tail", ":", "make", "(", "[", "]", "*", "Node", ",", "MaxLevel", "+", "1", ")", ",", "head", ":", "make", "(", "[", "]", "*", "Node", ",", "MaxLevel", "+", "1", ")", ",", "builder", ":", "b", ",", "rand", ":", "rand", ".", "New", "(", "rand", ".", "NewSource", "(", "int64", "(", "rand", ".", "Int", "(", ")", ")", ")", ")", ",", "}", "\n", "seg", ".", "sts", ".", "IsLocal", "(", "true", ")", "\n", "return", "seg", "\n", "}" ]
// NewSegment creates a new skiplist segment
[ "NewSegment", "creates", "a", "new", "skiplist", "segment" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/skiplist/builder.go#L68-L76
test
t3rm1n4l/nitro
skiplist/builder.go
Assemble
func (b *Builder) Assemble(segments ...*Segment) *Skiplist { tail := make([]*Node, MaxLevel+1) head := make([]*Node, MaxLevel+1) for _, seg := range segments { for l := 0; l <= MaxLevel; l++ { if tail[l] != nil && seg.head[l] != nil { tail[l].setNext(l, seg.head[l], false) } else if head[l] == nil && seg.head[l] != nil { head[l] = seg.head[l] } if seg.tail[l] != nil { tail[l] = seg.tail[l] } } } for l := 0; l <= MaxLevel; l++ { if head[l] != nil { b.store.head.setNext(l, head[l], false) } if tail[l] != nil { tail[l].setNext(l, b.store.tail, false) } } for _, seg := range segments { b.store.Stats.Merge(&seg.sts) } return b.store }
go
func (b *Builder) Assemble(segments ...*Segment) *Skiplist { tail := make([]*Node, MaxLevel+1) head := make([]*Node, MaxLevel+1) for _, seg := range segments { for l := 0; l <= MaxLevel; l++ { if tail[l] != nil && seg.head[l] != nil { tail[l].setNext(l, seg.head[l], false) } else if head[l] == nil && seg.head[l] != nil { head[l] = seg.head[l] } if seg.tail[l] != nil { tail[l] = seg.tail[l] } } } for l := 0; l <= MaxLevel; l++ { if head[l] != nil { b.store.head.setNext(l, head[l], false) } if tail[l] != nil { tail[l].setNext(l, b.store.tail, false) } } for _, seg := range segments { b.store.Stats.Merge(&seg.sts) } return b.store }
[ "func", "(", "b", "*", "Builder", ")", "Assemble", "(", "segments", "...", "*", "Segment", ")", "*", "Skiplist", "{", "tail", ":=", "make", "(", "[", "]", "*", "Node", ",", "MaxLevel", "+", "1", ")", "\n", "head", ":=", "make", "(", "[", "]", "*", "Node", ",", "MaxLevel", "+", "1", ")", "\n", "for", "_", ",", "seg", ":=", "range", "segments", "{", "for", "l", ":=", "0", ";", "l", "<=", "MaxLevel", ";", "l", "++", "{", "if", "tail", "[", "l", "]", "!=", "nil", "&&", "seg", ".", "head", "[", "l", "]", "!=", "nil", "{", "tail", "[", "l", "]", ".", "setNext", "(", "l", ",", "seg", ".", "head", "[", "l", "]", ",", "false", ")", "\n", "}", "else", "if", "head", "[", "l", "]", "==", "nil", "&&", "seg", ".", "head", "[", "l", "]", "!=", "nil", "{", "head", "[", "l", "]", "=", "seg", ".", "head", "[", "l", "]", "\n", "}", "\n", "if", "seg", ".", "tail", "[", "l", "]", "!=", "nil", "{", "tail", "[", "l", "]", "=", "seg", ".", "tail", "[", "l", "]", "\n", "}", "\n", "}", "\n", "}", "\n", "for", "l", ":=", "0", ";", "l", "<=", "MaxLevel", ";", "l", "++", "{", "if", "head", "[", "l", "]", "!=", "nil", "{", "b", ".", "store", ".", "head", ".", "setNext", "(", "l", ",", "head", "[", "l", "]", ",", "false", ")", "\n", "}", "\n", "if", "tail", "[", "l", "]", "!=", "nil", "{", "tail", "[", "l", "]", ".", "setNext", "(", "l", ",", "b", ".", "store", ".", "tail", ",", "false", ")", "\n", "}", "\n", "}", "\n", "for", "_", ",", "seg", ":=", "range", "segments", "{", "b", ".", "store", ".", "Stats", ".", "Merge", "(", "&", "seg", ".", "sts", ")", "\n", "}", "\n", "return", "b", ".", "store", "\n", "}" ]
// Assemble multiple skiplist segments and form a parent skiplist
[ "Assemble", "multiple", "skiplist", "segments", "and", "form", "a", "parent", "skiplist" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/skiplist/builder.go#L79-L112
test
t3rm1n4l/nitro
nodetable/table.go
CompareNodeTable
func CompareNodeTable(a, b unsafe.Pointer) int { return int(uintptr(a)) - int(uintptr(b)) }
go
func CompareNodeTable(a, b unsafe.Pointer) int { return int(uintptr(a)) - int(uintptr(b)) }
[ "func", "CompareNodeTable", "(", "a", ",", "b", "unsafe", ".", "Pointer", ")", "int", "{", "return", "int", "(", "uintptr", "(", "a", ")", ")", "-", "int", "(", "uintptr", "(", "b", ")", ")", "\n", "}" ]
// CompareNodeTable implements comparator for nodetable instances
[ "CompareNodeTable", "implements", "comparator", "for", "nodetable", "instances" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/nodetable/table.go#L58-L60
test
t3rm1n4l/nitro
nodetable/table.go
New
func New(hfn HashFn, kfn EqualKeyFn) *NodeTable { nt := &NodeTable{ fastHT: make(map[uint32]uint64), slowHT: make(map[uint32][]uint64), hash: hfn, keyEqual: kfn, } buf := dbInstances.MakeBuf() defer dbInstances.FreeBuf(buf) dbInstances.Insert(unsafe.Pointer(nt), CompareNodeTable, buf, &dbInstances.Stats) return nt }
go
func New(hfn HashFn, kfn EqualKeyFn) *NodeTable { nt := &NodeTable{ fastHT: make(map[uint32]uint64), slowHT: make(map[uint32][]uint64), hash: hfn, keyEqual: kfn, } buf := dbInstances.MakeBuf() defer dbInstances.FreeBuf(buf) dbInstances.Insert(unsafe.Pointer(nt), CompareNodeTable, buf, &dbInstances.Stats) return nt }
[ "func", "New", "(", "hfn", "HashFn", ",", "kfn", "EqualKeyFn", ")", "*", "NodeTable", "{", "nt", ":=", "&", "NodeTable", "{", "fastHT", ":", "make", "(", "map", "[", "uint32", "]", "uint64", ")", ",", "slowHT", ":", "make", "(", "map", "[", "uint32", "]", "[", "]", "uint64", ")", ",", "hash", ":", "hfn", ",", "keyEqual", ":", "kfn", ",", "}", "\n", "buf", ":=", "dbInstances", ".", "MakeBuf", "(", ")", "\n", "defer", "dbInstances", ".", "FreeBuf", "(", "buf", ")", "\n", "dbInstances", ".", "Insert", "(", "unsafe", ".", "Pointer", "(", "nt", ")", ",", "CompareNodeTable", ",", "buf", ",", "&", "dbInstances", ".", "Stats", ")", "\n", "return", "nt", "\n", "}" ]
// New creates a nodetable instance
[ "New", "creates", "a", "nodetable", "instance" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/nodetable/table.go#L80-L93
test
t3rm1n4l/nitro
nodetable/table.go
Stats
func (nt *NodeTable) Stats() string { return fmt.Sprintf("\nFastHTCount = %d\n"+ "SlowHTCount = %d\n"+ "Conflicts = %d\n"+ "MemoryInUse = %d\n", nt.fastHTCount, nt.slowHTCount, nt.conflicts, nt.MemoryInUse()) }
go
func (nt *NodeTable) Stats() string { return fmt.Sprintf("\nFastHTCount = %d\n"+ "SlowHTCount = %d\n"+ "Conflicts = %d\n"+ "MemoryInUse = %d\n", nt.fastHTCount, nt.slowHTCount, nt.conflicts, nt.MemoryInUse()) }
[ "func", "(", "nt", "*", "NodeTable", ")", "Stats", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"\\nFastHTCount = %d\\n\"", "+", "\\n", "+", "\\n", "+", "\"SlowHTCount = %d\\n\"", ",", "\\n", ",", "\"Conflicts = %d\\n\"", ",", "\\n", ",", "\"MemoryInUse = %d\\n\"", ")", "\n", "}" ]
// Stats returns nodetable statistics
[ "Stats", "returns", "nodetable", "statistics" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/nodetable/table.go#L96-L102
test
t3rm1n4l/nitro
nodetable/table.go
MemoryInUse
func (nt *NodeTable) MemoryInUse() int64 { return int64(approxItemSize * (nt.fastHTCount + nt.slowHTCount)) }
go
func (nt *NodeTable) MemoryInUse() int64 { return int64(approxItemSize * (nt.fastHTCount + nt.slowHTCount)) }
[ "func", "(", "nt", "*", "NodeTable", ")", "MemoryInUse", "(", ")", "int64", "{", "return", "int64", "(", "approxItemSize", "*", "(", "nt", ".", "fastHTCount", "+", "nt", ".", "slowHTCount", ")", ")", "\n", "}" ]
// MemoryInUse returns memory used by nodetable instance
[ "MemoryInUse", "returns", "memory", "used", "by", "nodetable", "instance" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/nodetable/table.go#L105-L107
test
t3rm1n4l/nitro
nodetable/table.go
Get
func (nt *NodeTable) Get(key []byte) unsafe.Pointer { res := nt.find(key) if res.status&ntFoundMask == ntFoundMask { if res.status == ntFoundInFast { return decodePointer(res.fastHTValue) } return decodePointer(res.slowHTValues[res.slowHTPos]) } return nil }
go
func (nt *NodeTable) Get(key []byte) unsafe.Pointer { res := nt.find(key) if res.status&ntFoundMask == ntFoundMask { if res.status == ntFoundInFast { return decodePointer(res.fastHTValue) } return decodePointer(res.slowHTValues[res.slowHTPos]) } return nil }
[ "func", "(", "nt", "*", "NodeTable", ")", "Get", "(", "key", "[", "]", "byte", ")", "unsafe", ".", "Pointer", "{", "res", ":=", "nt", ".", "find", "(", "key", ")", "\n", "if", "res", ".", "status", "&", "ntFoundMask", "==", "ntFoundMask", "{", "if", "res", ".", "status", "==", "ntFoundInFast", "{", "return", "decodePointer", "(", "res", ".", "fastHTValue", ")", "\n", "}", "\n", "return", "decodePointer", "(", "res", ".", "slowHTValues", "[", "res", ".", "slowHTPos", "]", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Get returns node pointer for the lookup key
[ "Get", "returns", "node", "pointer", "for", "the", "lookup", "key" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/nodetable/table.go#L110-L120
test
t3rm1n4l/nitro
nodetable/table.go
Update
func (nt *NodeTable) Update(key []byte, nptr unsafe.Pointer) (updated bool, oldPtr unsafe.Pointer) { res := nt.find(key) if res.status&ntFoundMask == ntFoundMask { // Found key, replace old pointer value with new one updated = true if res.status == ntFoundInFast { oldPtr = decodePointer(res.fastHTValue) nt.fastHT[res.hash] = encodePointer(nptr, res.hasConflict) } else { oldPtr = decodePointer(res.slowHTValues[res.slowHTPos]) res.slowHTValues[res.slowHTPos] = encodePointer(nptr, true) } } else { // Insert new key updated = false newSlowValue := res.fastHTHasEntry && !res.hasConflict // Key needs to be inserted into slowHT if res.hasConflict || newSlowValue { slowHTValues := nt.slowHT[res.hash] slowHTValues = append(slowHTValues, encodePointer(nptr, false)) nt.slowHT[res.hash] = slowHTValues // There is an entry already in the fastHT for same crc32 hash // We have inserted first entry into the slowHT. Now mark conflict bit. if newSlowValue { nt.fastHT[res.hash] = encodePointer(decodePointer(nt.fastHT[res.hash]), true) nt.conflicts++ } nt.slowHTCount++ } else { // Insert new item into fastHT nt.fastHT[res.hash] = encodePointer(nptr, false) nt.fastHTCount++ } } return }
go
func (nt *NodeTable) Update(key []byte, nptr unsafe.Pointer) (updated bool, oldPtr unsafe.Pointer) { res := nt.find(key) if res.status&ntFoundMask == ntFoundMask { // Found key, replace old pointer value with new one updated = true if res.status == ntFoundInFast { oldPtr = decodePointer(res.fastHTValue) nt.fastHT[res.hash] = encodePointer(nptr, res.hasConflict) } else { oldPtr = decodePointer(res.slowHTValues[res.slowHTPos]) res.slowHTValues[res.slowHTPos] = encodePointer(nptr, true) } } else { // Insert new key updated = false newSlowValue := res.fastHTHasEntry && !res.hasConflict // Key needs to be inserted into slowHT if res.hasConflict || newSlowValue { slowHTValues := nt.slowHT[res.hash] slowHTValues = append(slowHTValues, encodePointer(nptr, false)) nt.slowHT[res.hash] = slowHTValues // There is an entry already in the fastHT for same crc32 hash // We have inserted first entry into the slowHT. Now mark conflict bit. if newSlowValue { nt.fastHT[res.hash] = encodePointer(decodePointer(nt.fastHT[res.hash]), true) nt.conflicts++ } nt.slowHTCount++ } else { // Insert new item into fastHT nt.fastHT[res.hash] = encodePointer(nptr, false) nt.fastHTCount++ } } return }
[ "func", "(", "nt", "*", "NodeTable", ")", "Update", "(", "key", "[", "]", "byte", ",", "nptr", "unsafe", ".", "Pointer", ")", "(", "updated", "bool", ",", "oldPtr", "unsafe", ".", "Pointer", ")", "{", "res", ":=", "nt", ".", "find", "(", "key", ")", "\n", "if", "res", ".", "status", "&", "ntFoundMask", "==", "ntFoundMask", "{", "updated", "=", "true", "\n", "if", "res", ".", "status", "==", "ntFoundInFast", "{", "oldPtr", "=", "decodePointer", "(", "res", ".", "fastHTValue", ")", "\n", "nt", ".", "fastHT", "[", "res", ".", "hash", "]", "=", "encodePointer", "(", "nptr", ",", "res", ".", "hasConflict", ")", "\n", "}", "else", "{", "oldPtr", "=", "decodePointer", "(", "res", ".", "slowHTValues", "[", "res", ".", "slowHTPos", "]", ")", "\n", "res", ".", "slowHTValues", "[", "res", ".", "slowHTPos", "]", "=", "encodePointer", "(", "nptr", ",", "true", ")", "\n", "}", "\n", "}", "else", "{", "updated", "=", "false", "\n", "newSlowValue", ":=", "res", ".", "fastHTHasEntry", "&&", "!", "res", ".", "hasConflict", "\n", "if", "res", ".", "hasConflict", "||", "newSlowValue", "{", "slowHTValues", ":=", "nt", ".", "slowHT", "[", "res", ".", "hash", "]", "\n", "slowHTValues", "=", "append", "(", "slowHTValues", ",", "encodePointer", "(", "nptr", ",", "false", ")", ")", "\n", "nt", ".", "slowHT", "[", "res", ".", "hash", "]", "=", "slowHTValues", "\n", "if", "newSlowValue", "{", "nt", ".", "fastHT", "[", "res", ".", "hash", "]", "=", "encodePointer", "(", "decodePointer", "(", "nt", ".", "fastHT", "[", "res", ".", "hash", "]", ")", ",", "true", ")", "\n", "nt", ".", "conflicts", "++", "\n", "}", "\n", "nt", ".", "slowHTCount", "++", "\n", "}", "else", "{", "nt", ".", "fastHT", "[", "res", ".", "hash", "]", "=", "encodePointer", "(", "nptr", ",", "false", ")", "\n", "nt", ".", "fastHTCount", "++", "\n", "}", "\n", "}", "\n", "return", "\n", "}" ]
// Update inserts or replaces an existing entry
[ "Update", "inserts", "or", "replaces", "an", "existing", "entry" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/nodetable/table.go#L123-L159
test
t3rm1n4l/nitro
nodetable/table.go
Remove
func (nt *NodeTable) Remove(key []byte) (success bool, nptr unsafe.Pointer) { res := nt.find(key) if res.status&ntFoundMask == ntFoundMask { success = true if res.status == ntFoundInFast { nptr = decodePointer(res.fastHTValue) // Key needs to be removed from fastHT. For that we need to move // an item present in slowHT and overwrite fastHT entry. if res.hasConflict { slowHTValues := nt.slowHT[res.hash] v := slowHTValues[0] // New fastHT candidate slowHTValues = append([]uint64(nil), slowHTValues[1:]...) nt.slowHTCount-- var conflict bool if len(slowHTValues) == 0 { delete(nt.slowHT, res.hash) nt.conflicts-- } else { conflict = true nt.slowHT[res.hash] = slowHTValues } nt.fastHT[res.hash] = encodePointer(decodePointer(v), conflict) } else { delete(nt.fastHT, res.hash) nt.fastHTCount-- } } else { nptr = decodePointer(res.slowHTValues[res.slowHTPos]) // Remove key from slowHT newSlowValue := append([]uint64(nil), res.slowHTValues[:res.slowHTPos]...) if res.slowHTPos+1 != len(res.slowHTValues) { newSlowValue = append(newSlowValue, res.slowHTValues[res.slowHTPos+1:]...) } nt.slowHTCount-- if len(newSlowValue) == 0 { delete(nt.slowHT, res.hash) nt.fastHT[res.hash] = encodePointer(decodePointer(nt.fastHT[res.hash]), false) nt.conflicts-- } else { nt.slowHT[res.hash] = newSlowValue } } } return }
go
func (nt *NodeTable) Remove(key []byte) (success bool, nptr unsafe.Pointer) { res := nt.find(key) if res.status&ntFoundMask == ntFoundMask { success = true if res.status == ntFoundInFast { nptr = decodePointer(res.fastHTValue) // Key needs to be removed from fastHT. For that we need to move // an item present in slowHT and overwrite fastHT entry. if res.hasConflict { slowHTValues := nt.slowHT[res.hash] v := slowHTValues[0] // New fastHT candidate slowHTValues = append([]uint64(nil), slowHTValues[1:]...) nt.slowHTCount-- var conflict bool if len(slowHTValues) == 0 { delete(nt.slowHT, res.hash) nt.conflicts-- } else { conflict = true nt.slowHT[res.hash] = slowHTValues } nt.fastHT[res.hash] = encodePointer(decodePointer(v), conflict) } else { delete(nt.fastHT, res.hash) nt.fastHTCount-- } } else { nptr = decodePointer(res.slowHTValues[res.slowHTPos]) // Remove key from slowHT newSlowValue := append([]uint64(nil), res.slowHTValues[:res.slowHTPos]...) if res.slowHTPos+1 != len(res.slowHTValues) { newSlowValue = append(newSlowValue, res.slowHTValues[res.slowHTPos+1:]...) } nt.slowHTCount-- if len(newSlowValue) == 0 { delete(nt.slowHT, res.hash) nt.fastHT[res.hash] = encodePointer(decodePointer(nt.fastHT[res.hash]), false) nt.conflicts-- } else { nt.slowHT[res.hash] = newSlowValue } } } return }
[ "func", "(", "nt", "*", "NodeTable", ")", "Remove", "(", "key", "[", "]", "byte", ")", "(", "success", "bool", ",", "nptr", "unsafe", ".", "Pointer", ")", "{", "res", ":=", "nt", ".", "find", "(", "key", ")", "\n", "if", "res", ".", "status", "&", "ntFoundMask", "==", "ntFoundMask", "{", "success", "=", "true", "\n", "if", "res", ".", "status", "==", "ntFoundInFast", "{", "nptr", "=", "decodePointer", "(", "res", ".", "fastHTValue", ")", "\n", "if", "res", ".", "hasConflict", "{", "slowHTValues", ":=", "nt", ".", "slowHT", "[", "res", ".", "hash", "]", "\n", "v", ":=", "slowHTValues", "[", "0", "]", "\n", "slowHTValues", "=", "append", "(", "[", "]", "uint64", "(", "nil", ")", ",", "slowHTValues", "[", "1", ":", "]", "...", ")", "\n", "nt", ".", "slowHTCount", "--", "\n", "var", "conflict", "bool", "\n", "if", "len", "(", "slowHTValues", ")", "==", "0", "{", "delete", "(", "nt", ".", "slowHT", ",", "res", ".", "hash", ")", "\n", "nt", ".", "conflicts", "--", "\n", "}", "else", "{", "conflict", "=", "true", "\n", "nt", ".", "slowHT", "[", "res", ".", "hash", "]", "=", "slowHTValues", "\n", "}", "\n", "nt", ".", "fastHT", "[", "res", ".", "hash", "]", "=", "encodePointer", "(", "decodePointer", "(", "v", ")", ",", "conflict", ")", "\n", "}", "else", "{", "delete", "(", "nt", ".", "fastHT", ",", "res", ".", "hash", ")", "\n", "nt", ".", "fastHTCount", "--", "\n", "}", "\n", "}", "else", "{", "nptr", "=", "decodePointer", "(", "res", ".", "slowHTValues", "[", "res", ".", "slowHTPos", "]", ")", "\n", "newSlowValue", ":=", "append", "(", "[", "]", "uint64", "(", "nil", ")", ",", "res", ".", "slowHTValues", "[", ":", "res", ".", "slowHTPos", "]", "...", ")", "\n", "if", "res", ".", "slowHTPos", "+", "1", "!=", "len", "(", "res", ".", "slowHTValues", ")", "{", "newSlowValue", "=", "append", "(", "newSlowValue", ",", "res", ".", "slowHTValues", "[", "res", ".", "slowHTPos", "+", "1", ":", "]", "...", ")", "\n", "}", "\n", "nt", ".", "slowHTCount", "--", "\n", "if", "len", "(", "newSlowValue", ")", "==", "0", "{", "delete", "(", "nt", ".", "slowHT", ",", "res", ".", "hash", ")", "\n", "nt", ".", "fastHT", "[", "res", ".", "hash", "]", "=", "encodePointer", "(", "decodePointer", "(", "nt", ".", "fastHT", "[", "res", ".", "hash", "]", ")", ",", "false", ")", "\n", "nt", ".", "conflicts", "--", "\n", "}", "else", "{", "nt", ".", "slowHT", "[", "res", ".", "hash", "]", "=", "newSlowValue", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "\n", "}" ]
// Remove an item from the nodetable
[ "Remove", "an", "item", "from", "the", "nodetable" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/nodetable/table.go#L162-L209
test
t3rm1n4l/nitro
nodetable/table.go
Close
func (nt *NodeTable) Close() { nt.fastHTCount = 0 nt.slowHTCount = 0 nt.conflicts = 0 nt.fastHT = make(map[uint32]uint64) nt.slowHT = make(map[uint32][]uint64) buf := dbInstances.MakeBuf() defer dbInstances.FreeBuf(buf) dbInstances.Delete(unsafe.Pointer(nt), CompareNodeTable, buf, &dbInstances.Stats) }
go
func (nt *NodeTable) Close() { nt.fastHTCount = 0 nt.slowHTCount = 0 nt.conflicts = 0 nt.fastHT = make(map[uint32]uint64) nt.slowHT = make(map[uint32][]uint64) buf := dbInstances.MakeBuf() defer dbInstances.FreeBuf(buf) dbInstances.Delete(unsafe.Pointer(nt), CompareNodeTable, buf, &dbInstances.Stats) }
[ "func", "(", "nt", "*", "NodeTable", ")", "Close", "(", ")", "{", "nt", ".", "fastHTCount", "=", "0", "\n", "nt", ".", "slowHTCount", "=", "0", "\n", "nt", ".", "conflicts", "=", "0", "\n", "nt", ".", "fastHT", "=", "make", "(", "map", "[", "uint32", "]", "uint64", ")", "\n", "nt", ".", "slowHT", "=", "make", "(", "map", "[", "uint32", "]", "[", "]", "uint64", ")", "\n", "buf", ":=", "dbInstances", ".", "MakeBuf", "(", ")", "\n", "defer", "dbInstances", ".", "FreeBuf", "(", "buf", ")", "\n", "dbInstances", ".", "Delete", "(", "unsafe", ".", "Pointer", "(", "nt", ")", ",", "CompareNodeTable", ",", "buf", ",", "&", "dbInstances", ".", "Stats", ")", "\n", "}" ]
// Close destroys the nodetable
[ "Close", "destroys", "the", "nodetable" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/nodetable/table.go#L273-L283
test
t3rm1n4l/nitro
nodetable/table.go
MemoryInUse
func MemoryInUse() (sz int64) { buf := dbInstances.MakeBuf() defer dbInstances.FreeBuf(buf) iter := dbInstances.NewIterator(CompareNodeTable, buf) for iter.SeekFirst(); iter.Valid(); iter.Next() { db := (*NodeTable)(iter.Get()) sz += db.MemoryInUse() } return }
go
func MemoryInUse() (sz int64) { buf := dbInstances.MakeBuf() defer dbInstances.FreeBuf(buf) iter := dbInstances.NewIterator(CompareNodeTable, buf) for iter.SeekFirst(); iter.Valid(); iter.Next() { db := (*NodeTable)(iter.Get()) sz += db.MemoryInUse() } return }
[ "func", "MemoryInUse", "(", ")", "(", "sz", "int64", ")", "{", "buf", ":=", "dbInstances", ".", "MakeBuf", "(", ")", "\n", "defer", "dbInstances", ".", "FreeBuf", "(", "buf", ")", "\n", "iter", ":=", "dbInstances", ".", "NewIterator", "(", "CompareNodeTable", ",", "buf", ")", "\n", "for", "iter", ".", "SeekFirst", "(", ")", ";", "iter", ".", "Valid", "(", ")", ";", "iter", ".", "Next", "(", ")", "{", "db", ":=", "(", "*", "NodeTable", ")", "(", "iter", ".", "Get", "(", ")", ")", "\n", "sz", "+=", "db", ".", "MemoryInUse", "(", ")", "\n", "}", "\n", "return", "\n", "}" ]
// MemoryInUse returns total memory used by nodetables in a process
[ "MemoryInUse", "returns", "total", "memory", "used", "by", "nodetables", "in", "a", "process" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/nodetable/table.go#L286-L296
test
t3rm1n4l/nitro
skiplist/node_alloc_amd64.go
debugMarkFree
func debugMarkFree(n *Node) { var block []byte l := int(nodeTypes[n.level].Size()) sh := (*reflect.SliceHeader)(unsafe.Pointer(&block)) sh.Data = uintptr(unsafe.Pointer(n)) sh.Len = l sh.Cap = l copy(block, freeBlockContent) }
go
func debugMarkFree(n *Node) { var block []byte l := int(nodeTypes[n.level].Size()) sh := (*reflect.SliceHeader)(unsafe.Pointer(&block)) sh.Data = uintptr(unsafe.Pointer(n)) sh.Len = l sh.Cap = l copy(block, freeBlockContent) }
[ "func", "debugMarkFree", "(", "n", "*", "Node", ")", "{", "var", "block", "[", "]", "byte", "\n", "l", ":=", "int", "(", "nodeTypes", "[", "n", ".", "level", "]", ".", "Size", "(", ")", ")", "\n", "sh", ":=", "(", "*", "reflect", ".", "SliceHeader", ")", "(", "unsafe", ".", "Pointer", "(", "&", "block", ")", ")", "\n", "sh", ".", "Data", "=", "uintptr", "(", "unsafe", ".", "Pointer", "(", "n", ")", ")", "\n", "sh", ".", "Len", "=", "l", "\n", "sh", ".", "Cap", "=", "l", "\n", "copy", "(", "block", ",", "freeBlockContent", ")", "\n", "}" ]
// Fill free blocks with a const // This can help debugging of memory reclaimer bugs
[ "Fill", "free", "blocks", "with", "a", "const", "This", "can", "help", "debugging", "of", "memory", "reclaimer", "bugs" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/skiplist/node_alloc_amd64.go#L276-L285
test
t3rm1n4l/nitro
iterator.go
Seek
func (it *Iterator) Seek(bs []byte) { itm := it.snap.db.newItem(bs, false) it.iter.Seek(unsafe.Pointer(itm)) it.skipUnwanted() }
go
func (it *Iterator) Seek(bs []byte) { itm := it.snap.db.newItem(bs, false) it.iter.Seek(unsafe.Pointer(itm)) it.skipUnwanted() }
[ "func", "(", "it", "*", "Iterator", ")", "Seek", "(", "bs", "[", "]", "byte", ")", "{", "itm", ":=", "it", ".", "snap", ".", "db", ".", "newItem", "(", "bs", ",", "false", ")", "\n", "it", ".", "iter", ".", "Seek", "(", "unsafe", ".", "Pointer", "(", "itm", ")", ")", "\n", "it", ".", "skipUnwanted", "(", ")", "\n", "}" ]
// Seek to a specified key or the next bigger one if an item with key does not // exist.
[ "Seek", "to", "a", "specified", "key", "or", "the", "next", "bigger", "one", "if", "an", "item", "with", "key", "does", "not", "exist", "." ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/iterator.go#L48-L52
test
t3rm1n4l/nitro
iterator.go
Next
func (it *Iterator) Next() { it.iter.Next() it.count++ it.skipUnwanted() if it.refreshRate > 0 && it.count > it.refreshRate { it.Refresh() it.count = 0 } }
go
func (it *Iterator) Next() { it.iter.Next() it.count++ it.skipUnwanted() if it.refreshRate > 0 && it.count > it.refreshRate { it.Refresh() it.count = 0 } }
[ "func", "(", "it", "*", "Iterator", ")", "Next", "(", ")", "{", "it", ".", "iter", ".", "Next", "(", ")", "\n", "it", ".", "count", "++", "\n", "it", ".", "skipUnwanted", "(", ")", "\n", "if", "it", ".", "refreshRate", ">", "0", "&&", "it", ".", "count", ">", "it", ".", "refreshRate", "{", "it", ".", "Refresh", "(", ")", "\n", "it", ".", "count", "=", "0", "\n", "}", "\n", "}" ]
// Next moves iterator cursor to the next item
[ "Next", "moves", "iterator", "cursor", "to", "the", "next", "item" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/iterator.go#L70-L78
test
t3rm1n4l/nitro
iterator.go
Refresh
func (it *Iterator) Refresh() { if it.Valid() { itm := it.snap.db.ptrToItem(it.GetNode().Item()) it.iter.Close() it.iter = it.snap.db.store.NewIterator(it.snap.db.iterCmp, it.buf) it.iter.Seek(unsafe.Pointer(itm)) } }
go
func (it *Iterator) Refresh() { if it.Valid() { itm := it.snap.db.ptrToItem(it.GetNode().Item()) it.iter.Close() it.iter = it.snap.db.store.NewIterator(it.snap.db.iterCmp, it.buf) it.iter.Seek(unsafe.Pointer(itm)) } }
[ "func", "(", "it", "*", "Iterator", ")", "Refresh", "(", ")", "{", "if", "it", ".", "Valid", "(", ")", "{", "itm", ":=", "it", ".", "snap", ".", "db", ".", "ptrToItem", "(", "it", ".", "GetNode", "(", ")", ".", "Item", "(", ")", ")", "\n", "it", ".", "iter", ".", "Close", "(", ")", "\n", "it", ".", "iter", "=", "it", ".", "snap", ".", "db", ".", "store", ".", "NewIterator", "(", "it", ".", "snap", ".", "db", ".", "iterCmp", ",", "it", ".", "buf", ")", "\n", "it", ".", "iter", ".", "Seek", "(", "unsafe", ".", "Pointer", "(", "itm", ")", ")", "\n", "}", "\n", "}" ]
// Refresh is a helper API to call refresh accessor tokens manually // This would enable SMR to reclaim objects faster if an iterator is // alive for a longer duration of time.
[ "Refresh", "is", "a", "helper", "API", "to", "call", "refresh", "accessor", "tokens", "manually", "This", "would", "enable", "SMR", "to", "reclaim", "objects", "faster", "if", "an", "iterator", "is", "alive", "for", "a", "longer", "duration", "of", "time", "." ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/iterator.go#L83-L90
test
t3rm1n4l/nitro
iterator.go
Close
func (it *Iterator) Close() { it.snap.Close() it.snap.db.store.FreeBuf(it.buf) it.iter.Close() }
go
func (it *Iterator) Close() { it.snap.Close() it.snap.db.store.FreeBuf(it.buf) it.iter.Close() }
[ "func", "(", "it", "*", "Iterator", ")", "Close", "(", ")", "{", "it", ".", "snap", ".", "Close", "(", ")", "\n", "it", ".", "snap", ".", "db", ".", "store", ".", "FreeBuf", "(", "it", ".", "buf", ")", "\n", "it", ".", "iter", ".", "Close", "(", ")", "\n", "}" ]
// Close executes destructor for iterator
[ "Close", "executes", "destructor", "for", "iterator" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/iterator.go#L100-L104
test
t3rm1n4l/nitro
iterator.go
NewIterator
func (m *Nitro) NewIterator(snap *Snapshot) *Iterator { if !snap.Open() { return nil } buf := snap.db.store.MakeBuf() return &Iterator{ snap: snap, iter: m.store.NewIterator(m.iterCmp, buf), buf: buf, } }
go
func (m *Nitro) NewIterator(snap *Snapshot) *Iterator { if !snap.Open() { return nil } buf := snap.db.store.MakeBuf() return &Iterator{ snap: snap, iter: m.store.NewIterator(m.iterCmp, buf), buf: buf, } }
[ "func", "(", "m", "*", "Nitro", ")", "NewIterator", "(", "snap", "*", "Snapshot", ")", "*", "Iterator", "{", "if", "!", "snap", ".", "Open", "(", ")", "{", "return", "nil", "\n", "}", "\n", "buf", ":=", "snap", ".", "db", ".", "store", ".", "MakeBuf", "(", ")", "\n", "return", "&", "Iterator", "{", "snap", ":", "snap", ",", "iter", ":", "m", ".", "store", ".", "NewIterator", "(", "m", ".", "iterCmp", ",", "buf", ")", ",", "buf", ":", "buf", ",", "}", "\n", "}" ]
// NewIterator creates an iterator for a Nitro snapshot
[ "NewIterator", "creates", "an", "iterator", "for", "a", "Nitro", "snapshot" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/iterator.go#L107-L117
test
t3rm1n4l/nitro
skiplist/merger.go
SeekFirst
func (mit *MergeIterator) SeekFirst() { for _, it := range mit.iters { it.SeekFirst() if it.Valid() { n := it.GetNode() mit.h = append(mit.h, heapItem{iter: it, n: n}) } } heap.Init(&mit.h) mit.Next() }
go
func (mit *MergeIterator) SeekFirst() { for _, it := range mit.iters { it.SeekFirst() if it.Valid() { n := it.GetNode() mit.h = append(mit.h, heapItem{iter: it, n: n}) } } heap.Init(&mit.h) mit.Next() }
[ "func", "(", "mit", "*", "MergeIterator", ")", "SeekFirst", "(", ")", "{", "for", "_", ",", "it", ":=", "range", "mit", ".", "iters", "{", "it", ".", "SeekFirst", "(", ")", "\n", "if", "it", ".", "Valid", "(", ")", "{", "n", ":=", "it", ".", "GetNode", "(", ")", "\n", "mit", ".", "h", "=", "append", "(", "mit", ".", "h", ",", "heapItem", "{", "iter", ":", "it", ",", "n", ":", "n", "}", ")", "\n", "}", "\n", "}", "\n", "heap", ".", "Init", "(", "&", "mit", ".", "h", ")", "\n", "mit", ".", "Next", "(", ")", "\n", "}" ]
// SeekFirst moves cursor to the first item
[ "SeekFirst", "moves", "cursor", "to", "the", "first", "item" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/skiplist/merger.go#L53-L64
test
t3rm1n4l/nitro
skiplist/merger.go
Next
func (mit *MergeIterator) Next() { mit.curr = nil if mit.h.Len() == 0 { return } o := heap.Pop(&mit.h) hi := o.(heapItem) mit.curr = hi.n hi.iter.Next() if hi.iter.Valid() { hi.n = hi.iter.GetNode() heap.Push(&mit.h, hi) } }
go
func (mit *MergeIterator) Next() { mit.curr = nil if mit.h.Len() == 0 { return } o := heap.Pop(&mit.h) hi := o.(heapItem) mit.curr = hi.n hi.iter.Next() if hi.iter.Valid() { hi.n = hi.iter.GetNode() heap.Push(&mit.h, hi) } }
[ "func", "(", "mit", "*", "MergeIterator", ")", "Next", "(", ")", "{", "mit", ".", "curr", "=", "nil", "\n", "if", "mit", ".", "h", ".", "Len", "(", ")", "==", "0", "{", "return", "\n", "}", "\n", "o", ":=", "heap", ".", "Pop", "(", "&", "mit", ".", "h", ")", "\n", "hi", ":=", "o", ".", "(", "heapItem", ")", "\n", "mit", ".", "curr", "=", "hi", ".", "n", "\n", "hi", ".", "iter", ".", "Next", "(", ")", "\n", "if", "hi", ".", "iter", ".", "Valid", "(", ")", "{", "hi", ".", "n", "=", "hi", ".", "iter", ".", "GetNode", "(", ")", "\n", "heap", ".", "Push", "(", "&", "mit", ".", "h", ",", "hi", ")", "\n", "}", "\n", "}" ]
// Next moves cursor to the next item
[ "Next", "moves", "cursor", "to", "the", "next", "item" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/skiplist/merger.go#L72-L86
test
t3rm1n4l/nitro
skiplist/merger.go
Seek
func (mit *MergeIterator) Seek(itm unsafe.Pointer) bool { var found bool for _, it := range mit.iters { if it.Seek(itm) { found = true } if it.Valid() { n := it.GetNode() mit.h = append(mit.h, heapItem{iter: it, n: n}) } } heap.Init(&mit.h) mit.Next() return found }
go
func (mit *MergeIterator) Seek(itm unsafe.Pointer) bool { var found bool for _, it := range mit.iters { if it.Seek(itm) { found = true } if it.Valid() { n := it.GetNode() mit.h = append(mit.h, heapItem{iter: it, n: n}) } } heap.Init(&mit.h) mit.Next() return found }
[ "func", "(", "mit", "*", "MergeIterator", ")", "Seek", "(", "itm", "unsafe", ".", "Pointer", ")", "bool", "{", "var", "found", "bool", "\n", "for", "_", ",", "it", ":=", "range", "mit", ".", "iters", "{", "if", "it", ".", "Seek", "(", "itm", ")", "{", "found", "=", "true", "\n", "}", "\n", "if", "it", ".", "Valid", "(", ")", "{", "n", ":=", "it", ".", "GetNode", "(", ")", "\n", "mit", ".", "h", "=", "append", "(", "mit", ".", "h", ",", "heapItem", "{", "iter", ":", "it", ",", "n", ":", "n", "}", ")", "\n", "}", "\n", "}", "\n", "heap", ".", "Init", "(", "&", "mit", ".", "h", ")", "\n", "mit", ".", "Next", "(", ")", "\n", "return", "found", "\n", "}" ]
// Seek moves cursor to the specified item, if present
[ "Seek", "moves", "cursor", "to", "the", "specified", "item", "if", "present" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/skiplist/merger.go#L89-L105
test
t3rm1n4l/nitro
nodelist.go
Keys
func (l *NodeList) Keys() (keys [][]byte) { node := l.head for node != nil { key := (*Item)(node.Item()).Bytes() keys = append(keys, key) node = node.GetLink() } return }
go
func (l *NodeList) Keys() (keys [][]byte) { node := l.head for node != nil { key := (*Item)(node.Item()).Bytes() keys = append(keys, key) node = node.GetLink() } return }
[ "func", "(", "l", "*", "NodeList", ")", "Keys", "(", ")", "(", "keys", "[", "]", "[", "]", "byte", ")", "{", "node", ":=", "l", ".", "head", "\n", "for", "node", "!=", "nil", "{", "key", ":=", "(", "*", "Item", ")", "(", "node", ".", "Item", "(", ")", ")", ".", "Bytes", "(", ")", "\n", "keys", "=", "append", "(", "keys", ",", "key", ")", "\n", "node", "=", "node", ".", "GetLink", "(", ")", "\n", "}", "\n", "return", "\n", "}" ]
// Keys returns all keys from the node list
[ "Keys", "returns", "all", "keys", "from", "the", "node", "list" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/nodelist.go#L30-L39
test
t3rm1n4l/nitro
nodelist.go
Remove
func (l *NodeList) Remove(key []byte) *skiplist.Node { var prev *skiplist.Node node := l.head for node != nil { nodeKey := (*Item)(node.Item()).Bytes() if bytes.Equal(nodeKey, key) { if prev == nil { l.head = node.GetLink() return node } prev.SetLink(node.GetLink()) return node } prev = node node = node.GetLink() } return nil }
go
func (l *NodeList) Remove(key []byte) *skiplist.Node { var prev *skiplist.Node node := l.head for node != nil { nodeKey := (*Item)(node.Item()).Bytes() if bytes.Equal(nodeKey, key) { if prev == nil { l.head = node.GetLink() return node } prev.SetLink(node.GetLink()) return node } prev = node node = node.GetLink() } return nil }
[ "func", "(", "l", "*", "NodeList", ")", "Remove", "(", "key", "[", "]", "byte", ")", "*", "skiplist", ".", "Node", "{", "var", "prev", "*", "skiplist", ".", "Node", "\n", "node", ":=", "l", ".", "head", "\n", "for", "node", "!=", "nil", "{", "nodeKey", ":=", "(", "*", "Item", ")", "(", "node", ".", "Item", "(", ")", ")", ".", "Bytes", "(", ")", "\n", "if", "bytes", ".", "Equal", "(", "nodeKey", ",", "key", ")", "{", "if", "prev", "==", "nil", "{", "l", ".", "head", "=", "node", ".", "GetLink", "(", ")", "\n", "return", "node", "\n", "}", "\n", "prev", ".", "SetLink", "(", "node", ".", "GetLink", "(", ")", ")", "\n", "return", "node", "\n", "}", "\n", "prev", "=", "node", "\n", "node", "=", "node", ".", "GetLink", "(", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Remove a key from the node list
[ "Remove", "a", "key", "from", "the", "node", "list" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/nodelist.go#L42-L61
test
t3rm1n4l/nitro
nodelist.go
Add
func (l *NodeList) Add(node *skiplist.Node) { node.SetLink(l.head) l.head = node }
go
func (l *NodeList) Add(node *skiplist.Node) { node.SetLink(l.head) l.head = node }
[ "func", "(", "l", "*", "NodeList", ")", "Add", "(", "node", "*", "skiplist", ".", "Node", ")", "{", "node", ".", "SetLink", "(", "l", ".", "head", ")", "\n", "l", ".", "head", "=", "node", "\n", "}" ]
// Add a key into the node list
[ "Add", "a", "key", "into", "the", "node", "list" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/nodelist.go#L64-L67
test
t3rm1n4l/nitro
skiplist/skiplist.go
NewWithConfig
func NewWithConfig(cfg Config) *Skiplist { if runtime.GOARCH != "amd64" { cfg.UseMemoryMgmt = false } s := &Skiplist{ Config: cfg, barrier: newAccessBarrier(cfg.UseMemoryMgmt, cfg.BarrierDestructor), } s.newNode = func(itm unsafe.Pointer, level int) *Node { return allocNode(itm, level, cfg.Malloc) } if cfg.UseMemoryMgmt { s.freeNode = func(n *Node) { if Debug { debugMarkFree(n) } cfg.Free(unsafe.Pointer(n)) } } else { s.freeNode = func(*Node) {} } head := allocNode(minItem, MaxLevel, nil) tail := allocNode(maxItem, MaxLevel, nil) for i := 0; i <= MaxLevel; i++ { head.setNext(i, tail, false) } s.head = head s.tail = tail return s }
go
func NewWithConfig(cfg Config) *Skiplist { if runtime.GOARCH != "amd64" { cfg.UseMemoryMgmt = false } s := &Skiplist{ Config: cfg, barrier: newAccessBarrier(cfg.UseMemoryMgmt, cfg.BarrierDestructor), } s.newNode = func(itm unsafe.Pointer, level int) *Node { return allocNode(itm, level, cfg.Malloc) } if cfg.UseMemoryMgmt { s.freeNode = func(n *Node) { if Debug { debugMarkFree(n) } cfg.Free(unsafe.Pointer(n)) } } else { s.freeNode = func(*Node) {} } head := allocNode(minItem, MaxLevel, nil) tail := allocNode(maxItem, MaxLevel, nil) for i := 0; i <= MaxLevel; i++ { head.setNext(i, tail, false) } s.head = head s.tail = tail return s }
[ "func", "NewWithConfig", "(", "cfg", "Config", ")", "*", "Skiplist", "{", "if", "runtime", ".", "GOARCH", "!=", "\"amd64\"", "{", "cfg", ".", "UseMemoryMgmt", "=", "false", "\n", "}", "\n", "s", ":=", "&", "Skiplist", "{", "Config", ":", "cfg", ",", "barrier", ":", "newAccessBarrier", "(", "cfg", ".", "UseMemoryMgmt", ",", "cfg", ".", "BarrierDestructor", ")", ",", "}", "\n", "s", ".", "newNode", "=", "func", "(", "itm", "unsafe", ".", "Pointer", ",", "level", "int", ")", "*", "Node", "{", "return", "allocNode", "(", "itm", ",", "level", ",", "cfg", ".", "Malloc", ")", "\n", "}", "\n", "if", "cfg", ".", "UseMemoryMgmt", "{", "s", ".", "freeNode", "=", "func", "(", "n", "*", "Node", ")", "{", "if", "Debug", "{", "debugMarkFree", "(", "n", ")", "\n", "}", "\n", "cfg", ".", "Free", "(", "unsafe", ".", "Pointer", "(", "n", ")", ")", "\n", "}", "\n", "}", "else", "{", "s", ".", "freeNode", "=", "func", "(", "*", "Node", ")", "{", "}", "\n", "}", "\n", "head", ":=", "allocNode", "(", "minItem", ",", "MaxLevel", ",", "nil", ")", "\n", "tail", ":=", "allocNode", "(", "maxItem", ",", "MaxLevel", ",", "nil", ")", "\n", "for", "i", ":=", "0", ";", "i", "<=", "MaxLevel", ";", "i", "++", "{", "head", ".", "setNext", "(", "i", ",", "tail", ",", "false", ")", "\n", "}", "\n", "s", ".", "head", "=", "head", "\n", "s", ".", "tail", "=", "tail", "\n", "return", "s", "\n", "}" ]
// NewWithConfig creates a config from given config
[ "NewWithConfig", "creates", "a", "config", "from", "given", "config" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/skiplist/skiplist.go#L85-L121
test
t3rm1n4l/nitro
skiplist/skiplist.go
FreeNode
func (s *Skiplist) FreeNode(n *Node, sts *Stats) { s.freeNode(n) sts.AddInt64(&sts.nodeFrees, 1) }
go
func (s *Skiplist) FreeNode(n *Node, sts *Stats) { s.freeNode(n) sts.AddInt64(&sts.nodeFrees, 1) }
[ "func", "(", "s", "*", "Skiplist", ")", "FreeNode", "(", "n", "*", "Node", ",", "sts", "*", "Stats", ")", "{", "s", ".", "freeNode", "(", "n", ")", "\n", "sts", ".", "AddInt64", "(", "&", "sts", ".", "nodeFrees", ",", "1", ")", "\n", "}" ]
// FreeNode deallocates the skiplist node memory
[ "FreeNode", "deallocates", "the", "skiplist", "node", "memory" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/skiplist/skiplist.go#L129-L132
test
t3rm1n4l/nitro
skiplist/skiplist.go
MakeBuf
func (s *Skiplist) MakeBuf() *ActionBuffer { return &ActionBuffer{ preds: make([]*Node, MaxLevel+1), succs: make([]*Node, MaxLevel+1), } }
go
func (s *Skiplist) MakeBuf() *ActionBuffer { return &ActionBuffer{ preds: make([]*Node, MaxLevel+1), succs: make([]*Node, MaxLevel+1), } }
[ "func", "(", "s", "*", "Skiplist", ")", "MakeBuf", "(", ")", "*", "ActionBuffer", "{", "return", "&", "ActionBuffer", "{", "preds", ":", "make", "(", "[", "]", "*", "Node", ",", "MaxLevel", "+", "1", ")", ",", "succs", ":", "make", "(", "[", "]", "*", "Node", ",", "MaxLevel", "+", "1", ")", ",", "}", "\n", "}" ]
// MakeBuf creates an action buffer
[ "MakeBuf", "creates", "an", "action", "buffer" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/skiplist/skiplist.go#L141-L146
test
t3rm1n4l/nitro
skiplist/skiplist.go
Size
func (s *Skiplist) Size(n *Node) int { return s.ItemSize(n.Item()) + n.Size() }
go
func (s *Skiplist) Size(n *Node) int { return s.ItemSize(n.Item()) + n.Size() }
[ "func", "(", "s", "*", "Skiplist", ")", "Size", "(", "n", "*", "Node", ")", "int", "{", "return", "s", ".", "ItemSize", "(", "n", ".", "Item", "(", ")", ")", "+", "n", ".", "Size", "(", ")", "\n", "}" ]
// Size returns the size of a node
[ "Size", "returns", "the", "size", "of", "a", "node" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/skiplist/skiplist.go#L153-L155
test
t3rm1n4l/nitro
skiplist/skiplist.go
NewLevel
func (s *Skiplist) NewLevel(randFn func() float32) int { var nextLevel int for ; randFn() < p; nextLevel++ { } if nextLevel > MaxLevel { nextLevel = MaxLevel } level := int(atomic.LoadInt32(&s.level)) if nextLevel > level { if atomic.CompareAndSwapInt32(&s.level, int32(level), int32(level+1)) { nextLevel = level + 1 } else { nextLevel = level } } return nextLevel }
go
func (s *Skiplist) NewLevel(randFn func() float32) int { var nextLevel int for ; randFn() < p; nextLevel++ { } if nextLevel > MaxLevel { nextLevel = MaxLevel } level := int(atomic.LoadInt32(&s.level)) if nextLevel > level { if atomic.CompareAndSwapInt32(&s.level, int32(level), int32(level+1)) { nextLevel = level + 1 } else { nextLevel = level } } return nextLevel }
[ "func", "(", "s", "*", "Skiplist", ")", "NewLevel", "(", "randFn", "func", "(", ")", "float32", ")", "int", "{", "var", "nextLevel", "int", "\n", "for", ";", "randFn", "(", ")", "<", "p", ";", "nextLevel", "++", "{", "}", "\n", "if", "nextLevel", ">", "MaxLevel", "{", "nextLevel", "=", "MaxLevel", "\n", "}", "\n", "level", ":=", "int", "(", "atomic", ".", "LoadInt32", "(", "&", "s", ".", "level", ")", ")", "\n", "if", "nextLevel", ">", "level", "{", "if", "atomic", ".", "CompareAndSwapInt32", "(", "&", "s", ".", "level", ",", "int32", "(", "level", ")", ",", "int32", "(", "level", "+", "1", ")", ")", "{", "nextLevel", "=", "level", "+", "1", "\n", "}", "else", "{", "nextLevel", "=", "level", "\n", "}", "\n", "}", "\n", "return", "nextLevel", "\n", "}" ]
// NewLevel returns a random level for the next node
[ "NewLevel", "returns", "a", "random", "level", "for", "the", "next", "node" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/skiplist/skiplist.go#L158-L178
test
t3rm1n4l/nitro
skiplist/skiplist.go
Insert
func (s *Skiplist) Insert(itm unsafe.Pointer, cmp CompareFn, buf *ActionBuffer, sts *Stats) (success bool) { _, success = s.Insert2(itm, cmp, nil, buf, rand.Float32, sts) return }
go
func (s *Skiplist) Insert(itm unsafe.Pointer, cmp CompareFn, buf *ActionBuffer, sts *Stats) (success bool) { _, success = s.Insert2(itm, cmp, nil, buf, rand.Float32, sts) return }
[ "func", "(", "s", "*", "Skiplist", ")", "Insert", "(", "itm", "unsafe", ".", "Pointer", ",", "cmp", "CompareFn", ",", "buf", "*", "ActionBuffer", ",", "sts", "*", "Stats", ")", "(", "success", "bool", ")", "{", "_", ",", "success", "=", "s", ".", "Insert2", "(", "itm", ",", "cmp", ",", "nil", ",", "buf", ",", "rand", ".", "Float32", ",", "sts", ")", "\n", "return", "\n", "}" ]
// Insert adds an item into the skiplist
[ "Insert", "adds", "an", "item", "into", "the", "skiplist" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/skiplist/skiplist.go#L232-L236
test
t3rm1n4l/nitro
skiplist/skiplist.go
Insert2
func (s *Skiplist) Insert2(itm unsafe.Pointer, inscmp CompareFn, eqCmp CompareFn, buf *ActionBuffer, randFn func() float32, sts *Stats) (*Node, bool) { itemLevel := s.NewLevel(randFn) return s.Insert3(itm, inscmp, eqCmp, buf, itemLevel, false, sts) }
go
func (s *Skiplist) Insert2(itm unsafe.Pointer, inscmp CompareFn, eqCmp CompareFn, buf *ActionBuffer, randFn func() float32, sts *Stats) (*Node, bool) { itemLevel := s.NewLevel(randFn) return s.Insert3(itm, inscmp, eqCmp, buf, itemLevel, false, sts) }
[ "func", "(", "s", "*", "Skiplist", ")", "Insert2", "(", "itm", "unsafe", ".", "Pointer", ",", "inscmp", "CompareFn", ",", "eqCmp", "CompareFn", ",", "buf", "*", "ActionBuffer", ",", "randFn", "func", "(", ")", "float32", ",", "sts", "*", "Stats", ")", "(", "*", "Node", ",", "bool", ")", "{", "itemLevel", ":=", "s", ".", "NewLevel", "(", "randFn", ")", "\n", "return", "s", ".", "Insert3", "(", "itm", ",", "inscmp", ",", "eqCmp", ",", "buf", ",", "itemLevel", ",", "false", ",", "sts", ")", "\n", "}" ]
// Insert2 is a more verbose version of Insert
[ "Insert2", "is", "a", "more", "verbose", "version", "of", "Insert" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/skiplist/skiplist.go#L239-L243
test
t3rm1n4l/nitro
skiplist/skiplist.go
Insert3
func (s *Skiplist) Insert3(itm unsafe.Pointer, insCmp CompareFn, eqCmp CompareFn, buf *ActionBuffer, itemLevel int, skipFindPath bool, sts *Stats) (*Node, bool) { token := s.barrier.Acquire() defer s.barrier.Release(token) x := s.newNode(itm, itemLevel) retry: if skipFindPath { skipFindPath = false } else { if s.findPath(itm, insCmp, buf, sts) != nil || eqCmp != nil && compare(eqCmp, itm, buf.preds[0].Item()) == 0 { s.freeNode(x) return nil, false } } // Set all next links for the node non-atomically for i := 0; i <= int(itemLevel); i++ { x.setNext(i, buf.succs[i], false) } // Now node is part of the skiplist if !buf.preds[0].dcasNext(0, buf.succs[0], x, false, false) { sts.AddUint64(&sts.insertConflicts, 1) goto retry } // Add to index levels for i := 1; i <= int(itemLevel); i++ { fixThisLevel: for { nodeNext, deleted := x.getNext(i) next := buf.succs[i] // Update the node's next pointer at current level if required. // This is the only thread which can modify next pointer at this level // The dcas operation can fail only if another thread marked delete if deleted || (nodeNext != next && !x.dcasNext(i, nodeNext, next, false, false)) { goto finished } if buf.preds[i].dcasNext(i, next, x, false, false) { break fixThisLevel } s.findPath(itm, insCmp, buf, sts) } } finished: sts.AddInt64(&sts.nodeAllocs, 1) sts.AddInt64(&sts.levelNodesCount[itemLevel], 1) sts.AddInt64(&sts.usedBytes, int64(s.Size(x))) return x, true }
go
func (s *Skiplist) Insert3(itm unsafe.Pointer, insCmp CompareFn, eqCmp CompareFn, buf *ActionBuffer, itemLevel int, skipFindPath bool, sts *Stats) (*Node, bool) { token := s.barrier.Acquire() defer s.barrier.Release(token) x := s.newNode(itm, itemLevel) retry: if skipFindPath { skipFindPath = false } else { if s.findPath(itm, insCmp, buf, sts) != nil || eqCmp != nil && compare(eqCmp, itm, buf.preds[0].Item()) == 0 { s.freeNode(x) return nil, false } } // Set all next links for the node non-atomically for i := 0; i <= int(itemLevel); i++ { x.setNext(i, buf.succs[i], false) } // Now node is part of the skiplist if !buf.preds[0].dcasNext(0, buf.succs[0], x, false, false) { sts.AddUint64(&sts.insertConflicts, 1) goto retry } // Add to index levels for i := 1; i <= int(itemLevel); i++ { fixThisLevel: for { nodeNext, deleted := x.getNext(i) next := buf.succs[i] // Update the node's next pointer at current level if required. // This is the only thread which can modify next pointer at this level // The dcas operation can fail only if another thread marked delete if deleted || (nodeNext != next && !x.dcasNext(i, nodeNext, next, false, false)) { goto finished } if buf.preds[i].dcasNext(i, next, x, false, false) { break fixThisLevel } s.findPath(itm, insCmp, buf, sts) } } finished: sts.AddInt64(&sts.nodeAllocs, 1) sts.AddInt64(&sts.levelNodesCount[itemLevel], 1) sts.AddInt64(&sts.usedBytes, int64(s.Size(x))) return x, true }
[ "func", "(", "s", "*", "Skiplist", ")", "Insert3", "(", "itm", "unsafe", ".", "Pointer", ",", "insCmp", "CompareFn", ",", "eqCmp", "CompareFn", ",", "buf", "*", "ActionBuffer", ",", "itemLevel", "int", ",", "skipFindPath", "bool", ",", "sts", "*", "Stats", ")", "(", "*", "Node", ",", "bool", ")", "{", "token", ":=", "s", ".", "barrier", ".", "Acquire", "(", ")", "\n", "defer", "s", ".", "barrier", ".", "Release", "(", "token", ")", "\n", "x", ":=", "s", ".", "newNode", "(", "itm", ",", "itemLevel", ")", "\n", "retry", ":", "if", "skipFindPath", "{", "skipFindPath", "=", "false", "\n", "}", "else", "{", "if", "s", ".", "findPath", "(", "itm", ",", "insCmp", ",", "buf", ",", "sts", ")", "!=", "nil", "||", "eqCmp", "!=", "nil", "&&", "compare", "(", "eqCmp", ",", "itm", ",", "buf", ".", "preds", "[", "0", "]", ".", "Item", "(", ")", ")", "==", "0", "{", "s", ".", "freeNode", "(", "x", ")", "\n", "return", "nil", ",", "false", "\n", "}", "\n", "}", "\n", "for", "i", ":=", "0", ";", "i", "<=", "int", "(", "itemLevel", ")", ";", "i", "++", "{", "x", ".", "setNext", "(", "i", ",", "buf", ".", "succs", "[", "i", "]", ",", "false", ")", "\n", "}", "\n", "if", "!", "buf", ".", "preds", "[", "0", "]", ".", "dcasNext", "(", "0", ",", "buf", ".", "succs", "[", "0", "]", ",", "x", ",", "false", ",", "false", ")", "{", "sts", ".", "AddUint64", "(", "&", "sts", ".", "insertConflicts", ",", "1", ")", "\n", "goto", "retry", "\n", "}", "\n", "for", "i", ":=", "1", ";", "i", "<=", "int", "(", "itemLevel", ")", ";", "i", "++", "{", "fixThisLevel", ":", "for", "{", "nodeNext", ",", "deleted", ":=", "x", ".", "getNext", "(", "i", ")", "\n", "next", ":=", "buf", ".", "succs", "[", "i", "]", "\n", "if", "deleted", "||", "(", "nodeNext", "!=", "next", "&&", "!", "x", ".", "dcasNext", "(", "i", ",", "nodeNext", ",", "next", ",", "false", ",", "false", ")", ")", "{", "goto", "finished", "\n", "}", "\n", "if", "buf", ".", "preds", "[", "i", "]", ".", "dcasNext", "(", "i", ",", "next", ",", "x", ",", "false", ",", "false", ")", "{", "break", "fixThisLevel", "\n", "}", "\n", "s", ".", "findPath", "(", "itm", ",", "insCmp", ",", "buf", ",", "sts", ")", "\n", "}", "\n", "}", "\n", "finished", ":", "sts", ".", "AddInt64", "(", "&", "sts", ".", "nodeAllocs", ",", "1", ")", "\n", "sts", ".", "AddInt64", "(", "&", "sts", ".", "levelNodesCount", "[", "itemLevel", "]", ",", "1", ")", "\n", "sts", ".", "AddInt64", "(", "&", "sts", ".", "usedBytes", ",", "int64", "(", "s", ".", "Size", "(", "x", ")", ")", ")", "\n", "return", "x", ",", "true", "\n", "}" ]
// Insert3 is more verbose version of Insert2
[ "Insert3", "is", "more", "verbose", "version", "of", "Insert2" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/skiplist/skiplist.go#L246-L304
test
t3rm1n4l/nitro
skiplist/skiplist.go
Delete
func (s *Skiplist) Delete(itm unsafe.Pointer, cmp CompareFn, buf *ActionBuffer, sts *Stats) bool { token := s.barrier.Acquire() defer s.barrier.Release(token) found := s.findPath(itm, cmp, buf, sts) != nil if !found { return false } delNode := buf.succs[0] return s.deleteNode(delNode, cmp, buf, sts) }
go
func (s *Skiplist) Delete(itm unsafe.Pointer, cmp CompareFn, buf *ActionBuffer, sts *Stats) bool { token := s.barrier.Acquire() defer s.barrier.Release(token) found := s.findPath(itm, cmp, buf, sts) != nil if !found { return false } delNode := buf.succs[0] return s.deleteNode(delNode, cmp, buf, sts) }
[ "func", "(", "s", "*", "Skiplist", ")", "Delete", "(", "itm", "unsafe", ".", "Pointer", ",", "cmp", "CompareFn", ",", "buf", "*", "ActionBuffer", ",", "sts", "*", "Stats", ")", "bool", "{", "token", ":=", "s", ".", "barrier", ".", "Acquire", "(", ")", "\n", "defer", "s", ".", "barrier", ".", "Release", "(", "token", ")", "\n", "found", ":=", "s", ".", "findPath", "(", "itm", ",", "cmp", ",", "buf", ",", "sts", ")", "!=", "nil", "\n", "if", "!", "found", "{", "return", "false", "\n", "}", "\n", "delNode", ":=", "buf", ".", "succs", "[", "0", "]", "\n", "return", "s", ".", "deleteNode", "(", "delNode", ",", "cmp", ",", "buf", ",", "sts", ")", "\n", "}" ]
// Delete an item from the skiplist
[ "Delete", "an", "item", "from", "the", "skiplist" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/skiplist/skiplist.go#L324-L336
test
t3rm1n4l/nitro
skiplist/skiplist.go
DeleteNode
func (s *Skiplist) DeleteNode(n *Node, cmp CompareFn, buf *ActionBuffer, sts *Stats) bool { token := s.barrier.Acquire() defer s.barrier.Release(token) return s.deleteNode(n, cmp, buf, sts) }
go
func (s *Skiplist) DeleteNode(n *Node, cmp CompareFn, buf *ActionBuffer, sts *Stats) bool { token := s.barrier.Acquire() defer s.barrier.Release(token) return s.deleteNode(n, cmp, buf, sts) }
[ "func", "(", "s", "*", "Skiplist", ")", "DeleteNode", "(", "n", "*", "Node", ",", "cmp", "CompareFn", ",", "buf", "*", "ActionBuffer", ",", "sts", "*", "Stats", ")", "bool", "{", "token", ":=", "s", ".", "barrier", ".", "Acquire", "(", ")", "\n", "defer", "s", ".", "barrier", ".", "Release", "(", "token", ")", "\n", "return", "s", ".", "deleteNode", "(", "n", ",", "cmp", ",", "buf", ",", "sts", ")", "\n", "}" ]
// DeleteNode an item from the skiplist by specifying its node
[ "DeleteNode", "an", "item", "from", "the", "skiplist", "by", "specifying", "its", "node" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/skiplist/skiplist.go#L339-L345
test
t3rm1n4l/nitro
skiplist/skiplist.go
GetRangeSplitItems
func (s *Skiplist) GetRangeSplitItems(nways int) []unsafe.Pointer { var deleted bool repeat: var itms []unsafe.Pointer var finished bool l := int(atomic.LoadInt32(&s.level)) for ; l >= 0; l-- { c := int(atomic.LoadInt64(&s.Stats.levelNodesCount[l]) + 1) if c >= nways { perSplit := c / nways node := s.head for j := 0; node != s.tail && !finished; j++ { if j == perSplit { j = -1 itms = append(itms, node.Item()) finished = len(itms) == nways-1 } node, deleted = node.getNext(l) if deleted { goto repeat } } break } } return itms }
go
func (s *Skiplist) GetRangeSplitItems(nways int) []unsafe.Pointer { var deleted bool repeat: var itms []unsafe.Pointer var finished bool l := int(atomic.LoadInt32(&s.level)) for ; l >= 0; l-- { c := int(atomic.LoadInt64(&s.Stats.levelNodesCount[l]) + 1) if c >= nways { perSplit := c / nways node := s.head for j := 0; node != s.tail && !finished; j++ { if j == perSplit { j = -1 itms = append(itms, node.Item()) finished = len(itms) == nways-1 } node, deleted = node.getNext(l) if deleted { goto repeat } } break } } return itms }
[ "func", "(", "s", "*", "Skiplist", ")", "GetRangeSplitItems", "(", "nways", "int", ")", "[", "]", "unsafe", ".", "Pointer", "{", "var", "deleted", "bool", "\n", "repeat", ":", "var", "itms", "[", "]", "unsafe", ".", "Pointer", "\n", "var", "finished", "bool", "\n", "l", ":=", "int", "(", "atomic", ".", "LoadInt32", "(", "&", "s", ".", "level", ")", ")", "\n", "for", ";", "l", ">=", "0", ";", "l", "--", "{", "c", ":=", "int", "(", "atomic", ".", "LoadInt64", "(", "&", "s", ".", "Stats", ".", "levelNodesCount", "[", "l", "]", ")", "+", "1", ")", "\n", "if", "c", ">=", "nways", "{", "perSplit", ":=", "c", "/", "nways", "\n", "node", ":=", "s", ".", "head", "\n", "for", "j", ":=", "0", ";", "node", "!=", "s", ".", "tail", "&&", "!", "finished", ";", "j", "++", "{", "if", "j", "==", "perSplit", "{", "j", "=", "-", "1", "\n", "itms", "=", "append", "(", "itms", ",", "node", ".", "Item", "(", ")", ")", "\n", "finished", "=", "len", "(", "itms", ")", "==", "nways", "-", "1", "\n", "}", "\n", "node", ",", "deleted", "=", "node", ".", "getNext", "(", "l", ")", "\n", "if", "deleted", "{", "goto", "repeat", "\n", "}", "\n", "}", "\n", "break", "\n", "}", "\n", "}", "\n", "return", "itms", "\n", "}" ]
// GetRangeSplitItems returns `nways` split range pivots of the skiplist items // Explicit barrier and release should be used by the caller before // and after this function call
[ "GetRangeSplitItems", "returns", "nways", "split", "range", "pivots", "of", "the", "skiplist", "items", "Explicit", "barrier", "and", "release", "should", "be", "used", "by", "the", "caller", "before", "and", "after", "this", "function", "call" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/skiplist/skiplist.go#L360-L390
test
t3rm1n4l/nitro
item.go
Bytes
func (itm *Item) Bytes() (bs []byte) { l := itm.dataLen dataOffset := uintptr(unsafe.Pointer(itm)) + itemHeaderSize hdr := (*reflect.SliceHeader)(unsafe.Pointer(&bs)) hdr.Data = dataOffset hdr.Len = int(l) hdr.Cap = hdr.Len return }
go
func (itm *Item) Bytes() (bs []byte) { l := itm.dataLen dataOffset := uintptr(unsafe.Pointer(itm)) + itemHeaderSize hdr := (*reflect.SliceHeader)(unsafe.Pointer(&bs)) hdr.Data = dataOffset hdr.Len = int(l) hdr.Cap = hdr.Len return }
[ "func", "(", "itm", "*", "Item", ")", "Bytes", "(", ")", "(", "bs", "[", "]", "byte", ")", "{", "l", ":=", "itm", ".", "dataLen", "\n", "dataOffset", ":=", "uintptr", "(", "unsafe", ".", "Pointer", "(", "itm", ")", ")", "+", "itemHeaderSize", "\n", "hdr", ":=", "(", "*", "reflect", ".", "SliceHeader", ")", "(", "unsafe", ".", "Pointer", "(", "&", "bs", ")", ")", "\n", "hdr", ".", "Data", "=", "dataOffset", "\n", "hdr", ".", "Len", "=", "int", "(", "l", ")", "\n", "hdr", ".", "Cap", "=", "hdr", ".", "Len", "\n", "return", "\n", "}" ]
// Bytes return item data bytes
[ "Bytes", "return", "item", "data", "bytes" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/item.go#L96-L105
test
t3rm1n4l/nitro
item.go
ItemSize
func ItemSize(p unsafe.Pointer) int { itm := (*Item)(p) return int(itemHeaderSize + uintptr(itm.dataLen)) }
go
func ItemSize(p unsafe.Pointer) int { itm := (*Item)(p) return int(itemHeaderSize + uintptr(itm.dataLen)) }
[ "func", "ItemSize", "(", "p", "unsafe", ".", "Pointer", ")", "int", "{", "itm", ":=", "(", "*", "Item", ")", "(", "p", ")", "\n", "return", "int", "(", "itemHeaderSize", "+", "uintptr", "(", "itm", ".", "dataLen", ")", ")", "\n", "}" ]
// ItemSize returns total bytes consumed by item representation
[ "ItemSize", "returns", "total", "bytes", "consumed", "by", "item", "representation" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/item.go#L108-L111
test
t3rm1n4l/nitro
item.go
KVFromBytes
func KVFromBytes(bs []byte) (k, v []byte) { klen := int(binary.LittleEndian.Uint16(bs[0:2])) return bs[2 : 2+klen], bs[2+klen:] }
go
func KVFromBytes(bs []byte) (k, v []byte) { klen := int(binary.LittleEndian.Uint16(bs[0:2])) return bs[2 : 2+klen], bs[2+klen:] }
[ "func", "KVFromBytes", "(", "bs", "[", "]", "byte", ")", "(", "k", ",", "v", "[", "]", "byte", ")", "{", "klen", ":=", "int", "(", "binary", ".", "LittleEndian", ".", "Uint16", "(", "bs", "[", "0", ":", "2", "]", ")", ")", "\n", "return", "bs", "[", "2", ":", "2", "+", "klen", "]", ",", "bs", "[", "2", "+", "klen", ":", "]", "\n", "}" ]
// KVFromBytes extracts key-value pair from item bytes returned by iterator
[ "KVFromBytes", "extracts", "key", "-", "value", "pair", "from", "item", "bytes", "returned", "by", "iterator" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/item.go#L126-L129
test
t3rm1n4l/nitro
item.go
CompareKV
func CompareKV(a []byte, b []byte) int { la := int(binary.LittleEndian.Uint16(a[0:2])) lb := int(binary.LittleEndian.Uint16(b[0:2])) return bytes.Compare(a[2:2+la], b[2:2+lb]) }
go
func CompareKV(a []byte, b []byte) int { la := int(binary.LittleEndian.Uint16(a[0:2])) lb := int(binary.LittleEndian.Uint16(b[0:2])) return bytes.Compare(a[2:2+la], b[2:2+lb]) }
[ "func", "CompareKV", "(", "a", "[", "]", "byte", ",", "b", "[", "]", "byte", ")", "int", "{", "la", ":=", "int", "(", "binary", ".", "LittleEndian", ".", "Uint16", "(", "a", "[", "0", ":", "2", "]", ")", ")", "\n", "lb", ":=", "int", "(", "binary", ".", "LittleEndian", ".", "Uint16", "(", "b", "[", "0", ":", "2", "]", ")", ")", "\n", "return", "bytes", ".", "Compare", "(", "a", "[", "2", ":", "2", "+", "la", "]", ",", "b", "[", "2", ":", "2", "+", "lb", "]", ")", "\n", "}" ]
// CompareKV is a comparator for KV item
[ "CompareKV", "is", "a", "comparator", "for", "KV", "item" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/item.go#L132-L137
test
intelsdi-x/gomit
event_controller.go
Emit
func (e *EventController) Emit(b EventBody) (int, error) { // int used to count the number of Handlers fired. var i int // We build an event struct to contain the Body and generate a Header. event := Event{Header: generateHeader(), Body: b} // Fire a gorountine for each handler. // By design the is no waiting for any Handlers to complete // before firing another. Therefore there is also no guarantee // that any Handler will predictably fire before another one. // // Any synchronizing needs to be within the Handler. for _, h := range e.Handlers { i++ go h.HandleGomitEvent(event) } return i, nil }
go
func (e *EventController) Emit(b EventBody) (int, error) { // int used to count the number of Handlers fired. var i int // We build an event struct to contain the Body and generate a Header. event := Event{Header: generateHeader(), Body: b} // Fire a gorountine for each handler. // By design the is no waiting for any Handlers to complete // before firing another. Therefore there is also no guarantee // that any Handler will predictably fire before another one. // // Any synchronizing needs to be within the Handler. for _, h := range e.Handlers { i++ go h.HandleGomitEvent(event) } return i, nil }
[ "func", "(", "e", "*", "EventController", ")", "Emit", "(", "b", "EventBody", ")", "(", "int", ",", "error", ")", "{", "var", "i", "int", "\n", "event", ":=", "Event", "{", "Header", ":", "generateHeader", "(", ")", ",", "Body", ":", "b", "}", "\n", "for", "_", ",", "h", ":=", "range", "e", ".", "Handlers", "{", "i", "++", "\n", "go", "h", ".", "HandleGomitEvent", "(", "event", ")", "\n", "}", "\n", "return", "i", ",", "nil", "\n", "}" ]
// Emits an Event from the EventController. Takes an EventBody which is used // to build an Event. Returns number of handlers that // received the event and error if an error was raised.
[ "Emits", "an", "Event", "from", "the", "EventController", ".", "Takes", "an", "EventBody", "which", "is", "used", "to", "build", "an", "Event", ".", "Returns", "number", "of", "handlers", "that", "received", "the", "event", "and", "error", "if", "an", "error", "was", "raised", "." ]
286c3ad6599724faed681cd18a9ff595b00d9f3f
https://github.com/intelsdi-x/gomit/blob/286c3ad6599724faed681cd18a9ff595b00d9f3f/event_controller.go#L66-L84
test
intelsdi-x/gomit
event_controller.go
UnregisterHandler
func (e *EventController) UnregisterHandler(n string) error { e.handlerMutex.Lock() delete(e.Handlers, n) e.handlerMutex.Unlock() return nil }
go
func (e *EventController) UnregisterHandler(n string) error { e.handlerMutex.Lock() delete(e.Handlers, n) e.handlerMutex.Unlock() return nil }
[ "func", "(", "e", "*", "EventController", ")", "UnregisterHandler", "(", "n", "string", ")", "error", "{", "e", ".", "handlerMutex", ".", "Lock", "(", ")", "\n", "delete", "(", "e", ".", "Handlers", ",", "n", ")", "\n", "e", ".", "handlerMutex", ".", "Unlock", "(", ")", "\n", "return", "nil", "\n", "}" ]
// Unregisters Handler from the EventController. This is idempotent where if a Handler is // not registered no error is returned.
[ "Unregisters", "Handler", "from", "the", "EventController", ".", "This", "is", "idempotent", "where", "if", "a", "Handler", "is", "not", "registered", "no", "error", "is", "returned", "." ]
286c3ad6599724faed681cd18a9ff595b00d9f3f
https://github.com/intelsdi-x/gomit/blob/286c3ad6599724faed681cd18a9ff595b00d9f3f/event_controller.go#L104-L111
test
intelsdi-x/gomit
event_controller.go
IsHandlerRegistered
func (e *EventController) IsHandlerRegistered(n string) bool { _, x := e.Handlers[n] return x }
go
func (e *EventController) IsHandlerRegistered(n string) bool { _, x := e.Handlers[n] return x }
[ "func", "(", "e", "*", "EventController", ")", "IsHandlerRegistered", "(", "n", "string", ")", "bool", "{", "_", ",", "x", ":=", "e", ".", "Handlers", "[", "n", "]", "\n", "return", "x", "\n", "}" ]
// Returns bool on whether the Handler is registered with this EventController.
[ "Returns", "bool", "on", "whether", "the", "Handler", "is", "registered", "with", "this", "EventController", "." ]
286c3ad6599724faed681cd18a9ff595b00d9f3f
https://github.com/intelsdi-x/gomit/blob/286c3ad6599724faed681cd18a9ff595b00d9f3f/event_controller.go#L114-L117
test
t3rm1n4l/nitro
nitro.go
CompareNitro
func CompareNitro(this unsafe.Pointer, that unsafe.Pointer) int { thisItem := (*Nitro)(this) thatItem := (*Nitro)(that) return int(thisItem.id - thatItem.id) }
go
func CompareNitro(this unsafe.Pointer, that unsafe.Pointer) int { thisItem := (*Nitro)(this) thatItem := (*Nitro)(that) return int(thisItem.id - thatItem.id) }
[ "func", "CompareNitro", "(", "this", "unsafe", ".", "Pointer", ",", "that", "unsafe", ".", "Pointer", ")", "int", "{", "thisItem", ":=", "(", "*", "Nitro", ")", "(", "this", ")", "\n", "thatItem", ":=", "(", "*", "Nitro", ")", "(", "that", ")", "\n", "return", "int", "(", "thisItem", ".", "id", "-", "thatItem", ".", "id", ")", "\n", "}" ]
// CompareNitro implements comparator for Nitro instances based on its id
[ "CompareNitro", "implements", "comparator", "for", "Nitro", "instances", "based", "on", "its", "id" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/nitro.go#L79-L84
test
t3rm1n4l/nitro
nitro.go
DefaultConfig
func DefaultConfig() Config { var cfg Config cfg.SetKeyComparator(defaultKeyCmp) cfg.fileType = RawdbFile cfg.useMemoryMgmt = false cfg.refreshRate = defaultRefreshRate return cfg }
go
func DefaultConfig() Config { var cfg Config cfg.SetKeyComparator(defaultKeyCmp) cfg.fileType = RawdbFile cfg.useMemoryMgmt = false cfg.refreshRate = defaultRefreshRate return cfg }
[ "func", "DefaultConfig", "(", ")", "Config", "{", "var", "cfg", "Config", "\n", "cfg", ".", "SetKeyComparator", "(", "defaultKeyCmp", ")", "\n", "cfg", ".", "fileType", "=", "RawdbFile", "\n", "cfg", ".", "useMemoryMgmt", "=", "false", "\n", "cfg", ".", "refreshRate", "=", "defaultRefreshRate", "\n", "return", "cfg", "\n", "}" ]
// DefaultConfig - Nitro configuration
[ "DefaultConfig", "-", "Nitro", "configuration" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/nitro.go#L87-L94
test
t3rm1n4l/nitro
nitro.go
Delete
func (w *Writer) Delete(bs []byte) (success bool) { _, success = w.Delete2(bs) return }
go
func (w *Writer) Delete(bs []byte) (success bool) { _, success = w.Delete2(bs) return }
[ "func", "(", "w", "*", "Writer", ")", "Delete", "(", "bs", "[", "]", "byte", ")", "(", "success", "bool", ")", "{", "_", ",", "success", "=", "w", ".", "Delete2", "(", "bs", ")", "\n", "return", "\n", "}" ]
// Delete an item // Delete always succeed if an item exists.
[ "Delete", "an", "item", "Delete", "always", "succeed", "if", "an", "item", "exists", "." ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/nitro.go#L220-L223
test
t3rm1n4l/nitro
nitro.go
GetNode
func (w *Writer) GetNode(bs []byte) *skiplist.Node { iter := w.store.NewIterator(w.iterCmp, w.buf) defer iter.Close() x := w.newItem(bs, false) x.bornSn = w.getCurrSn() if found := iter.SeekWithCmp(unsafe.Pointer(x), w.insCmp, w.existCmp); found { return iter.GetNode() } return nil }
go
func (w *Writer) GetNode(bs []byte) *skiplist.Node { iter := w.store.NewIterator(w.iterCmp, w.buf) defer iter.Close() x := w.newItem(bs, false) x.bornSn = w.getCurrSn() if found := iter.SeekWithCmp(unsafe.Pointer(x), w.insCmp, w.existCmp); found { return iter.GetNode() } return nil }
[ "func", "(", "w", "*", "Writer", ")", "GetNode", "(", "bs", "[", "]", "byte", ")", "*", "skiplist", ".", "Node", "{", "iter", ":=", "w", ".", "store", ".", "NewIterator", "(", "w", ".", "iterCmp", ",", "w", ".", "buf", ")", "\n", "defer", "iter", ".", "Close", "(", ")", "\n", "x", ":=", "w", ".", "newItem", "(", "bs", ",", "false", ")", "\n", "x", ".", "bornSn", "=", "w", ".", "getCurrSn", "(", ")", "\n", "if", "found", ":=", "iter", ".", "SeekWithCmp", "(", "unsafe", ".", "Pointer", "(", "x", ")", ",", "w", ".", "insCmp", ",", "w", ".", "existCmp", ")", ";", "found", "{", "return", "iter", ".", "GetNode", "(", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// GetNode implements lookup of an item and return its skiplist Node // This API enables to lookup an item without using a snapshot handle.
[ "GetNode", "implements", "lookup", "of", "an", "item", "and", "return", "its", "skiplist", "Node", "This", "API", "enables", "to", "lookup", "an", "item", "without", "using", "a", "snapshot", "handle", "." ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/nitro.go#L269-L281
test
t3rm1n4l/nitro
nitro.go
SetKeyComparator
func (cfg *Config) SetKeyComparator(cmp KeyCompare) { cfg.keyCmp = cmp cfg.insCmp = newInsertCompare(cmp) cfg.iterCmp = newIterCompare(cmp) cfg.existCmp = newExistCompare(cmp) }
go
func (cfg *Config) SetKeyComparator(cmp KeyCompare) { cfg.keyCmp = cmp cfg.insCmp = newInsertCompare(cmp) cfg.iterCmp = newIterCompare(cmp) cfg.existCmp = newExistCompare(cmp) }
[ "func", "(", "cfg", "*", "Config", ")", "SetKeyComparator", "(", "cmp", "KeyCompare", ")", "{", "cfg", ".", "keyCmp", "=", "cmp", "\n", "cfg", ".", "insCmp", "=", "newInsertCompare", "(", "cmp", ")", "\n", "cfg", ".", "iterCmp", "=", "newIterCompare", "(", "cmp", ")", "\n", "cfg", ".", "existCmp", "=", "newExistCompare", "(", "cmp", ")", "\n", "}" ]
// SetKeyComparator provides key comparator for the Nitro item data
[ "SetKeyComparator", "provides", "key", "comparator", "for", "the", "Nitro", "item", "data" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/nitro.go#L300-L305
test
t3rm1n4l/nitro
nitro.go
UseMemoryMgmt
func (cfg *Config) UseMemoryMgmt(malloc skiplist.MallocFn, free skiplist.FreeFn) { if runtime.GOARCH == "amd64" { cfg.useMemoryMgmt = true cfg.mallocFun = malloc cfg.freeFun = free } }
go
func (cfg *Config) UseMemoryMgmt(malloc skiplist.MallocFn, free skiplist.FreeFn) { if runtime.GOARCH == "amd64" { cfg.useMemoryMgmt = true cfg.mallocFun = malloc cfg.freeFun = free } }
[ "func", "(", "cfg", "*", "Config", ")", "UseMemoryMgmt", "(", "malloc", "skiplist", ".", "MallocFn", ",", "free", "skiplist", ".", "FreeFn", ")", "{", "if", "runtime", ".", "GOARCH", "==", "\"amd64\"", "{", "cfg", ".", "useMemoryMgmt", "=", "true", "\n", "cfg", ".", "mallocFun", "=", "malloc", "\n", "cfg", ".", "freeFun", "=", "free", "\n", "}", "\n", "}" ]
// UseMemoryMgmt provides custom memory allocator for Nitro items storage
[ "UseMemoryMgmt", "provides", "custom", "memory", "allocator", "for", "Nitro", "items", "storage" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/nitro.go#L308-L314
test
t3rm1n4l/nitro
nitro.go
NewWithConfig
func NewWithConfig(cfg Config) *Nitro { m := &Nitro{ snapshots: skiplist.New(), gcsnapshots: skiplist.New(), currSn: 1, Config: cfg, gcchan: make(chan *skiplist.Node, gcchanBufSize), id: int(atomic.AddInt64(&dbInstancesCount, 1)), } m.freechan = make(chan *skiplist.Node, gcchanBufSize) m.store = skiplist.NewWithConfig(m.newStoreConfig()) m.initSizeFuns() buf := dbInstances.MakeBuf() defer dbInstances.FreeBuf(buf) dbInstances.Insert(unsafe.Pointer(m), CompareNitro, buf, &dbInstances.Stats) return m }
go
func NewWithConfig(cfg Config) *Nitro { m := &Nitro{ snapshots: skiplist.New(), gcsnapshots: skiplist.New(), currSn: 1, Config: cfg, gcchan: make(chan *skiplist.Node, gcchanBufSize), id: int(atomic.AddInt64(&dbInstancesCount, 1)), } m.freechan = make(chan *skiplist.Node, gcchanBufSize) m.store = skiplist.NewWithConfig(m.newStoreConfig()) m.initSizeFuns() buf := dbInstances.MakeBuf() defer dbInstances.FreeBuf(buf) dbInstances.Insert(unsafe.Pointer(m), CompareNitro, buf, &dbInstances.Stats) return m }
[ "func", "NewWithConfig", "(", "cfg", "Config", ")", "*", "Nitro", "{", "m", ":=", "&", "Nitro", "{", "snapshots", ":", "skiplist", ".", "New", "(", ")", ",", "gcsnapshots", ":", "skiplist", ".", "New", "(", ")", ",", "currSn", ":", "1", ",", "Config", ":", "cfg", ",", "gcchan", ":", "make", "(", "chan", "*", "skiplist", ".", "Node", ",", "gcchanBufSize", ")", ",", "id", ":", "int", "(", "atomic", ".", "AddInt64", "(", "&", "dbInstancesCount", ",", "1", ")", ")", ",", "}", "\n", "m", ".", "freechan", "=", "make", "(", "chan", "*", "skiplist", ".", "Node", ",", "gcchanBufSize", ")", "\n", "m", ".", "store", "=", "skiplist", ".", "NewWithConfig", "(", "m", ".", "newStoreConfig", "(", ")", ")", "\n", "m", ".", "initSizeFuns", "(", ")", "\n", "buf", ":=", "dbInstances", ".", "MakeBuf", "(", ")", "\n", "defer", "dbInstances", ".", "FreeBuf", "(", "buf", ")", "\n", "dbInstances", ".", "Insert", "(", "unsafe", ".", "Pointer", "(", "m", ")", ",", "CompareNitro", ",", "buf", ",", "&", "dbInstances", ".", "Stats", ")", "\n", "return", "m", "\n", "}" ]
// NewWithConfig creates a new Nitro instance based on provided configuration.
[ "NewWithConfig", "creates", "a", "new", "Nitro", "instance", "based", "on", "provided", "configuration", "." ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/nitro.go#L354-L374
test
t3rm1n4l/nitro
nitro.go
MemoryInUse
func (m *Nitro) MemoryInUse() int64 { storeStats := m.aggrStoreStats() return storeStats.Memory + m.snapshots.MemoryInUse() + m.gcsnapshots.MemoryInUse() }
go
func (m *Nitro) MemoryInUse() int64 { storeStats := m.aggrStoreStats() return storeStats.Memory + m.snapshots.MemoryInUse() + m.gcsnapshots.MemoryInUse() }
[ "func", "(", "m", "*", "Nitro", ")", "MemoryInUse", "(", ")", "int64", "{", "storeStats", ":=", "m", ".", "aggrStoreStats", "(", ")", "\n", "return", "storeStats", ".", "Memory", "+", "m", ".", "snapshots", ".", "MemoryInUse", "(", ")", "+", "m", ".", "gcsnapshots", ".", "MemoryInUse", "(", ")", "\n", "}" ]
// MemoryInUse returns total memory used by the Nitro instance.
[ "MemoryInUse", "returns", "total", "memory", "used", "by", "the", "Nitro", "instance", "." ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/nitro.go#L410-L413
test
t3rm1n4l/nitro
nitro.go
Close
func (m *Nitro) Close() { // Wait until all snapshot iterators have finished for s := m.snapshots.GetStats(); int(s.NodeCount) != 0; s = m.snapshots.GetStats() { time.Sleep(time.Millisecond) } m.hasShutdown = true // Acquire gc chan ownership // This will make sure that no other goroutine will write to gcchan for !atomic.CompareAndSwapInt32(&m.isGCRunning, 0, 1) { time.Sleep(time.Millisecond) } close(m.gcchan) buf := dbInstances.MakeBuf() defer dbInstances.FreeBuf(buf) dbInstances.Delete(unsafe.Pointer(m), CompareNitro, buf, &dbInstances.Stats) if m.useMemoryMgmt { buf := m.snapshots.MakeBuf() defer m.snapshots.FreeBuf(buf) m.shutdownWg1.Wait() close(m.freechan) m.shutdownWg2.Wait() // Manually free up all nodes iter := m.store.NewIterator(m.iterCmp, buf) defer iter.Close() var lastNode *skiplist.Node iter.SeekFirst() if iter.Valid() { lastNode = iter.GetNode() iter.Next() } for lastNode != nil { m.freeItem((*Item)(lastNode.Item())) m.store.FreeNode(lastNode, &m.store.Stats) lastNode = nil if iter.Valid() { lastNode = iter.GetNode() iter.Next() } } } }
go
func (m *Nitro) Close() { // Wait until all snapshot iterators have finished for s := m.snapshots.GetStats(); int(s.NodeCount) != 0; s = m.snapshots.GetStats() { time.Sleep(time.Millisecond) } m.hasShutdown = true // Acquire gc chan ownership // This will make sure that no other goroutine will write to gcchan for !atomic.CompareAndSwapInt32(&m.isGCRunning, 0, 1) { time.Sleep(time.Millisecond) } close(m.gcchan) buf := dbInstances.MakeBuf() defer dbInstances.FreeBuf(buf) dbInstances.Delete(unsafe.Pointer(m), CompareNitro, buf, &dbInstances.Stats) if m.useMemoryMgmt { buf := m.snapshots.MakeBuf() defer m.snapshots.FreeBuf(buf) m.shutdownWg1.Wait() close(m.freechan) m.shutdownWg2.Wait() // Manually free up all nodes iter := m.store.NewIterator(m.iterCmp, buf) defer iter.Close() var lastNode *skiplist.Node iter.SeekFirst() if iter.Valid() { lastNode = iter.GetNode() iter.Next() } for lastNode != nil { m.freeItem((*Item)(lastNode.Item())) m.store.FreeNode(lastNode, &m.store.Stats) lastNode = nil if iter.Valid() { lastNode = iter.GetNode() iter.Next() } } } }
[ "func", "(", "m", "*", "Nitro", ")", "Close", "(", ")", "{", "for", "s", ":=", "m", ".", "snapshots", ".", "GetStats", "(", ")", ";", "int", "(", "s", ".", "NodeCount", ")", "!=", "0", ";", "s", "=", "m", ".", "snapshots", ".", "GetStats", "(", ")", "{", "time", ".", "Sleep", "(", "time", ".", "Millisecond", ")", "\n", "}", "\n", "m", ".", "hasShutdown", "=", "true", "\n", "for", "!", "atomic", ".", "CompareAndSwapInt32", "(", "&", "m", ".", "isGCRunning", ",", "0", ",", "1", ")", "{", "time", ".", "Sleep", "(", "time", ".", "Millisecond", ")", "\n", "}", "\n", "close", "(", "m", ".", "gcchan", ")", "\n", "buf", ":=", "dbInstances", ".", "MakeBuf", "(", ")", "\n", "defer", "dbInstances", ".", "FreeBuf", "(", "buf", ")", "\n", "dbInstances", ".", "Delete", "(", "unsafe", ".", "Pointer", "(", "m", ")", ",", "CompareNitro", ",", "buf", ",", "&", "dbInstances", ".", "Stats", ")", "\n", "if", "m", ".", "useMemoryMgmt", "{", "buf", ":=", "m", ".", "snapshots", ".", "MakeBuf", "(", ")", "\n", "defer", "m", ".", "snapshots", ".", "FreeBuf", "(", "buf", ")", "\n", "m", ".", "shutdownWg1", ".", "Wait", "(", ")", "\n", "close", "(", "m", ".", "freechan", ")", "\n", "m", ".", "shutdownWg2", ".", "Wait", "(", ")", "\n", "iter", ":=", "m", ".", "store", ".", "NewIterator", "(", "m", ".", "iterCmp", ",", "buf", ")", "\n", "defer", "iter", ".", "Close", "(", ")", "\n", "var", "lastNode", "*", "skiplist", ".", "Node", "\n", "iter", ".", "SeekFirst", "(", ")", "\n", "if", "iter", ".", "Valid", "(", ")", "{", "lastNode", "=", "iter", ".", "GetNode", "(", ")", "\n", "iter", ".", "Next", "(", ")", "\n", "}", "\n", "for", "lastNode", "!=", "nil", "{", "m", ".", "freeItem", "(", "(", "*", "Item", ")", "(", "lastNode", ".", "Item", "(", ")", ")", ")", "\n", "m", ".", "store", ".", "FreeNode", "(", "lastNode", ",", "&", "m", ".", "store", ".", "Stats", ")", "\n", "lastNode", "=", "nil", "\n", "if", "iter", ".", "Valid", "(", ")", "{", "lastNode", "=", "iter", ".", "GetNode", "(", ")", "\n", "iter", ".", "Next", "(", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}" ]
// Close shuts down the nitro instance
[ "Close", "shuts", "down", "the", "nitro", "instance" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/nitro.go#L416-L465
test
t3rm1n4l/nitro
nitro.go
NewWriter
func (m *Nitro) NewWriter() *Writer { w := m.newWriter() w.next = m.wlist m.wlist = w w.dwrCtx.Init() m.shutdownWg1.Add(1) go m.collectionWorker(w) if m.useMemoryMgmt { m.shutdownWg2.Add(1) go m.freeWorker(w) } return w }
go
func (m *Nitro) NewWriter() *Writer { w := m.newWriter() w.next = m.wlist m.wlist = w w.dwrCtx.Init() m.shutdownWg1.Add(1) go m.collectionWorker(w) if m.useMemoryMgmt { m.shutdownWg2.Add(1) go m.freeWorker(w) } return w }
[ "func", "(", "m", "*", "Nitro", ")", "NewWriter", "(", ")", "*", "Writer", "{", "w", ":=", "m", ".", "newWriter", "(", ")", "\n", "w", ".", "next", "=", "m", ".", "wlist", "\n", "m", ".", "wlist", "=", "w", "\n", "w", ".", "dwrCtx", ".", "Init", "(", ")", "\n", "m", ".", "shutdownWg1", ".", "Add", "(", "1", ")", "\n", "go", "m", ".", "collectionWorker", "(", "w", ")", "\n", "if", "m", ".", "useMemoryMgmt", "{", "m", ".", "shutdownWg2", ".", "Add", "(", "1", ")", "\n", "go", "m", ".", "freeWorker", "(", "w", ")", "\n", "}", "\n", "return", "w", "\n", "}" ]
// NewWriter creates a Nitro writer
[ "NewWriter", "creates", "a", "Nitro", "writer" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/nitro.go#L485-L499
test
t3rm1n4l/nitro
nitro.go
SnapshotSize
func SnapshotSize(p unsafe.Pointer) int { s := (*Snapshot)(p) return int(unsafe.Sizeof(s.sn) + unsafe.Sizeof(s.refCount) + unsafe.Sizeof(s.db) + unsafe.Sizeof(s.count) + unsafe.Sizeof(s.gclist)) }
go
func SnapshotSize(p unsafe.Pointer) int { s := (*Snapshot)(p) return int(unsafe.Sizeof(s.sn) + unsafe.Sizeof(s.refCount) + unsafe.Sizeof(s.db) + unsafe.Sizeof(s.count) + unsafe.Sizeof(s.gclist)) }
[ "func", "SnapshotSize", "(", "p", "unsafe", ".", "Pointer", ")", "int", "{", "s", ":=", "(", "*", "Snapshot", ")", "(", "p", ")", "\n", "return", "int", "(", "unsafe", ".", "Sizeof", "(", "s", ".", "sn", ")", "+", "unsafe", ".", "Sizeof", "(", "s", ".", "refCount", ")", "+", "unsafe", ".", "Sizeof", "(", "s", ".", "db", ")", "+", "unsafe", ".", "Sizeof", "(", "s", ".", "count", ")", "+", "unsafe", ".", "Sizeof", "(", "s", ".", "gclist", ")", ")", "\n", "}" ]
// SnapshotSize returns the memory used by Nitro snapshot metadata
[ "SnapshotSize", "returns", "the", "memory", "used", "by", "Nitro", "snapshot", "metadata" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/nitro.go#L512-L516
test
t3rm1n4l/nitro
nitro.go
Encode
func (s *Snapshot) Encode(buf []byte, w io.Writer) error { l := 4 if len(buf) < l { return errNotEnoughSpace } binary.BigEndian.PutUint32(buf[0:4], s.sn) if _, err := w.Write(buf[0:4]); err != nil { return err } return nil }
go
func (s *Snapshot) Encode(buf []byte, w io.Writer) error { l := 4 if len(buf) < l { return errNotEnoughSpace } binary.BigEndian.PutUint32(buf[0:4], s.sn) if _, err := w.Write(buf[0:4]); err != nil { return err } return nil }
[ "func", "(", "s", "*", "Snapshot", ")", "Encode", "(", "buf", "[", "]", "byte", ",", "w", "io", ".", "Writer", ")", "error", "{", "l", ":=", "4", "\n", "if", "len", "(", "buf", ")", "<", "l", "{", "return", "errNotEnoughSpace", "\n", "}", "\n", "binary", ".", "BigEndian", ".", "PutUint32", "(", "buf", "[", "0", ":", "4", "]", ",", "s", ".", "sn", ")", "\n", "if", "_", ",", "err", ":=", "w", ".", "Write", "(", "buf", "[", "0", ":", "4", "]", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Encode implements Binary encoder for snapshot metadata
[ "Encode", "implements", "Binary", "encoder", "for", "snapshot", "metadata" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/nitro.go#L524-L537
test
t3rm1n4l/nitro
nitro.go
Decode
func (s *Snapshot) Decode(buf []byte, r io.Reader) error { if _, err := io.ReadFull(r, buf[0:4]); err != nil { return err } s.sn = binary.BigEndian.Uint32(buf[0:4]) return nil }
go
func (s *Snapshot) Decode(buf []byte, r io.Reader) error { if _, err := io.ReadFull(r, buf[0:4]); err != nil { return err } s.sn = binary.BigEndian.Uint32(buf[0:4]) return nil }
[ "func", "(", "s", "*", "Snapshot", ")", "Decode", "(", "buf", "[", "]", "byte", ",", "r", "io", ".", "Reader", ")", "error", "{", "if", "_", ",", "err", ":=", "io", ".", "ReadFull", "(", "r", ",", "buf", "[", "0", ":", "4", "]", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "s", ".", "sn", "=", "binary", ".", "BigEndian", ".", "Uint32", "(", "buf", "[", "0", ":", "4", "]", ")", "\n", "return", "nil", "\n", "}" ]
// Decode implements binary decoder for snapshot metadata
[ "Decode", "implements", "binary", "decoder", "for", "snapshot", "metadata" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/nitro.go#L540-L546
test
t3rm1n4l/nitro
nitro.go
Open
func (s *Snapshot) Open() bool { if atomic.LoadInt32(&s.refCount) == 0 { return false } atomic.AddInt32(&s.refCount, 1) return true }
go
func (s *Snapshot) Open() bool { if atomic.LoadInt32(&s.refCount) == 0 { return false } atomic.AddInt32(&s.refCount, 1) return true }
[ "func", "(", "s", "*", "Snapshot", ")", "Open", "(", ")", "bool", "{", "if", "atomic", ".", "LoadInt32", "(", "&", "s", ".", "refCount", ")", "==", "0", "{", "return", "false", "\n", "}", "\n", "atomic", ".", "AddInt32", "(", "&", "s", ".", "refCount", ",", "1", ")", "\n", "return", "true", "\n", "}" ]
// Open implements reference couting and garbage collection for snapshots // When snapshots are shared by multiple threads, each thread should Open the // snapshot. This API internally tracks the reference count for the snapshot.
[ "Open", "implements", "reference", "couting", "and", "garbage", "collection", "for", "snapshots", "When", "snapshots", "are", "shared", "by", "multiple", "threads", "each", "thread", "should", "Open", "the", "snapshot", ".", "This", "API", "internally", "tracks", "the", "reference", "count", "for", "the", "snapshot", "." ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/nitro.go#L551-L557
test
t3rm1n4l/nitro
nitro.go
CompareSnapshot
func CompareSnapshot(this, that unsafe.Pointer) int { thisItem := (*Snapshot)(this) thatItem := (*Snapshot)(that) return int(thisItem.sn) - int(thatItem.sn) }
go
func CompareSnapshot(this, that unsafe.Pointer) int { thisItem := (*Snapshot)(this) thatItem := (*Snapshot)(that) return int(thisItem.sn) - int(thatItem.sn) }
[ "func", "CompareSnapshot", "(", "this", ",", "that", "unsafe", ".", "Pointer", ")", "int", "{", "thisItem", ":=", "(", "*", "Snapshot", ")", "(", "this", ")", "\n", "thatItem", ":=", "(", "*", "Snapshot", ")", "(", "that", ")", "\n", "return", "int", "(", "thisItem", ".", "sn", ")", "-", "int", "(", "thatItem", ".", "sn", ")", "\n", "}" ]
// CompareSnapshot implements comparator for snapshots based on snapshot number
[ "CompareSnapshot", "implements", "comparator", "for", "snapshots", "based", "on", "snapshot", "number" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/nitro.go#L581-L586
test
t3rm1n4l/nitro
nitro.go
GC
func (m *Nitro) GC() { if atomic.CompareAndSwapInt32(&m.isGCRunning, 0, 1) { m.collectDead() atomic.CompareAndSwapInt32(&m.isGCRunning, 1, 0) } }
go
func (m *Nitro) GC() { if atomic.CompareAndSwapInt32(&m.isGCRunning, 0, 1) { m.collectDead() atomic.CompareAndSwapInt32(&m.isGCRunning, 1, 0) } }
[ "func", "(", "m", "*", "Nitro", ")", "GC", "(", ")", "{", "if", "atomic", ".", "CompareAndSwapInt32", "(", "&", "m", ".", "isGCRunning", ",", "0", ",", "1", ")", "{", "m", ".", "collectDead", "(", ")", "\n", "atomic", ".", "CompareAndSwapInt32", "(", "&", "m", ".", "isGCRunning", ",", "1", ",", "0", ")", "\n", "}", "\n", "}" ]
// GC implements manual garbage collection of Nitro snapshots.
[ "GC", "implements", "manual", "garbage", "collection", "of", "Nitro", "snapshots", "." ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/nitro.go#L702-L707
test
t3rm1n4l/nitro
nitro.go
GetSnapshots
func (m *Nitro) GetSnapshots() []*Snapshot { var snaps []*Snapshot buf := m.snapshots.MakeBuf() defer m.snapshots.FreeBuf(buf) iter := m.snapshots.NewIterator(CompareSnapshot, buf) iter.SeekFirst() for ; iter.Valid(); iter.Next() { snaps = append(snaps, (*Snapshot)(iter.Get())) } return snaps }
go
func (m *Nitro) GetSnapshots() []*Snapshot { var snaps []*Snapshot buf := m.snapshots.MakeBuf() defer m.snapshots.FreeBuf(buf) iter := m.snapshots.NewIterator(CompareSnapshot, buf) iter.SeekFirst() for ; iter.Valid(); iter.Next() { snaps = append(snaps, (*Snapshot)(iter.Get())) } return snaps }
[ "func", "(", "m", "*", "Nitro", ")", "GetSnapshots", "(", ")", "[", "]", "*", "Snapshot", "{", "var", "snaps", "[", "]", "*", "Snapshot", "\n", "buf", ":=", "m", ".", "snapshots", ".", "MakeBuf", "(", ")", "\n", "defer", "m", ".", "snapshots", ".", "FreeBuf", "(", "buf", ")", "\n", "iter", ":=", "m", ".", "snapshots", ".", "NewIterator", "(", "CompareSnapshot", ",", "buf", ")", "\n", "iter", ".", "SeekFirst", "(", ")", "\n", "for", ";", "iter", ".", "Valid", "(", ")", ";", "iter", ".", "Next", "(", ")", "{", "snaps", "=", "append", "(", "snaps", ",", "(", "*", "Snapshot", ")", "(", "iter", ".", "Get", "(", ")", ")", ")", "\n", "}", "\n", "return", "snaps", "\n", "}" ]
// GetSnapshots returns the list of current live snapshots // This API is mainly for debugging purpose
[ "GetSnapshots", "returns", "the", "list", "of", "current", "live", "snapshots", "This", "API", "is", "mainly", "for", "debugging", "purpose" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/nitro.go#L711-L722
test
t3rm1n4l/nitro
nitro.go
MemoryInUse
func MemoryInUse() (sz int64) { buf := dbInstances.MakeBuf() defer dbInstances.FreeBuf(buf) iter := dbInstances.NewIterator(CompareNitro, buf) for iter.SeekFirst(); iter.Valid(); iter.Next() { db := (*Nitro)(iter.Get()) sz += db.MemoryInUse() } return }
go
func MemoryInUse() (sz int64) { buf := dbInstances.MakeBuf() defer dbInstances.FreeBuf(buf) iter := dbInstances.NewIterator(CompareNitro, buf) for iter.SeekFirst(); iter.Valid(); iter.Next() { db := (*Nitro)(iter.Get()) sz += db.MemoryInUse() } return }
[ "func", "MemoryInUse", "(", ")", "(", "sz", "int64", ")", "{", "buf", ":=", "dbInstances", ".", "MakeBuf", "(", ")", "\n", "defer", "dbInstances", ".", "FreeBuf", "(", "buf", ")", "\n", "iter", ":=", "dbInstances", ".", "NewIterator", "(", "CompareNitro", ",", "buf", ")", "\n", "for", "iter", ".", "SeekFirst", "(", ")", ";", "iter", ".", "Valid", "(", ")", ";", "iter", ".", "Next", "(", ")", "{", "db", ":=", "(", "*", "Nitro", ")", "(", "iter", ".", "Get", "(", ")", ")", "\n", "sz", "+=", "db", ".", "MemoryInUse", "(", ")", "\n", "}", "\n", "return", "\n", "}" ]
// MemoryInUse returns total memory used by all Nitro instances in the current process
[ "MemoryInUse", "returns", "total", "memory", "used", "by", "all", "Nitro", "instances", "in", "the", "current", "process" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/nitro.go#L1184-L1194
test
t3rm1n4l/nitro
skiplist/access_barrier.go
CompareBS
func CompareBS(this, that unsafe.Pointer) int { thisItm := (*BarrierSession)(this) thatItm := (*BarrierSession)(that) return int(thisItm.seqno) - int(thatItm.seqno) }
go
func CompareBS(this, that unsafe.Pointer) int { thisItm := (*BarrierSession)(this) thatItm := (*BarrierSession)(that) return int(thisItm.seqno) - int(thatItm.seqno) }
[ "func", "CompareBS", "(", "this", ",", "that", "unsafe", ".", "Pointer", ")", "int", "{", "thisItm", ":=", "(", "*", "BarrierSession", ")", "(", "this", ")", "\n", "thatItm", ":=", "(", "*", "BarrierSession", ")", "(", "that", ")", "\n", "return", "int", "(", "thisItm", ".", "seqno", ")", "-", "int", "(", "thatItm", ".", "seqno", ")", "\n", "}" ]
// CompareBS is a barrier session comparator based on seqno
[ "CompareBS", "is", "a", "barrier", "session", "comparator", "based", "on", "seqno" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/skiplist/access_barrier.go#L77-L82
test
t3rm1n4l/nitro
skiplist/access_barrier.go
Acquire
func (ab *AccessBarrier) Acquire() *BarrierSession { if ab.active { retry: bs := (*BarrierSession)(atomic.LoadPointer(&ab.session)) liveCount := atomic.AddInt32(bs.liveCount, 1) if liveCount > barrierFlushOffset { ab.Release(bs) goto retry } return bs } return nil }
go
func (ab *AccessBarrier) Acquire() *BarrierSession { if ab.active { retry: bs := (*BarrierSession)(atomic.LoadPointer(&ab.session)) liveCount := atomic.AddInt32(bs.liveCount, 1) if liveCount > barrierFlushOffset { ab.Release(bs) goto retry } return bs } return nil }
[ "func", "(", "ab", "*", "AccessBarrier", ")", "Acquire", "(", ")", "*", "BarrierSession", "{", "if", "ab", ".", "active", "{", "retry", ":", "bs", ":=", "(", "*", "BarrierSession", ")", "(", "atomic", ".", "LoadPointer", "(", "&", "ab", ".", "session", ")", ")", "\n", "liveCount", ":=", "atomic", ".", "AddInt32", "(", "bs", ".", "liveCount", ",", "1", ")", "\n", "if", "liveCount", ">", "barrierFlushOffset", "{", "ab", ".", "Release", "(", "bs", ")", "\n", "goto", "retry", "\n", "}", "\n", "return", "bs", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Acquire marks enter of an accessor in the skiplist
[ "Acquire", "marks", "enter", "of", "an", "accessor", "in", "the", "skiplist" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/skiplist/access_barrier.go#L141-L155
test
t3rm1n4l/nitro
skiplist/access_barrier.go
Release
func (ab *AccessBarrier) Release(bs *BarrierSession) { if ab.active { liveCount := atomic.AddInt32(bs.liveCount, -1) if liveCount == barrierFlushOffset { buf := ab.freeq.MakeBuf() defer ab.freeq.FreeBuf(buf) // Accessors which entered a closed barrier session steps down automatically // But, they may try to close an already closed session. if atomic.AddInt32(&bs.closed, 1) == 1 { ab.freeq.Insert(unsafe.Pointer(bs), CompareBS, buf, &ab.freeq.Stats) if atomic.CompareAndSwapInt32(&ab.isDestructorRunning, 0, 1) { ab.doCleanup() atomic.CompareAndSwapInt32(&ab.isDestructorRunning, 1, 0) } } } } }
go
func (ab *AccessBarrier) Release(bs *BarrierSession) { if ab.active { liveCount := atomic.AddInt32(bs.liveCount, -1) if liveCount == barrierFlushOffset { buf := ab.freeq.MakeBuf() defer ab.freeq.FreeBuf(buf) // Accessors which entered a closed barrier session steps down automatically // But, they may try to close an already closed session. if atomic.AddInt32(&bs.closed, 1) == 1 { ab.freeq.Insert(unsafe.Pointer(bs), CompareBS, buf, &ab.freeq.Stats) if atomic.CompareAndSwapInt32(&ab.isDestructorRunning, 0, 1) { ab.doCleanup() atomic.CompareAndSwapInt32(&ab.isDestructorRunning, 1, 0) } } } } }
[ "func", "(", "ab", "*", "AccessBarrier", ")", "Release", "(", "bs", "*", "BarrierSession", ")", "{", "if", "ab", ".", "active", "{", "liveCount", ":=", "atomic", ".", "AddInt32", "(", "bs", ".", "liveCount", ",", "-", "1", ")", "\n", "if", "liveCount", "==", "barrierFlushOffset", "{", "buf", ":=", "ab", ".", "freeq", ".", "MakeBuf", "(", ")", "\n", "defer", "ab", ".", "freeq", ".", "FreeBuf", "(", "buf", ")", "\n", "if", "atomic", ".", "AddInt32", "(", "&", "bs", ".", "closed", ",", "1", ")", "==", "1", "{", "ab", ".", "freeq", ".", "Insert", "(", "unsafe", ".", "Pointer", "(", "bs", ")", ",", "CompareBS", ",", "buf", ",", "&", "ab", ".", "freeq", ".", "Stats", ")", "\n", "if", "atomic", ".", "CompareAndSwapInt32", "(", "&", "ab", ".", "isDestructorRunning", ",", "0", ",", "1", ")", "{", "ab", ".", "doCleanup", "(", ")", "\n", "atomic", ".", "CompareAndSwapInt32", "(", "&", "ab", ".", "isDestructorRunning", ",", "1", ",", "0", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "}" ]
// Release marks leaving of an accessor in the skiplist
[ "Release", "marks", "leaving", "of", "an", "accessor", "in", "the", "skiplist" ]
937fe99f63a01a8bea7661c49e2f3f8af6541d7c
https://github.com/t3rm1n4l/nitro/blob/937fe99f63a01a8bea7661c49e2f3f8af6541d7c/skiplist/access_barrier.go#L158-L176
test