id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
sequencelengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
sequencelengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
6,200 | ncw/swift | swift.go | authenticate | func (c *Connection) authenticate() (err error) {
c.setDefaults()
// Flush the keepalives connection - if we are
// re-authenticating then stuff has gone wrong
flushKeepaliveConnections(c.Transport)
if c.Auth == nil {
c.Auth, err = newAuth(c)
if err != nil {
return
}
}
retries := 1
again:
var req *http.Request
req, err = c.Auth.Request(c)
if err != nil {
return
}
if req != nil {
timer := time.NewTimer(c.ConnectTimeout)
defer timer.Stop()
var resp *http.Response
resp, err = c.doTimeoutRequest(timer, req)
if err != nil {
return
}
defer func() {
drainAndClose(resp.Body, &err)
// Flush the auth connection - we don't want to keep
// it open if keepalives were enabled
flushKeepaliveConnections(c.Transport)
}()
if err = c.parseHeaders(resp, authErrorMap); err != nil {
// Try again for a limited number of times on
// AuthorizationFailed or BadRequest. This allows us
// to try some alternate forms of the request
if (err == AuthorizationFailed || err == BadRequest) && retries > 0 {
retries--
goto again
}
return
}
err = c.Auth.Response(resp)
if err != nil {
return
}
}
if customAuth, isCustom := c.Auth.(CustomEndpointAuthenticator); isCustom && c.EndpointType != "" {
c.StorageUrl = customAuth.StorageUrlForEndpoint(c.EndpointType)
} else {
c.StorageUrl = c.Auth.StorageUrl(c.Internal)
}
c.AuthToken = c.Auth.Token()
if do, ok := c.Auth.(Expireser); ok {
c.Expires = do.Expires()
} else {
c.Expires = time.Time{}
}
if !c.authenticated() {
err = newError(0, "Response didn't have storage url and auth token")
return
}
return
} | go | func (c *Connection) authenticate() (err error) {
c.setDefaults()
// Flush the keepalives connection - if we are
// re-authenticating then stuff has gone wrong
flushKeepaliveConnections(c.Transport)
if c.Auth == nil {
c.Auth, err = newAuth(c)
if err != nil {
return
}
}
retries := 1
again:
var req *http.Request
req, err = c.Auth.Request(c)
if err != nil {
return
}
if req != nil {
timer := time.NewTimer(c.ConnectTimeout)
defer timer.Stop()
var resp *http.Response
resp, err = c.doTimeoutRequest(timer, req)
if err != nil {
return
}
defer func() {
drainAndClose(resp.Body, &err)
// Flush the auth connection - we don't want to keep
// it open if keepalives were enabled
flushKeepaliveConnections(c.Transport)
}()
if err = c.parseHeaders(resp, authErrorMap); err != nil {
// Try again for a limited number of times on
// AuthorizationFailed or BadRequest. This allows us
// to try some alternate forms of the request
if (err == AuthorizationFailed || err == BadRequest) && retries > 0 {
retries--
goto again
}
return
}
err = c.Auth.Response(resp)
if err != nil {
return
}
}
if customAuth, isCustom := c.Auth.(CustomEndpointAuthenticator); isCustom && c.EndpointType != "" {
c.StorageUrl = customAuth.StorageUrlForEndpoint(c.EndpointType)
} else {
c.StorageUrl = c.Auth.StorageUrl(c.Internal)
}
c.AuthToken = c.Auth.Token()
if do, ok := c.Auth.(Expireser); ok {
c.Expires = do.Expires()
} else {
c.Expires = time.Time{}
}
if !c.authenticated() {
err = newError(0, "Response didn't have storage url and auth token")
return
}
return
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"authenticate",
"(",
")",
"(",
"err",
"error",
")",
"{",
"c",
".",
"setDefaults",
"(",
")",
"\n\n",
"// Flush the keepalives connection - if we are",
"// re-authenticating then stuff has gone wrong",
"flushKeepaliveConnections",
"(",
"c",
".",
"Transport",
")",
"\n\n",
"if",
"c",
".",
"Auth",
"==",
"nil",
"{",
"c",
".",
"Auth",
",",
"err",
"=",
"newAuth",
"(",
"c",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n\n",
"retries",
":=",
"1",
"\n",
"again",
":",
"var",
"req",
"*",
"http",
".",
"Request",
"\n",
"req",
",",
"err",
"=",
"c",
".",
"Auth",
".",
"Request",
"(",
"c",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"if",
"req",
"!=",
"nil",
"{",
"timer",
":=",
"time",
".",
"NewTimer",
"(",
"c",
".",
"ConnectTimeout",
")",
"\n",
"defer",
"timer",
".",
"Stop",
"(",
")",
"\n",
"var",
"resp",
"*",
"http",
".",
"Response",
"\n",
"resp",
",",
"err",
"=",
"c",
".",
"doTimeoutRequest",
"(",
"timer",
",",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"defer",
"func",
"(",
")",
"{",
"drainAndClose",
"(",
"resp",
".",
"Body",
",",
"&",
"err",
")",
"\n",
"// Flush the auth connection - we don't want to keep",
"// it open if keepalives were enabled",
"flushKeepaliveConnections",
"(",
"c",
".",
"Transport",
")",
"\n",
"}",
"(",
")",
"\n",
"if",
"err",
"=",
"c",
".",
"parseHeaders",
"(",
"resp",
",",
"authErrorMap",
")",
";",
"err",
"!=",
"nil",
"{",
"// Try again for a limited number of times on",
"// AuthorizationFailed or BadRequest. This allows us",
"// to try some alternate forms of the request",
"if",
"(",
"err",
"==",
"AuthorizationFailed",
"||",
"err",
"==",
"BadRequest",
")",
"&&",
"retries",
">",
"0",
"{",
"retries",
"--",
"\n",
"goto",
"again",
"\n",
"}",
"\n",
"return",
"\n",
"}",
"\n",
"err",
"=",
"c",
".",
"Auth",
".",
"Response",
"(",
"resp",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"customAuth",
",",
"isCustom",
":=",
"c",
".",
"Auth",
".",
"(",
"CustomEndpointAuthenticator",
")",
";",
"isCustom",
"&&",
"c",
".",
"EndpointType",
"!=",
"\"",
"\"",
"{",
"c",
".",
"StorageUrl",
"=",
"customAuth",
".",
"StorageUrlForEndpoint",
"(",
"c",
".",
"EndpointType",
")",
"\n",
"}",
"else",
"{",
"c",
".",
"StorageUrl",
"=",
"c",
".",
"Auth",
".",
"StorageUrl",
"(",
"c",
".",
"Internal",
")",
"\n",
"}",
"\n",
"c",
".",
"AuthToken",
"=",
"c",
".",
"Auth",
".",
"Token",
"(",
")",
"\n",
"if",
"do",
",",
"ok",
":=",
"c",
".",
"Auth",
".",
"(",
"Expireser",
")",
";",
"ok",
"{",
"c",
".",
"Expires",
"=",
"do",
".",
"Expires",
"(",
")",
"\n",
"}",
"else",
"{",
"c",
".",
"Expires",
"=",
"time",
".",
"Time",
"{",
"}",
"\n",
"}",
"\n\n",
"if",
"!",
"c",
".",
"authenticated",
"(",
")",
"{",
"err",
"=",
"newError",
"(",
"0",
",",
"\"",
"\"",
")",
"\n",
"return",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // Internal implementation of Authenticate
//
// Call with authLock held | [
"Internal",
"implementation",
"of",
"Authenticate",
"Call",
"with",
"authLock",
"held"
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/swift.go#L469-L536 |
6,201 | ncw/swift | swift.go | getUrlAndAuthToken | func (c *Connection) getUrlAndAuthToken(targetUrlIn string, OnReAuth func() (string, error)) (targetUrlOut, authToken string, err error) {
c.authLock.Lock()
defer c.authLock.Unlock()
targetUrlOut = targetUrlIn
if !c.authenticated() {
err = c.authenticate()
if err != nil {
return
}
if OnReAuth != nil {
targetUrlOut, err = OnReAuth()
if err != nil {
return
}
}
}
authToken = c.AuthToken
return
} | go | func (c *Connection) getUrlAndAuthToken(targetUrlIn string, OnReAuth func() (string, error)) (targetUrlOut, authToken string, err error) {
c.authLock.Lock()
defer c.authLock.Unlock()
targetUrlOut = targetUrlIn
if !c.authenticated() {
err = c.authenticate()
if err != nil {
return
}
if OnReAuth != nil {
targetUrlOut, err = OnReAuth()
if err != nil {
return
}
}
}
authToken = c.AuthToken
return
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"getUrlAndAuthToken",
"(",
"targetUrlIn",
"string",
",",
"OnReAuth",
"func",
"(",
")",
"(",
"string",
",",
"error",
")",
")",
"(",
"targetUrlOut",
",",
"authToken",
"string",
",",
"err",
"error",
")",
"{",
"c",
".",
"authLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"authLock",
".",
"Unlock",
"(",
")",
"\n",
"targetUrlOut",
"=",
"targetUrlIn",
"\n",
"if",
"!",
"c",
".",
"authenticated",
"(",
")",
"{",
"err",
"=",
"c",
".",
"authenticate",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"if",
"OnReAuth",
"!=",
"nil",
"{",
"targetUrlOut",
",",
"err",
"=",
"OnReAuth",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"authToken",
"=",
"c",
".",
"AuthToken",
"\n",
"return",
"\n",
"}"
] | // Get an authToken and url
//
// The Url may be updated if it needed to authenticate using the OnReAuth function | [
"Get",
"an",
"authToken",
"and",
"url",
"The",
"Url",
"may",
"be",
"updated",
"if",
"it",
"needed",
"to",
"authenticate",
"using",
"the",
"OnReAuth",
"function"
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/swift.go#L541-L559 |
6,202 | ncw/swift | swift.go | flushKeepaliveConnections | func flushKeepaliveConnections(transport http.RoundTripper) {
if tr, ok := transport.(interface {
CloseIdleConnections()
}); ok {
tr.CloseIdleConnections()
}
} | go | func flushKeepaliveConnections(transport http.RoundTripper) {
if tr, ok := transport.(interface {
CloseIdleConnections()
}); ok {
tr.CloseIdleConnections()
}
} | [
"func",
"flushKeepaliveConnections",
"(",
"transport",
"http",
".",
"RoundTripper",
")",
"{",
"if",
"tr",
",",
"ok",
":=",
"transport",
".",
"(",
"interface",
"{",
"CloseIdleConnections",
"(",
")",
"\n",
"}",
")",
";",
"ok",
"{",
"tr",
".",
"CloseIdleConnections",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // flushKeepaliveConnections is called to flush pending requests after an error. | [
"flushKeepaliveConnections",
"is",
"called",
"to",
"flush",
"pending",
"requests",
"after",
"an",
"error",
"."
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/swift.go#L562-L568 |
6,203 | ncw/swift | swift.go | UnAuthenticate | func (c *Connection) UnAuthenticate() {
c.authLock.Lock()
c.StorageUrl = ""
c.AuthToken = ""
c.authLock.Unlock()
} | go | func (c *Connection) UnAuthenticate() {
c.authLock.Lock()
c.StorageUrl = ""
c.AuthToken = ""
c.authLock.Unlock()
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"UnAuthenticate",
"(",
")",
"{",
"c",
".",
"authLock",
".",
"Lock",
"(",
")",
"\n",
"c",
".",
"StorageUrl",
"=",
"\"",
"\"",
"\n",
"c",
".",
"AuthToken",
"=",
"\"",
"\"",
"\n",
"c",
".",
"authLock",
".",
"Unlock",
"(",
")",
"\n",
"}"
] | // UnAuthenticate removes the authentication from the Connection. | [
"UnAuthenticate",
"removes",
"the",
"authentication",
"from",
"the",
"Connection",
"."
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/swift.go#L571-L576 |
6,204 | ncw/swift | swift.go | Authenticated | func (c *Connection) Authenticated() bool {
c.authLock.Lock()
defer c.authLock.Unlock()
return c.authenticated()
} | go | func (c *Connection) Authenticated() bool {
c.authLock.Lock()
defer c.authLock.Unlock()
return c.authenticated()
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"Authenticated",
"(",
")",
"bool",
"{",
"c",
".",
"authLock",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"authLock",
".",
"Unlock",
"(",
")",
"\n",
"return",
"c",
".",
"authenticated",
"(",
")",
"\n",
"}"
] | // Authenticated returns a boolean to show if the current connection
// is authenticated.
//
// Doesn't actually check the credentials against the server. | [
"Authenticated",
"returns",
"a",
"boolean",
"to",
"show",
"if",
"the",
"current",
"connection",
"is",
"authenticated",
".",
"Doesn",
"t",
"actually",
"check",
"the",
"credentials",
"against",
"the",
"server",
"."
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/swift.go#L582-L586 |
6,205 | ncw/swift | swift.go | readLines | func readLines(resp *http.Response) (lines []string, err error) {
defer drainAndClose(resp.Body, &err)
reader := bufio.NewReader(resp.Body)
buffer := bytes.NewBuffer(make([]byte, 0, 128))
var part []byte
var prefix bool
for {
if part, prefix, err = reader.ReadLine(); err != nil {
break
}
buffer.Write(part)
if !prefix {
lines = append(lines, buffer.String())
buffer.Reset()
}
}
if err == io.EOF {
err = nil
}
return
} | go | func readLines(resp *http.Response) (lines []string, err error) {
defer drainAndClose(resp.Body, &err)
reader := bufio.NewReader(resp.Body)
buffer := bytes.NewBuffer(make([]byte, 0, 128))
var part []byte
var prefix bool
for {
if part, prefix, err = reader.ReadLine(); err != nil {
break
}
buffer.Write(part)
if !prefix {
lines = append(lines, buffer.String())
buffer.Reset()
}
}
if err == io.EOF {
err = nil
}
return
} | [
"func",
"readLines",
"(",
"resp",
"*",
"http",
".",
"Response",
")",
"(",
"lines",
"[",
"]",
"string",
",",
"err",
"error",
")",
"{",
"defer",
"drainAndClose",
"(",
"resp",
".",
"Body",
",",
"&",
"err",
")",
"\n",
"reader",
":=",
"bufio",
".",
"NewReader",
"(",
"resp",
".",
"Body",
")",
"\n",
"buffer",
":=",
"bytes",
".",
"NewBuffer",
"(",
"make",
"(",
"[",
"]",
"byte",
",",
"0",
",",
"128",
")",
")",
"\n",
"var",
"part",
"[",
"]",
"byte",
"\n",
"var",
"prefix",
"bool",
"\n",
"for",
"{",
"if",
"part",
",",
"prefix",
",",
"err",
"=",
"reader",
".",
"ReadLine",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"break",
"\n",
"}",
"\n",
"buffer",
".",
"Write",
"(",
"part",
")",
"\n",
"if",
"!",
"prefix",
"{",
"lines",
"=",
"append",
"(",
"lines",
",",
"buffer",
".",
"String",
"(",
")",
")",
"\n",
"buffer",
".",
"Reset",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"err",
"==",
"io",
".",
"EOF",
"{",
"err",
"=",
"nil",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // readLines reads the response into an array of strings.
//
// Closes the response when done | [
"readLines",
"reads",
"the",
"response",
"into",
"an",
"array",
"of",
"strings",
".",
"Closes",
"the",
"response",
"when",
"done"
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/swift.go#L819-L839 |
6,206 | ncw/swift | swift.go | readJson | func readJson(resp *http.Response, result interface{}) (err error) {
defer drainAndClose(resp.Body, &err)
decoder := json.NewDecoder(resp.Body)
return decoder.Decode(result)
} | go | func readJson(resp *http.Response, result interface{}) (err error) {
defer drainAndClose(resp.Body, &err)
decoder := json.NewDecoder(resp.Body)
return decoder.Decode(result)
} | [
"func",
"readJson",
"(",
"resp",
"*",
"http",
".",
"Response",
",",
"result",
"interface",
"{",
"}",
")",
"(",
"err",
"error",
")",
"{",
"defer",
"drainAndClose",
"(",
"resp",
".",
"Body",
",",
"&",
"err",
")",
"\n",
"decoder",
":=",
"json",
".",
"NewDecoder",
"(",
"resp",
".",
"Body",
")",
"\n",
"return",
"decoder",
".",
"Decode",
"(",
"result",
")",
"\n",
"}"
] | // readJson reads the response into the json type passed in
//
// Closes the response when done | [
"readJson",
"reads",
"the",
"response",
"into",
"the",
"json",
"type",
"passed",
"in",
"Closes",
"the",
"response",
"when",
"done"
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/swift.go#L844-L848 |
6,207 | ncw/swift | swift.go | parse | func (opts *ContainersOpts) parse() (url.Values, Headers) {
v := url.Values{}
var h Headers
if opts != nil {
if opts.Limit > 0 {
v.Set("limit", strconv.Itoa(opts.Limit))
}
if opts.Prefix != "" {
v.Set("prefix", opts.Prefix)
}
if opts.Marker != "" {
v.Set("marker", opts.Marker)
}
if opts.EndMarker != "" {
v.Set("end_marker", opts.EndMarker)
}
h = opts.Headers
}
return v, h
} | go | func (opts *ContainersOpts) parse() (url.Values, Headers) {
v := url.Values{}
var h Headers
if opts != nil {
if opts.Limit > 0 {
v.Set("limit", strconv.Itoa(opts.Limit))
}
if opts.Prefix != "" {
v.Set("prefix", opts.Prefix)
}
if opts.Marker != "" {
v.Set("marker", opts.Marker)
}
if opts.EndMarker != "" {
v.Set("end_marker", opts.EndMarker)
}
h = opts.Headers
}
return v, h
} | [
"func",
"(",
"opts",
"*",
"ContainersOpts",
")",
"parse",
"(",
")",
"(",
"url",
".",
"Values",
",",
"Headers",
")",
"{",
"v",
":=",
"url",
".",
"Values",
"{",
"}",
"\n",
"var",
"h",
"Headers",
"\n",
"if",
"opts",
"!=",
"nil",
"{",
"if",
"opts",
".",
"Limit",
">",
"0",
"{",
"v",
".",
"Set",
"(",
"\"",
"\"",
",",
"strconv",
".",
"Itoa",
"(",
"opts",
".",
"Limit",
")",
")",
"\n",
"}",
"\n",
"if",
"opts",
".",
"Prefix",
"!=",
"\"",
"\"",
"{",
"v",
".",
"Set",
"(",
"\"",
"\"",
",",
"opts",
".",
"Prefix",
")",
"\n",
"}",
"\n",
"if",
"opts",
".",
"Marker",
"!=",
"\"",
"\"",
"{",
"v",
".",
"Set",
"(",
"\"",
"\"",
",",
"opts",
".",
"Marker",
")",
"\n",
"}",
"\n",
"if",
"opts",
".",
"EndMarker",
"!=",
"\"",
"\"",
"{",
"v",
".",
"Set",
"(",
"\"",
"\"",
",",
"opts",
".",
"EndMarker",
")",
"\n",
"}",
"\n",
"h",
"=",
"opts",
".",
"Headers",
"\n",
"}",
"\n",
"return",
"v",
",",
"h",
"\n",
"}"
] | // parse the ContainerOpts | [
"parse",
"the",
"ContainerOpts"
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/swift.go#L862-L881 |
6,208 | ncw/swift | swift.go | ContainerNames | func (c *Connection) ContainerNames(opts *ContainersOpts) ([]string, error) {
v, h := opts.parse()
resp, _, err := c.storage(RequestOpts{
Operation: "GET",
Parameters: v,
ErrorMap: ContainerErrorMap,
Headers: h,
})
if err != nil {
return nil, err
}
lines, err := readLines(resp)
return lines, err
} | go | func (c *Connection) ContainerNames(opts *ContainersOpts) ([]string, error) {
v, h := opts.parse()
resp, _, err := c.storage(RequestOpts{
Operation: "GET",
Parameters: v,
ErrorMap: ContainerErrorMap,
Headers: h,
})
if err != nil {
return nil, err
}
lines, err := readLines(resp)
return lines, err
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"ContainerNames",
"(",
"opts",
"*",
"ContainersOpts",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"v",
",",
"h",
":=",
"opts",
".",
"parse",
"(",
")",
"\n",
"resp",
",",
"_",
",",
"err",
":=",
"c",
".",
"storage",
"(",
"RequestOpts",
"{",
"Operation",
":",
"\"",
"\"",
",",
"Parameters",
":",
"v",
",",
"ErrorMap",
":",
"ContainerErrorMap",
",",
"Headers",
":",
"h",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"lines",
",",
"err",
":=",
"readLines",
"(",
"resp",
")",
"\n",
"return",
"lines",
",",
"err",
"\n",
"}"
] | // ContainerNames returns a slice of names of containers in this account. | [
"ContainerNames",
"returns",
"a",
"slice",
"of",
"names",
"of",
"containers",
"in",
"this",
"account",
"."
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/swift.go#L884-L897 |
6,209 | ncw/swift | swift.go | Containers | func (c *Connection) Containers(opts *ContainersOpts) ([]Container, error) {
v, h := opts.parse()
v.Set("format", "json")
resp, _, err := c.storage(RequestOpts{
Operation: "GET",
Parameters: v,
ErrorMap: ContainerErrorMap,
Headers: h,
})
if err != nil {
return nil, err
}
var containers []Container
err = readJson(resp, &containers)
return containers, err
} | go | func (c *Connection) Containers(opts *ContainersOpts) ([]Container, error) {
v, h := opts.parse()
v.Set("format", "json")
resp, _, err := c.storage(RequestOpts{
Operation: "GET",
Parameters: v,
ErrorMap: ContainerErrorMap,
Headers: h,
})
if err != nil {
return nil, err
}
var containers []Container
err = readJson(resp, &containers)
return containers, err
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"Containers",
"(",
"opts",
"*",
"ContainersOpts",
")",
"(",
"[",
"]",
"Container",
",",
"error",
")",
"{",
"v",
",",
"h",
":=",
"opts",
".",
"parse",
"(",
")",
"\n",
"v",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"resp",
",",
"_",
",",
"err",
":=",
"c",
".",
"storage",
"(",
"RequestOpts",
"{",
"Operation",
":",
"\"",
"\"",
",",
"Parameters",
":",
"v",
",",
"ErrorMap",
":",
"ContainerErrorMap",
",",
"Headers",
":",
"h",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"var",
"containers",
"[",
"]",
"Container",
"\n",
"err",
"=",
"readJson",
"(",
"resp",
",",
"&",
"containers",
")",
"\n",
"return",
"containers",
",",
"err",
"\n",
"}"
] | // Containers returns a slice of structures with full information as
// described in Container. | [
"Containers",
"returns",
"a",
"slice",
"of",
"structures",
"with",
"full",
"information",
"as",
"described",
"in",
"Container",
"."
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/swift.go#L908-L923 |
6,210 | ncw/swift | swift.go | containersAllOpts | func containersAllOpts(opts *ContainersOpts) *ContainersOpts {
var newOpts ContainersOpts
if opts != nil {
newOpts = *opts
}
if newOpts.Limit == 0 {
newOpts.Limit = allContainersLimit
}
newOpts.Marker = ""
return &newOpts
} | go | func containersAllOpts(opts *ContainersOpts) *ContainersOpts {
var newOpts ContainersOpts
if opts != nil {
newOpts = *opts
}
if newOpts.Limit == 0 {
newOpts.Limit = allContainersLimit
}
newOpts.Marker = ""
return &newOpts
} | [
"func",
"containersAllOpts",
"(",
"opts",
"*",
"ContainersOpts",
")",
"*",
"ContainersOpts",
"{",
"var",
"newOpts",
"ContainersOpts",
"\n",
"if",
"opts",
"!=",
"nil",
"{",
"newOpts",
"=",
"*",
"opts",
"\n",
"}",
"\n",
"if",
"newOpts",
".",
"Limit",
"==",
"0",
"{",
"newOpts",
".",
"Limit",
"=",
"allContainersLimit",
"\n",
"}",
"\n",
"newOpts",
".",
"Marker",
"=",
"\"",
"\"",
"\n",
"return",
"&",
"newOpts",
"\n",
"}"
] | // containersAllOpts makes a copy of opts if set or makes a new one and
// overrides Limit and Marker | [
"containersAllOpts",
"makes",
"a",
"copy",
"of",
"opts",
"if",
"set",
"or",
"makes",
"a",
"new",
"one",
"and",
"overrides",
"Limit",
"and",
"Marker"
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/swift.go#L927-L937 |
6,211 | ncw/swift | swift.go | ContainersAll | func (c *Connection) ContainersAll(opts *ContainersOpts) ([]Container, error) {
opts = containersAllOpts(opts)
containers := make([]Container, 0)
for {
newContainers, err := c.Containers(opts)
if err != nil {
return nil, err
}
containers = append(containers, newContainers...)
if len(newContainers) < opts.Limit {
break
}
opts.Marker = newContainers[len(newContainers)-1].Name
}
return containers, nil
} | go | func (c *Connection) ContainersAll(opts *ContainersOpts) ([]Container, error) {
opts = containersAllOpts(opts)
containers := make([]Container, 0)
for {
newContainers, err := c.Containers(opts)
if err != nil {
return nil, err
}
containers = append(containers, newContainers...)
if len(newContainers) < opts.Limit {
break
}
opts.Marker = newContainers[len(newContainers)-1].Name
}
return containers, nil
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"ContainersAll",
"(",
"opts",
"*",
"ContainersOpts",
")",
"(",
"[",
"]",
"Container",
",",
"error",
")",
"{",
"opts",
"=",
"containersAllOpts",
"(",
"opts",
")",
"\n",
"containers",
":=",
"make",
"(",
"[",
"]",
"Container",
",",
"0",
")",
"\n",
"for",
"{",
"newContainers",
",",
"err",
":=",
"c",
".",
"Containers",
"(",
"opts",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"containers",
"=",
"append",
"(",
"containers",
",",
"newContainers",
"...",
")",
"\n",
"if",
"len",
"(",
"newContainers",
")",
"<",
"opts",
".",
"Limit",
"{",
"break",
"\n",
"}",
"\n",
"opts",
".",
"Marker",
"=",
"newContainers",
"[",
"len",
"(",
"newContainers",
")",
"-",
"1",
"]",
".",
"Name",
"\n",
"}",
"\n",
"return",
"containers",
",",
"nil",
"\n",
"}"
] | // ContainersAll is like Containers but it returns all the Containers
//
// It calls Containers multiple times using the Marker parameter
//
// It has a default Limit parameter but you may pass in your own | [
"ContainersAll",
"is",
"like",
"Containers",
"but",
"it",
"returns",
"all",
"the",
"Containers",
"It",
"calls",
"Containers",
"multiple",
"times",
"using",
"the",
"Marker",
"parameter",
"It",
"has",
"a",
"default",
"Limit",
"parameter",
"but",
"you",
"may",
"pass",
"in",
"your",
"own"
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/swift.go#L944-L959 |
6,212 | ncw/swift | swift.go | ContainerNamesAll | func (c *Connection) ContainerNamesAll(opts *ContainersOpts) ([]string, error) {
opts = containersAllOpts(opts)
containers := make([]string, 0)
for {
newContainers, err := c.ContainerNames(opts)
if err != nil {
return nil, err
}
containers = append(containers, newContainers...)
if len(newContainers) < opts.Limit {
break
}
opts.Marker = newContainers[len(newContainers)-1]
}
return containers, nil
} | go | func (c *Connection) ContainerNamesAll(opts *ContainersOpts) ([]string, error) {
opts = containersAllOpts(opts)
containers := make([]string, 0)
for {
newContainers, err := c.ContainerNames(opts)
if err != nil {
return nil, err
}
containers = append(containers, newContainers...)
if len(newContainers) < opts.Limit {
break
}
opts.Marker = newContainers[len(newContainers)-1]
}
return containers, nil
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"ContainerNamesAll",
"(",
"opts",
"*",
"ContainersOpts",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"opts",
"=",
"containersAllOpts",
"(",
"opts",
")",
"\n",
"containers",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
")",
"\n",
"for",
"{",
"newContainers",
",",
"err",
":=",
"c",
".",
"ContainerNames",
"(",
"opts",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"containers",
"=",
"append",
"(",
"containers",
",",
"newContainers",
"...",
")",
"\n",
"if",
"len",
"(",
"newContainers",
")",
"<",
"opts",
".",
"Limit",
"{",
"break",
"\n",
"}",
"\n",
"opts",
".",
"Marker",
"=",
"newContainers",
"[",
"len",
"(",
"newContainers",
")",
"-",
"1",
"]",
"\n",
"}",
"\n",
"return",
"containers",
",",
"nil",
"\n",
"}"
] | // ContainerNamesAll is like ContainerNamess but it returns all the Containers
//
// It calls ContainerNames multiple times using the Marker parameter
//
// It has a default Limit parameter but you may pass in your own | [
"ContainerNamesAll",
"is",
"like",
"ContainerNamess",
"but",
"it",
"returns",
"all",
"the",
"Containers",
"It",
"calls",
"ContainerNames",
"multiple",
"times",
"using",
"the",
"Marker",
"parameter",
"It",
"has",
"a",
"default",
"Limit",
"parameter",
"but",
"you",
"may",
"pass",
"in",
"your",
"own"
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/swift.go#L966-L981 |
6,213 | ncw/swift | swift.go | parse | func (opts *ObjectsOpts) parse() (url.Values, Headers) {
v := url.Values{}
var h Headers
if opts != nil {
if opts.Limit > 0 {
v.Set("limit", strconv.Itoa(opts.Limit))
}
if opts.Marker != "" {
v.Set("marker", opts.Marker)
}
if opts.EndMarker != "" {
v.Set("end_marker", opts.EndMarker)
}
if opts.Prefix != "" {
v.Set("prefix", opts.Prefix)
}
if opts.Path != "" {
v.Set("path", opts.Path)
}
if opts.Delimiter != 0 {
v.Set("delimiter", string(opts.Delimiter))
}
h = opts.Headers
}
return v, h
} | go | func (opts *ObjectsOpts) parse() (url.Values, Headers) {
v := url.Values{}
var h Headers
if opts != nil {
if opts.Limit > 0 {
v.Set("limit", strconv.Itoa(opts.Limit))
}
if opts.Marker != "" {
v.Set("marker", opts.Marker)
}
if opts.EndMarker != "" {
v.Set("end_marker", opts.EndMarker)
}
if opts.Prefix != "" {
v.Set("prefix", opts.Prefix)
}
if opts.Path != "" {
v.Set("path", opts.Path)
}
if opts.Delimiter != 0 {
v.Set("delimiter", string(opts.Delimiter))
}
h = opts.Headers
}
return v, h
} | [
"func",
"(",
"opts",
"*",
"ObjectsOpts",
")",
"parse",
"(",
")",
"(",
"url",
".",
"Values",
",",
"Headers",
")",
"{",
"v",
":=",
"url",
".",
"Values",
"{",
"}",
"\n",
"var",
"h",
"Headers",
"\n",
"if",
"opts",
"!=",
"nil",
"{",
"if",
"opts",
".",
"Limit",
">",
"0",
"{",
"v",
".",
"Set",
"(",
"\"",
"\"",
",",
"strconv",
".",
"Itoa",
"(",
"opts",
".",
"Limit",
")",
")",
"\n",
"}",
"\n",
"if",
"opts",
".",
"Marker",
"!=",
"\"",
"\"",
"{",
"v",
".",
"Set",
"(",
"\"",
"\"",
",",
"opts",
".",
"Marker",
")",
"\n",
"}",
"\n",
"if",
"opts",
".",
"EndMarker",
"!=",
"\"",
"\"",
"{",
"v",
".",
"Set",
"(",
"\"",
"\"",
",",
"opts",
".",
"EndMarker",
")",
"\n",
"}",
"\n",
"if",
"opts",
".",
"Prefix",
"!=",
"\"",
"\"",
"{",
"v",
".",
"Set",
"(",
"\"",
"\"",
",",
"opts",
".",
"Prefix",
")",
"\n",
"}",
"\n",
"if",
"opts",
".",
"Path",
"!=",
"\"",
"\"",
"{",
"v",
".",
"Set",
"(",
"\"",
"\"",
",",
"opts",
".",
"Path",
")",
"\n",
"}",
"\n",
"if",
"opts",
".",
"Delimiter",
"!=",
"0",
"{",
"v",
".",
"Set",
"(",
"\"",
"\"",
",",
"string",
"(",
"opts",
".",
"Delimiter",
")",
")",
"\n",
"}",
"\n",
"h",
"=",
"opts",
".",
"Headers",
"\n",
"}",
"\n",
"return",
"v",
",",
"h",
"\n",
"}"
] | // parse reads values out of ObjectsOpts | [
"parse",
"reads",
"values",
"out",
"of",
"ObjectsOpts"
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/swift.go#L998-L1023 |
6,214 | ncw/swift | swift.go | ObjectNames | func (c *Connection) ObjectNames(container string, opts *ObjectsOpts) ([]string, error) {
v, h := opts.parse()
resp, _, err := c.storage(RequestOpts{
Container: container,
Operation: "GET",
Parameters: v,
ErrorMap: ContainerErrorMap,
Headers: h,
})
if err != nil {
return nil, err
}
return readLines(resp)
} | go | func (c *Connection) ObjectNames(container string, opts *ObjectsOpts) ([]string, error) {
v, h := opts.parse()
resp, _, err := c.storage(RequestOpts{
Container: container,
Operation: "GET",
Parameters: v,
ErrorMap: ContainerErrorMap,
Headers: h,
})
if err != nil {
return nil, err
}
return readLines(resp)
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"ObjectNames",
"(",
"container",
"string",
",",
"opts",
"*",
"ObjectsOpts",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"v",
",",
"h",
":=",
"opts",
".",
"parse",
"(",
")",
"\n",
"resp",
",",
"_",
",",
"err",
":=",
"c",
".",
"storage",
"(",
"RequestOpts",
"{",
"Container",
":",
"container",
",",
"Operation",
":",
"\"",
"\"",
",",
"Parameters",
":",
"v",
",",
"ErrorMap",
":",
"ContainerErrorMap",
",",
"Headers",
":",
"h",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"readLines",
"(",
"resp",
")",
"\n",
"}"
] | // ObjectNames returns a slice of names of objects in a given container. | [
"ObjectNames",
"returns",
"a",
"slice",
"of",
"names",
"of",
"objects",
"in",
"a",
"given",
"container",
"."
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/swift.go#L1026-L1039 |
6,215 | ncw/swift | swift.go | objectsAllOpts | func objectsAllOpts(opts *ObjectsOpts, Limit int) *ObjectsOpts {
var newOpts ObjectsOpts
if opts != nil {
newOpts = *opts
}
if newOpts.Limit == 0 {
newOpts.Limit = Limit
}
if !newOpts.KeepMarker {
newOpts.Marker = ""
}
return &newOpts
} | go | func objectsAllOpts(opts *ObjectsOpts, Limit int) *ObjectsOpts {
var newOpts ObjectsOpts
if opts != nil {
newOpts = *opts
}
if newOpts.Limit == 0 {
newOpts.Limit = Limit
}
if !newOpts.KeepMarker {
newOpts.Marker = ""
}
return &newOpts
} | [
"func",
"objectsAllOpts",
"(",
"opts",
"*",
"ObjectsOpts",
",",
"Limit",
"int",
")",
"*",
"ObjectsOpts",
"{",
"var",
"newOpts",
"ObjectsOpts",
"\n",
"if",
"opts",
"!=",
"nil",
"{",
"newOpts",
"=",
"*",
"opts",
"\n",
"}",
"\n",
"if",
"newOpts",
".",
"Limit",
"==",
"0",
"{",
"newOpts",
".",
"Limit",
"=",
"Limit",
"\n",
"}",
"\n",
"if",
"!",
"newOpts",
".",
"KeepMarker",
"{",
"newOpts",
".",
"Marker",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"&",
"newOpts",
"\n",
"}"
] | // objectsAllOpts makes a copy of opts if set or makes a new one and
// overrides Limit and Marker
// Marker is not overriden if KeepMarker is set | [
"objectsAllOpts",
"makes",
"a",
"copy",
"of",
"opts",
"if",
"set",
"or",
"makes",
"a",
"new",
"one",
"and",
"overrides",
"Limit",
"and",
"Marker",
"Marker",
"is",
"not",
"overriden",
"if",
"KeepMarker",
"is",
"set"
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/swift.go#L1111-L1123 |
6,216 | ncw/swift | swift.go | ObjectsAll | func (c *Connection) ObjectsAll(container string, opts *ObjectsOpts) ([]Object, error) {
objects := make([]Object, 0)
err := c.ObjectsWalk(container, opts, func(opts *ObjectsOpts) (interface{}, error) {
newObjects, err := c.Objects(container, opts)
if err == nil {
objects = append(objects, newObjects...)
}
return newObjects, err
})
return objects, err
} | go | func (c *Connection) ObjectsAll(container string, opts *ObjectsOpts) ([]Object, error) {
objects := make([]Object, 0)
err := c.ObjectsWalk(container, opts, func(opts *ObjectsOpts) (interface{}, error) {
newObjects, err := c.Objects(container, opts)
if err == nil {
objects = append(objects, newObjects...)
}
return newObjects, err
})
return objects, err
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"ObjectsAll",
"(",
"container",
"string",
",",
"opts",
"*",
"ObjectsOpts",
")",
"(",
"[",
"]",
"Object",
",",
"error",
")",
"{",
"objects",
":=",
"make",
"(",
"[",
"]",
"Object",
",",
"0",
")",
"\n",
"err",
":=",
"c",
".",
"ObjectsWalk",
"(",
"container",
",",
"opts",
",",
"func",
"(",
"opts",
"*",
"ObjectsOpts",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"newObjects",
",",
"err",
":=",
"c",
".",
"Objects",
"(",
"container",
",",
"opts",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"objects",
"=",
"append",
"(",
"objects",
",",
"newObjects",
"...",
")",
"\n",
"}",
"\n",
"return",
"newObjects",
",",
"err",
"\n",
"}",
")",
"\n",
"return",
"objects",
",",
"err",
"\n",
"}"
] | // ObjectsAll is like Objects but it returns an unlimited number of Objects in a slice
//
// It calls Objects multiple times using the Marker parameter | [
"ObjectsAll",
"is",
"like",
"Objects",
"but",
"it",
"returns",
"an",
"unlimited",
"number",
"of",
"Objects",
"in",
"a",
"slice",
"It",
"calls",
"Objects",
"multiple",
"times",
"using",
"the",
"Marker",
"parameter"
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/swift.go#L1176-L1186 |
6,217 | ncw/swift | swift.go | ObjectNamesAll | func (c *Connection) ObjectNamesAll(container string, opts *ObjectsOpts) ([]string, error) {
objects := make([]string, 0)
err := c.ObjectsWalk(container, opts, func(opts *ObjectsOpts) (interface{}, error) {
newObjects, err := c.ObjectNames(container, opts)
if err == nil {
objects = append(objects, newObjects...)
}
return newObjects, err
})
return objects, err
} | go | func (c *Connection) ObjectNamesAll(container string, opts *ObjectsOpts) ([]string, error) {
objects := make([]string, 0)
err := c.ObjectsWalk(container, opts, func(opts *ObjectsOpts) (interface{}, error) {
newObjects, err := c.ObjectNames(container, opts)
if err == nil {
objects = append(objects, newObjects...)
}
return newObjects, err
})
return objects, err
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"ObjectNamesAll",
"(",
"container",
"string",
",",
"opts",
"*",
"ObjectsOpts",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"objects",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
")",
"\n",
"err",
":=",
"c",
".",
"ObjectsWalk",
"(",
"container",
",",
"opts",
",",
"func",
"(",
"opts",
"*",
"ObjectsOpts",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"newObjects",
",",
"err",
":=",
"c",
".",
"ObjectNames",
"(",
"container",
",",
"opts",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"objects",
"=",
"append",
"(",
"objects",
",",
"newObjects",
"...",
")",
"\n",
"}",
"\n",
"return",
"newObjects",
",",
"err",
"\n",
"}",
")",
"\n",
"return",
"objects",
",",
"err",
"\n",
"}"
] | // ObjectNamesAll is like ObjectNames but it returns all the Objects
//
// It calls ObjectNames multiple times using the Marker parameter. Marker is
// reset unless KeepMarker is set
//
// It has a default Limit parameter but you may pass in your own | [
"ObjectNamesAll",
"is",
"like",
"ObjectNames",
"but",
"it",
"returns",
"all",
"the",
"Objects",
"It",
"calls",
"ObjectNames",
"multiple",
"times",
"using",
"the",
"Marker",
"parameter",
".",
"Marker",
"is",
"reset",
"unless",
"KeepMarker",
"is",
"set",
"It",
"has",
"a",
"default",
"Limit",
"parameter",
"but",
"you",
"may",
"pass",
"in",
"your",
"own"
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/swift.go#L1194-L1204 |
6,218 | ncw/swift | swift.go | getInt64FromHeader | func getInt64FromHeader(resp *http.Response, header string) (result int64, err error) {
value := resp.Header.Get(header)
result, err = strconv.ParseInt(value, 10, 64)
if err != nil {
err = newErrorf(0, "Bad Header '%s': '%s': %s", header, value, err)
}
return
} | go | func getInt64FromHeader(resp *http.Response, header string) (result int64, err error) {
value := resp.Header.Get(header)
result, err = strconv.ParseInt(value, 10, 64)
if err != nil {
err = newErrorf(0, "Bad Header '%s': '%s': %s", header, value, err)
}
return
} | [
"func",
"getInt64FromHeader",
"(",
"resp",
"*",
"http",
".",
"Response",
",",
"header",
"string",
")",
"(",
"result",
"int64",
",",
"err",
"error",
")",
"{",
"value",
":=",
"resp",
".",
"Header",
".",
"Get",
"(",
"header",
")",
"\n",
"result",
",",
"err",
"=",
"strconv",
".",
"ParseInt",
"(",
"value",
",",
"10",
",",
"64",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"err",
"=",
"newErrorf",
"(",
"0",
",",
"\"",
"\"",
",",
"header",
",",
"value",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // getInt64FromHeader is a helper function to decode int64 from header. | [
"getInt64FromHeader",
"is",
"a",
"helper",
"function",
"to",
"decode",
"int64",
"from",
"header",
"."
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/swift.go#L1214-L1221 |
6,219 | ncw/swift | swift.go | Account | func (c *Connection) Account() (info Account, headers Headers, err error) {
var resp *http.Response
resp, headers, err = c.storage(RequestOpts{
Operation: "HEAD",
ErrorMap: ContainerErrorMap,
NoResponse: true,
})
if err != nil {
return
}
// Parse the headers into a dict
//
// {'Accept-Ranges': 'bytes',
// 'Content-Length': '0',
// 'Date': 'Tue, 05 Jul 2011 16:37:06 GMT',
// 'X-Account-Bytes-Used': '316598182',
// 'X-Account-Container-Count': '4',
// 'X-Account-Object-Count': '1433'}
if info.BytesUsed, err = getInt64FromHeader(resp, "X-Account-Bytes-Used"); err != nil {
return
}
if info.Containers, err = getInt64FromHeader(resp, "X-Account-Container-Count"); err != nil {
return
}
if info.Objects, err = getInt64FromHeader(resp, "X-Account-Object-Count"); err != nil {
return
}
return
} | go | func (c *Connection) Account() (info Account, headers Headers, err error) {
var resp *http.Response
resp, headers, err = c.storage(RequestOpts{
Operation: "HEAD",
ErrorMap: ContainerErrorMap,
NoResponse: true,
})
if err != nil {
return
}
// Parse the headers into a dict
//
// {'Accept-Ranges': 'bytes',
// 'Content-Length': '0',
// 'Date': 'Tue, 05 Jul 2011 16:37:06 GMT',
// 'X-Account-Bytes-Used': '316598182',
// 'X-Account-Container-Count': '4',
// 'X-Account-Object-Count': '1433'}
if info.BytesUsed, err = getInt64FromHeader(resp, "X-Account-Bytes-Used"); err != nil {
return
}
if info.Containers, err = getInt64FromHeader(resp, "X-Account-Container-Count"); err != nil {
return
}
if info.Objects, err = getInt64FromHeader(resp, "X-Account-Object-Count"); err != nil {
return
}
return
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"Account",
"(",
")",
"(",
"info",
"Account",
",",
"headers",
"Headers",
",",
"err",
"error",
")",
"{",
"var",
"resp",
"*",
"http",
".",
"Response",
"\n",
"resp",
",",
"headers",
",",
"err",
"=",
"c",
".",
"storage",
"(",
"RequestOpts",
"{",
"Operation",
":",
"\"",
"\"",
",",
"ErrorMap",
":",
"ContainerErrorMap",
",",
"NoResponse",
":",
"true",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"// Parse the headers into a dict",
"//",
"// {'Accept-Ranges': 'bytes',",
"// 'Content-Length': '0',",
"// 'Date': 'Tue, 05 Jul 2011 16:37:06 GMT',",
"// 'X-Account-Bytes-Used': '316598182',",
"// 'X-Account-Container-Count': '4',",
"// 'X-Account-Object-Count': '1433'}",
"if",
"info",
".",
"BytesUsed",
",",
"err",
"=",
"getInt64FromHeader",
"(",
"resp",
",",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"if",
"info",
".",
"Containers",
",",
"err",
"=",
"getInt64FromHeader",
"(",
"resp",
",",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"if",
"info",
".",
"Objects",
",",
"err",
"=",
"getInt64FromHeader",
"(",
"resp",
",",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // Account returns info about the account in an Account struct. | [
"Account",
"returns",
"info",
"about",
"the",
"account",
"in",
"an",
"Account",
"struct",
"."
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/swift.go#L1224-L1252 |
6,220 | ncw/swift | swift.go | AccountUpdate | func (c *Connection) AccountUpdate(h Headers) error {
_, _, err := c.storage(RequestOpts{
Operation: "POST",
ErrorMap: ContainerErrorMap,
NoResponse: true,
Headers: h,
})
return err
} | go | func (c *Connection) AccountUpdate(h Headers) error {
_, _, err := c.storage(RequestOpts{
Operation: "POST",
ErrorMap: ContainerErrorMap,
NoResponse: true,
Headers: h,
})
return err
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"AccountUpdate",
"(",
"h",
"Headers",
")",
"error",
"{",
"_",
",",
"_",
",",
"err",
":=",
"c",
".",
"storage",
"(",
"RequestOpts",
"{",
"Operation",
":",
"\"",
"\"",
",",
"ErrorMap",
":",
"ContainerErrorMap",
",",
"NoResponse",
":",
"true",
",",
"Headers",
":",
"h",
",",
"}",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // AccountUpdate adds, replaces or remove account metadata.
//
// Add or update keys by mentioning them in the Headers.
//
// Remove keys by setting them to an empty string. | [
"AccountUpdate",
"adds",
"replaces",
"or",
"remove",
"account",
"metadata",
".",
"Add",
"or",
"update",
"keys",
"by",
"mentioning",
"them",
"in",
"the",
"Headers",
".",
"Remove",
"keys",
"by",
"setting",
"them",
"to",
"an",
"empty",
"string",
"."
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/swift.go#L1259-L1267 |
6,221 | ncw/swift | swift.go | ContainerCreate | func (c *Connection) ContainerCreate(container string, h Headers) error {
_, _, err := c.storage(RequestOpts{
Container: container,
Operation: "PUT",
ErrorMap: ContainerErrorMap,
NoResponse: true,
Headers: h,
})
return err
} | go | func (c *Connection) ContainerCreate(container string, h Headers) error {
_, _, err := c.storage(RequestOpts{
Container: container,
Operation: "PUT",
ErrorMap: ContainerErrorMap,
NoResponse: true,
Headers: h,
})
return err
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"ContainerCreate",
"(",
"container",
"string",
",",
"h",
"Headers",
")",
"error",
"{",
"_",
",",
"_",
",",
"err",
":=",
"c",
".",
"storage",
"(",
"RequestOpts",
"{",
"Container",
":",
"container",
",",
"Operation",
":",
"\"",
"\"",
",",
"ErrorMap",
":",
"ContainerErrorMap",
",",
"NoResponse",
":",
"true",
",",
"Headers",
":",
"h",
",",
"}",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // ContainerCreate creates a container.
//
// If you don't want to add Headers just pass in nil
//
// No error is returned if it already exists but the metadata if any will be updated. | [
"ContainerCreate",
"creates",
"a",
"container",
".",
"If",
"you",
"don",
"t",
"want",
"to",
"add",
"Headers",
"just",
"pass",
"in",
"nil",
"No",
"error",
"is",
"returned",
"if",
"it",
"already",
"exists",
"but",
"the",
"metadata",
"if",
"any",
"will",
"be",
"updated",
"."
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/swift.go#L1274-L1283 |
6,222 | ncw/swift | swift.go | ContainerDelete | func (c *Connection) ContainerDelete(container string) error {
_, _, err := c.storage(RequestOpts{
Container: container,
Operation: "DELETE",
ErrorMap: ContainerErrorMap,
NoResponse: true,
})
return err
} | go | func (c *Connection) ContainerDelete(container string) error {
_, _, err := c.storage(RequestOpts{
Container: container,
Operation: "DELETE",
ErrorMap: ContainerErrorMap,
NoResponse: true,
})
return err
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"ContainerDelete",
"(",
"container",
"string",
")",
"error",
"{",
"_",
",",
"_",
",",
"err",
":=",
"c",
".",
"storage",
"(",
"RequestOpts",
"{",
"Container",
":",
"container",
",",
"Operation",
":",
"\"",
"\"",
",",
"ErrorMap",
":",
"ContainerErrorMap",
",",
"NoResponse",
":",
"true",
",",
"}",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // ContainerDelete deletes a container.
//
// May return ContainerDoesNotExist or ContainerNotEmpty | [
"ContainerDelete",
"deletes",
"a",
"container",
".",
"May",
"return",
"ContainerDoesNotExist",
"or",
"ContainerNotEmpty"
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/swift.go#L1288-L1296 |
6,223 | ncw/swift | swift.go | Container | func (c *Connection) Container(container string) (info Container, headers Headers, err error) {
var resp *http.Response
resp, headers, err = c.storage(RequestOpts{
Container: container,
Operation: "HEAD",
ErrorMap: ContainerErrorMap,
NoResponse: true,
})
if err != nil {
return
}
// Parse the headers into the struct
info.Name = container
if info.Bytes, err = getInt64FromHeader(resp, "X-Container-Bytes-Used"); err != nil {
return
}
if info.Count, err = getInt64FromHeader(resp, "X-Container-Object-Count"); err != nil {
return
}
return
} | go | func (c *Connection) Container(container string) (info Container, headers Headers, err error) {
var resp *http.Response
resp, headers, err = c.storage(RequestOpts{
Container: container,
Operation: "HEAD",
ErrorMap: ContainerErrorMap,
NoResponse: true,
})
if err != nil {
return
}
// Parse the headers into the struct
info.Name = container
if info.Bytes, err = getInt64FromHeader(resp, "X-Container-Bytes-Used"); err != nil {
return
}
if info.Count, err = getInt64FromHeader(resp, "X-Container-Object-Count"); err != nil {
return
}
return
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"Container",
"(",
"container",
"string",
")",
"(",
"info",
"Container",
",",
"headers",
"Headers",
",",
"err",
"error",
")",
"{",
"var",
"resp",
"*",
"http",
".",
"Response",
"\n",
"resp",
",",
"headers",
",",
"err",
"=",
"c",
".",
"storage",
"(",
"RequestOpts",
"{",
"Container",
":",
"container",
",",
"Operation",
":",
"\"",
"\"",
",",
"ErrorMap",
":",
"ContainerErrorMap",
",",
"NoResponse",
":",
"true",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"// Parse the headers into the struct",
"info",
".",
"Name",
"=",
"container",
"\n",
"if",
"info",
".",
"Bytes",
",",
"err",
"=",
"getInt64FromHeader",
"(",
"resp",
",",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"if",
"info",
".",
"Count",
",",
"err",
"=",
"getInt64FromHeader",
"(",
"resp",
",",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // Container returns info about a single container including any
// metadata in the headers. | [
"Container",
"returns",
"info",
"about",
"a",
"single",
"container",
"including",
"any",
"metadata",
"in",
"the",
"headers",
"."
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/swift.go#L1300-L1320 |
6,224 | ncw/swift | swift.go | Write | func (file *ObjectCreateFile) Write(p []byte) (n int, err error) {
n, err = file.pipeWriter.Write(p)
if err == io.ErrClosedPipe {
if file.err != nil {
return 0, file.err
}
return 0, newError(500, "Write on closed file")
}
if err == nil && file.checkHash {
_, _ = file.hash.Write(p)
}
return
} | go | func (file *ObjectCreateFile) Write(p []byte) (n int, err error) {
n, err = file.pipeWriter.Write(p)
if err == io.ErrClosedPipe {
if file.err != nil {
return 0, file.err
}
return 0, newError(500, "Write on closed file")
}
if err == nil && file.checkHash {
_, _ = file.hash.Write(p)
}
return
} | [
"func",
"(",
"file",
"*",
"ObjectCreateFile",
")",
"Write",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"n",
",",
"err",
"=",
"file",
".",
"pipeWriter",
".",
"Write",
"(",
"p",
")",
"\n",
"if",
"err",
"==",
"io",
".",
"ErrClosedPipe",
"{",
"if",
"file",
".",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"file",
".",
"err",
"\n",
"}",
"\n",
"return",
"0",
",",
"newError",
"(",
"500",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"err",
"==",
"nil",
"&&",
"file",
".",
"checkHash",
"{",
"_",
",",
"_",
"=",
"file",
".",
"hash",
".",
"Write",
"(",
"p",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // Write bytes to the object - see io.Writer | [
"Write",
"bytes",
"to",
"the",
"object",
"-",
"see",
"io",
".",
"Writer"
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/swift.go#L1355-L1367 |
6,225 | ncw/swift | swift.go | objectPutHeaders | func objectPutHeaders(objectName string, checkHash *bool, Hash string, contentType string, h Headers) Headers {
if contentType == "" {
contentType = mime.TypeByExtension(path.Ext(objectName))
if contentType == "" {
contentType = "application/octet-stream"
}
}
// Meta stuff
extraHeaders := map[string]string{
"Content-Type": contentType,
}
for key, value := range h {
extraHeaders[key] = value
}
if Hash != "" {
extraHeaders["Etag"] = Hash
*checkHash = false // the server will do it
}
return extraHeaders
} | go | func objectPutHeaders(objectName string, checkHash *bool, Hash string, contentType string, h Headers) Headers {
if contentType == "" {
contentType = mime.TypeByExtension(path.Ext(objectName))
if contentType == "" {
contentType = "application/octet-stream"
}
}
// Meta stuff
extraHeaders := map[string]string{
"Content-Type": contentType,
}
for key, value := range h {
extraHeaders[key] = value
}
if Hash != "" {
extraHeaders["Etag"] = Hash
*checkHash = false // the server will do it
}
return extraHeaders
} | [
"func",
"objectPutHeaders",
"(",
"objectName",
"string",
",",
"checkHash",
"*",
"bool",
",",
"Hash",
"string",
",",
"contentType",
"string",
",",
"h",
"Headers",
")",
"Headers",
"{",
"if",
"contentType",
"==",
"\"",
"\"",
"{",
"contentType",
"=",
"mime",
".",
"TypeByExtension",
"(",
"path",
".",
"Ext",
"(",
"objectName",
")",
")",
"\n",
"if",
"contentType",
"==",
"\"",
"\"",
"{",
"contentType",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"}",
"\n",
"// Meta stuff",
"extraHeaders",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"contentType",
",",
"}",
"\n",
"for",
"key",
",",
"value",
":=",
"range",
"h",
"{",
"extraHeaders",
"[",
"key",
"]",
"=",
"value",
"\n",
"}",
"\n",
"if",
"Hash",
"!=",
"\"",
"\"",
"{",
"extraHeaders",
"[",
"\"",
"\"",
"]",
"=",
"Hash",
"\n",
"*",
"checkHash",
"=",
"false",
"// the server will do it",
"\n",
"}",
"\n",
"return",
"extraHeaders",
"\n",
"}"
] | // objectPutHeaders create a set of headers for a PUT
//
// It guesses the contentType from the objectName if it isn't set
//
// checkHash may be changed | [
"objectPutHeaders",
"create",
"a",
"set",
"of",
"headers",
"for",
"a",
"PUT",
"It",
"guesses",
"the",
"contentType",
"from",
"the",
"objectName",
"if",
"it",
"isn",
"t",
"set",
"checkHash",
"may",
"be",
"changed"
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/swift.go#L1418-L1437 |
6,226 | ncw/swift | swift.go | ObjectPutString | func (c *Connection) ObjectPutString(container string, objectName string, contents string, contentType string) (err error) {
buf := strings.NewReader(contents)
h := Headers{"Content-Length": strconv.Itoa(len(contents))}
_, err = c.ObjectPut(container, objectName, buf, true, "", contentType, h)
return
} | go | func (c *Connection) ObjectPutString(container string, objectName string, contents string, contentType string) (err error) {
buf := strings.NewReader(contents)
h := Headers{"Content-Length": strconv.Itoa(len(contents))}
_, err = c.ObjectPut(container, objectName, buf, true, "", contentType, h)
return
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"ObjectPutString",
"(",
"container",
"string",
",",
"objectName",
"string",
",",
"contents",
"string",
",",
"contentType",
"string",
")",
"(",
"err",
"error",
")",
"{",
"buf",
":=",
"strings",
".",
"NewReader",
"(",
"contents",
")",
"\n",
"h",
":=",
"Headers",
"{",
"\"",
"\"",
":",
"strconv",
".",
"Itoa",
"(",
"len",
"(",
"contents",
")",
")",
"}",
"\n",
"_",
",",
"err",
"=",
"c",
".",
"ObjectPut",
"(",
"container",
",",
"objectName",
",",
"buf",
",",
"true",
",",
"\"",
"\"",
",",
"contentType",
",",
"h",
")",
"\n",
"return",
"\n",
"}"
] | // ObjectPutString creates an object from a string in a container.
//
// This is a simplified interface which checks the MD5 | [
"ObjectPutString",
"creates",
"an",
"object",
"from",
"a",
"string",
"in",
"a",
"container",
".",
"This",
"is",
"a",
"simplified",
"interface",
"which",
"checks",
"the",
"MD5"
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/swift.go#L1557-L1562 |
6,227 | ncw/swift | swift.go | Read | func (file *ObjectOpenFile) Read(p []byte) (n int, err error) {
if file.overSeeked {
return 0, io.EOF
}
n, err = file.body.Read(p)
file.bytes += int64(n)
file.pos += int64(n)
if err == io.EOF {
file.eof = true
}
return
} | go | func (file *ObjectOpenFile) Read(p []byte) (n int, err error) {
if file.overSeeked {
return 0, io.EOF
}
n, err = file.body.Read(p)
file.bytes += int64(n)
file.pos += int64(n)
if err == io.EOF {
file.eof = true
}
return
} | [
"func",
"(",
"file",
"*",
"ObjectOpenFile",
")",
"Read",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"if",
"file",
".",
"overSeeked",
"{",
"return",
"0",
",",
"io",
".",
"EOF",
"\n",
"}",
"\n",
"n",
",",
"err",
"=",
"file",
".",
"body",
".",
"Read",
"(",
"p",
")",
"\n",
"file",
".",
"bytes",
"+=",
"int64",
"(",
"n",
")",
"\n",
"file",
".",
"pos",
"+=",
"int64",
"(",
"n",
")",
"\n",
"if",
"err",
"==",
"io",
".",
"EOF",
"{",
"file",
".",
"eof",
"=",
"true",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // Read bytes from the object - see io.Reader | [
"Read",
"bytes",
"from",
"the",
"object",
"-",
"see",
"io",
".",
"Reader"
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/swift.go#L1584-L1595 |
6,228 | ncw/swift | swift.go | Length | func (file *ObjectOpenFile) Length() (int64, error) {
if !file.lengthOk {
info, _, err := file.connection.Object(file.container, file.objectName)
file.length = info.Bytes
file.lengthOk = (err == nil)
return file.length, err
}
return file.length, nil
} | go | func (file *ObjectOpenFile) Length() (int64, error) {
if !file.lengthOk {
info, _, err := file.connection.Object(file.container, file.objectName)
file.length = info.Bytes
file.lengthOk = (err == nil)
return file.length, err
}
return file.length, nil
} | [
"func",
"(",
"file",
"*",
"ObjectOpenFile",
")",
"Length",
"(",
")",
"(",
"int64",
",",
"error",
")",
"{",
"if",
"!",
"file",
".",
"lengthOk",
"{",
"info",
",",
"_",
",",
"err",
":=",
"file",
".",
"connection",
".",
"Object",
"(",
"file",
".",
"container",
",",
"file",
".",
"objectName",
")",
"\n",
"file",
".",
"length",
"=",
"info",
".",
"Bytes",
"\n",
"file",
".",
"lengthOk",
"=",
"(",
"err",
"==",
"nil",
")",
"\n",
"return",
"file",
".",
"length",
",",
"err",
"\n",
"}",
"\n",
"return",
"file",
".",
"length",
",",
"nil",
"\n",
"}"
] | // Length gets the objects content length either from a cached copy or
// from the server. | [
"Length",
"gets",
"the",
"objects",
"content",
"length",
"either",
"from",
"a",
"cached",
"copy",
"or",
"from",
"the",
"server",
"."
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/swift.go#L1662-L1670 |
6,229 | ncw/swift | swift.go | Close | func (file *ObjectOpenFile) Close() (err error) {
// Close the body at the end
defer checkClose(file.resp.Body, &err)
// If not end of file or seeked then can't check anything
if !file.eof || file.seeked {
return
}
// Check the MD5 sum if requested
if file.checkHash {
receivedMd5 := strings.ToLower(file.resp.Header.Get("Etag"))
calculatedMd5 := fmt.Sprintf("%x", file.hash.Sum(nil))
if receivedMd5 != calculatedMd5 {
err = ObjectCorrupted
return
}
}
// Check to see we read the correct number of bytes
if file.lengthOk && file.length != file.bytes {
err = ObjectCorrupted
return
}
return
} | go | func (file *ObjectOpenFile) Close() (err error) {
// Close the body at the end
defer checkClose(file.resp.Body, &err)
// If not end of file or seeked then can't check anything
if !file.eof || file.seeked {
return
}
// Check the MD5 sum if requested
if file.checkHash {
receivedMd5 := strings.ToLower(file.resp.Header.Get("Etag"))
calculatedMd5 := fmt.Sprintf("%x", file.hash.Sum(nil))
if receivedMd5 != calculatedMd5 {
err = ObjectCorrupted
return
}
}
// Check to see we read the correct number of bytes
if file.lengthOk && file.length != file.bytes {
err = ObjectCorrupted
return
}
return
} | [
"func",
"(",
"file",
"*",
"ObjectOpenFile",
")",
"Close",
"(",
")",
"(",
"err",
"error",
")",
"{",
"// Close the body at the end",
"defer",
"checkClose",
"(",
"file",
".",
"resp",
".",
"Body",
",",
"&",
"err",
")",
"\n\n",
"// If not end of file or seeked then can't check anything",
"if",
"!",
"file",
".",
"eof",
"||",
"file",
".",
"seeked",
"{",
"return",
"\n",
"}",
"\n\n",
"// Check the MD5 sum if requested",
"if",
"file",
".",
"checkHash",
"{",
"receivedMd5",
":=",
"strings",
".",
"ToLower",
"(",
"file",
".",
"resp",
".",
"Header",
".",
"Get",
"(",
"\"",
"\"",
")",
")",
"\n",
"calculatedMd5",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"file",
".",
"hash",
".",
"Sum",
"(",
"nil",
")",
")",
"\n",
"if",
"receivedMd5",
"!=",
"calculatedMd5",
"{",
"err",
"=",
"ObjectCorrupted",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Check to see we read the correct number of bytes",
"if",
"file",
".",
"lengthOk",
"&&",
"file",
".",
"length",
"!=",
"file",
".",
"bytes",
"{",
"err",
"=",
"ObjectCorrupted",
"\n",
"return",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // Close the object and checks the length and md5sum if it was
// required and all the object was read | [
"Close",
"the",
"object",
"and",
"checks",
"the",
"length",
"and",
"md5sum",
"if",
"it",
"was",
"required",
"and",
"all",
"the",
"object",
"was",
"read"
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/swift.go#L1674-L1699 |
6,230 | ncw/swift | swift.go | ObjectGetString | func (c *Connection) ObjectGetString(container string, objectName string) (contents string, err error) {
var buf bytes.Buffer
_, err = c.ObjectGet(container, objectName, &buf, true, nil)
contents = buf.String()
return
} | go | func (c *Connection) ObjectGetString(container string, objectName string) (contents string, err error) {
var buf bytes.Buffer
_, err = c.ObjectGet(container, objectName, &buf, true, nil)
contents = buf.String()
return
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"ObjectGetString",
"(",
"container",
"string",
",",
"objectName",
"string",
")",
"(",
"contents",
"string",
",",
"err",
"error",
")",
"{",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"_",
",",
"err",
"=",
"c",
".",
"ObjectGet",
"(",
"container",
",",
"objectName",
",",
"&",
"buf",
",",
"true",
",",
"nil",
")",
"\n",
"contents",
"=",
"buf",
".",
"String",
"(",
")",
"\n",
"return",
"\n",
"}"
] | // ObjectGetString returns an object as a string.
//
// This is a simplified interface which checks the MD5 | [
"ObjectGetString",
"returns",
"an",
"object",
"as",
"a",
"string",
".",
"This",
"is",
"a",
"simplified",
"interface",
"which",
"checks",
"the",
"MD5"
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/swift.go#L1815-L1820 |
6,231 | ncw/swift | swift.go | ObjectDelete | func (c *Connection) ObjectDelete(container string, objectName string) error {
_, _, err := c.storage(RequestOpts{
Container: container,
ObjectName: objectName,
Operation: "DELETE",
ErrorMap: objectErrorMap,
})
return err
} | go | func (c *Connection) ObjectDelete(container string, objectName string) error {
_, _, err := c.storage(RequestOpts{
Container: container,
ObjectName: objectName,
Operation: "DELETE",
ErrorMap: objectErrorMap,
})
return err
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"ObjectDelete",
"(",
"container",
"string",
",",
"objectName",
"string",
")",
"error",
"{",
"_",
",",
"_",
",",
"err",
":=",
"c",
".",
"storage",
"(",
"RequestOpts",
"{",
"Container",
":",
"container",
",",
"ObjectName",
":",
"objectName",
",",
"Operation",
":",
"\"",
"\"",
",",
"ErrorMap",
":",
"objectErrorMap",
",",
"}",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // ObjectDelete deletes the object.
//
// May return ObjectNotFound if the object isn't found | [
"ObjectDelete",
"deletes",
"the",
"object",
".",
"May",
"return",
"ObjectNotFound",
"if",
"the",
"object",
"isn",
"t",
"found"
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/swift.go#L1825-L1833 |
6,232 | ncw/swift | swift.go | ObjectTempUrl | func (c *Connection) ObjectTempUrl(container string, objectName string, secretKey string, method string, expires time.Time) string {
mac := hmac.New(sha1.New, []byte(secretKey))
prefix, _ := url.Parse(c.StorageUrl)
body := fmt.Sprintf("%s\n%d\n%s/%s/%s", method, expires.Unix(), prefix.Path, container, objectName)
mac.Write([]byte(body))
sig := hex.EncodeToString(mac.Sum(nil))
return fmt.Sprintf("%s/%s/%s?temp_url_sig=%s&temp_url_expires=%d", c.StorageUrl, container, objectName, sig, expires.Unix())
} | go | func (c *Connection) ObjectTempUrl(container string, objectName string, secretKey string, method string, expires time.Time) string {
mac := hmac.New(sha1.New, []byte(secretKey))
prefix, _ := url.Parse(c.StorageUrl)
body := fmt.Sprintf("%s\n%d\n%s/%s/%s", method, expires.Unix(), prefix.Path, container, objectName)
mac.Write([]byte(body))
sig := hex.EncodeToString(mac.Sum(nil))
return fmt.Sprintf("%s/%s/%s?temp_url_sig=%s&temp_url_expires=%d", c.StorageUrl, container, objectName, sig, expires.Unix())
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"ObjectTempUrl",
"(",
"container",
"string",
",",
"objectName",
"string",
",",
"secretKey",
"string",
",",
"method",
"string",
",",
"expires",
"time",
".",
"Time",
")",
"string",
"{",
"mac",
":=",
"hmac",
".",
"New",
"(",
"sha1",
".",
"New",
",",
"[",
"]",
"byte",
"(",
"secretKey",
")",
")",
"\n",
"prefix",
",",
"_",
":=",
"url",
".",
"Parse",
"(",
"c",
".",
"StorageUrl",
")",
"\n",
"body",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\\n",
"\"",
",",
"method",
",",
"expires",
".",
"Unix",
"(",
")",
",",
"prefix",
".",
"Path",
",",
"container",
",",
"objectName",
")",
"\n",
"mac",
".",
"Write",
"(",
"[",
"]",
"byte",
"(",
"body",
")",
")",
"\n",
"sig",
":=",
"hex",
".",
"EncodeToString",
"(",
"mac",
".",
"Sum",
"(",
"nil",
")",
")",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"c",
".",
"StorageUrl",
",",
"container",
",",
"objectName",
",",
"sig",
",",
"expires",
".",
"Unix",
"(",
")",
")",
"\n",
"}"
] | // ObjectTempUrl returns a temporary URL for an object | [
"ObjectTempUrl",
"returns",
"a",
"temporary",
"URL",
"for",
"an",
"object"
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/swift.go#L1836-L1843 |
6,233 | ncw/swift | swift.go | parseResponseStatus | func parseResponseStatus(resp string, errorMap errorMap) error {
code := 0
reason := resp
t := strings.SplitN(resp, " ", 2)
if len(t) == 2 {
ncode, err := strconv.Atoi(t[0])
if err == nil {
code = ncode
reason = t[1]
}
}
if errorMap != nil {
if err, ok := errorMap[code]; ok {
return err
}
}
if 200 <= code && code <= 299 {
return nil
}
return newError(code, reason)
} | go | func parseResponseStatus(resp string, errorMap errorMap) error {
code := 0
reason := resp
t := strings.SplitN(resp, " ", 2)
if len(t) == 2 {
ncode, err := strconv.Atoi(t[0])
if err == nil {
code = ncode
reason = t[1]
}
}
if errorMap != nil {
if err, ok := errorMap[code]; ok {
return err
}
}
if 200 <= code && code <= 299 {
return nil
}
return newError(code, reason)
} | [
"func",
"parseResponseStatus",
"(",
"resp",
"string",
",",
"errorMap",
"errorMap",
")",
"error",
"{",
"code",
":=",
"0",
"\n",
"reason",
":=",
"resp",
"\n",
"t",
":=",
"strings",
".",
"SplitN",
"(",
"resp",
",",
"\"",
"\"",
",",
"2",
")",
"\n",
"if",
"len",
"(",
"t",
")",
"==",
"2",
"{",
"ncode",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"t",
"[",
"0",
"]",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"code",
"=",
"ncode",
"\n",
"reason",
"=",
"t",
"[",
"1",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"errorMap",
"!=",
"nil",
"{",
"if",
"err",
",",
"ok",
":=",
"errorMap",
"[",
"code",
"]",
";",
"ok",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"200",
"<=",
"code",
"&&",
"code",
"<=",
"299",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"newError",
"(",
"code",
",",
"reason",
")",
"\n",
"}"
] | // parseResponseStatus parses string like "200 OK" and returns Error.
//
// For status codes beween 200 and 299, this returns nil. | [
"parseResponseStatus",
"parses",
"string",
"like",
"200",
"OK",
"and",
"returns",
"Error",
".",
"For",
"status",
"codes",
"beween",
"200",
"and",
"299",
"this",
"returns",
"nil",
"."
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/swift.go#L1848-L1868 |
6,234 | ncw/swift | swift.go | urlPathEscape | func urlPathEscape(in string) string {
var u url.URL
u.Path = in
return u.String()
} | go | func urlPathEscape(in string) string {
var u url.URL
u.Path = in
return u.String()
} | [
"func",
"urlPathEscape",
"(",
"in",
"string",
")",
"string",
"{",
"var",
"u",
"url",
".",
"URL",
"\n",
"u",
".",
"Path",
"=",
"in",
"\n",
"return",
"u",
".",
"String",
"(",
")",
"\n",
"}"
] | // urlPathEscape escapes URL path the in string using URL escaping rules
//
// This mimics url.PathEscape which only available from go 1.8 | [
"urlPathEscape",
"escapes",
"URL",
"path",
"the",
"in",
"string",
"using",
"URL",
"escaping",
"rules",
"This",
"mimics",
"url",
".",
"PathEscape",
"which",
"only",
"available",
"from",
"go",
"1",
".",
"8"
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/swift.go#L2129-L2133 |
6,235 | ncw/swift | swift.go | ObjectCopy | func (c *Connection) ObjectCopy(srcContainer string, srcObjectName string, dstContainer string, dstObjectName string, h Headers) (headers Headers, err error) {
// Meta stuff
extraHeaders := map[string]string{
"Destination": urlPathEscape(dstContainer + "/" + dstObjectName),
}
for key, value := range h {
extraHeaders[key] = value
}
_, headers, err = c.storage(RequestOpts{
Container: srcContainer,
ObjectName: srcObjectName,
Operation: "COPY",
ErrorMap: objectErrorMap,
NoResponse: true,
Headers: extraHeaders,
})
return
} | go | func (c *Connection) ObjectCopy(srcContainer string, srcObjectName string, dstContainer string, dstObjectName string, h Headers) (headers Headers, err error) {
// Meta stuff
extraHeaders := map[string]string{
"Destination": urlPathEscape(dstContainer + "/" + dstObjectName),
}
for key, value := range h {
extraHeaders[key] = value
}
_, headers, err = c.storage(RequestOpts{
Container: srcContainer,
ObjectName: srcObjectName,
Operation: "COPY",
ErrorMap: objectErrorMap,
NoResponse: true,
Headers: extraHeaders,
})
return
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"ObjectCopy",
"(",
"srcContainer",
"string",
",",
"srcObjectName",
"string",
",",
"dstContainer",
"string",
",",
"dstObjectName",
"string",
",",
"h",
"Headers",
")",
"(",
"headers",
"Headers",
",",
"err",
"error",
")",
"{",
"// Meta stuff",
"extraHeaders",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"urlPathEscape",
"(",
"dstContainer",
"+",
"\"",
"\"",
"+",
"dstObjectName",
")",
",",
"}",
"\n",
"for",
"key",
",",
"value",
":=",
"range",
"h",
"{",
"extraHeaders",
"[",
"key",
"]",
"=",
"value",
"\n",
"}",
"\n",
"_",
",",
"headers",
",",
"err",
"=",
"c",
".",
"storage",
"(",
"RequestOpts",
"{",
"Container",
":",
"srcContainer",
",",
"ObjectName",
":",
"srcObjectName",
",",
"Operation",
":",
"\"",
"\"",
",",
"ErrorMap",
":",
"objectErrorMap",
",",
"NoResponse",
":",
"true",
",",
"Headers",
":",
"extraHeaders",
",",
"}",
")",
"\n",
"return",
"\n",
"}"
] | // ObjectCopy does a server side copy of an object to a new position
//
// All metadata is preserved. If metadata is set in the headers then
// it overrides the old metadata on the copied object.
//
// The destination container must exist before the copy.
//
// You can use this to copy an object to itself - this is the only way
// to update the content type of an object. | [
"ObjectCopy",
"does",
"a",
"server",
"side",
"copy",
"of",
"an",
"object",
"to",
"a",
"new",
"position",
"All",
"metadata",
"is",
"preserved",
".",
"If",
"metadata",
"is",
"set",
"in",
"the",
"headers",
"then",
"it",
"overrides",
"the",
"old",
"metadata",
"on",
"the",
"copied",
"object",
".",
"The",
"destination",
"container",
"must",
"exist",
"before",
"the",
"copy",
".",
"You",
"can",
"use",
"this",
"to",
"copy",
"an",
"object",
"to",
"itself",
"-",
"this",
"is",
"the",
"only",
"way",
"to",
"update",
"the",
"content",
"type",
"of",
"an",
"object",
"."
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/swift.go#L2144-L2161 |
6,236 | ncw/swift | swift.go | ObjectMove | func (c *Connection) ObjectMove(srcContainer string, srcObjectName string, dstContainer string, dstObjectName string) (err error) {
_, err = c.ObjectCopy(srcContainer, srcObjectName, dstContainer, dstObjectName, nil)
if err != nil {
return
}
return c.ObjectDelete(srcContainer, srcObjectName)
} | go | func (c *Connection) ObjectMove(srcContainer string, srcObjectName string, dstContainer string, dstObjectName string) (err error) {
_, err = c.ObjectCopy(srcContainer, srcObjectName, dstContainer, dstObjectName, nil)
if err != nil {
return
}
return c.ObjectDelete(srcContainer, srcObjectName)
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"ObjectMove",
"(",
"srcContainer",
"string",
",",
"srcObjectName",
"string",
",",
"dstContainer",
"string",
",",
"dstObjectName",
"string",
")",
"(",
"err",
"error",
")",
"{",
"_",
",",
"err",
"=",
"c",
".",
"ObjectCopy",
"(",
"srcContainer",
",",
"srcObjectName",
",",
"dstContainer",
",",
"dstObjectName",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"return",
"c",
".",
"ObjectDelete",
"(",
"srcContainer",
",",
"srcObjectName",
")",
"\n",
"}"
] | // ObjectMove does a server side move of an object to a new position
//
// This is a convenience method which calls ObjectCopy then ObjectDelete
//
// All metadata is preserved.
//
// The destination container must exist before the copy. | [
"ObjectMove",
"does",
"a",
"server",
"side",
"move",
"of",
"an",
"object",
"to",
"a",
"new",
"position",
"This",
"is",
"a",
"convenience",
"method",
"which",
"calls",
"ObjectCopy",
"then",
"ObjectDelete",
"All",
"metadata",
"is",
"preserved",
".",
"The",
"destination",
"container",
"must",
"exist",
"before",
"the",
"copy",
"."
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/swift.go#L2170-L2176 |
6,237 | ncw/swift | swift.go | ObjectUpdateContentType | func (c *Connection) ObjectUpdateContentType(container string, objectName string, contentType string) (err error) {
h := Headers{"Content-Type": contentType}
_, err = c.ObjectCopy(container, objectName, container, objectName, h)
return
} | go | func (c *Connection) ObjectUpdateContentType(container string, objectName string, contentType string) (err error) {
h := Headers{"Content-Type": contentType}
_, err = c.ObjectCopy(container, objectName, container, objectName, h)
return
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"ObjectUpdateContentType",
"(",
"container",
"string",
",",
"objectName",
"string",
",",
"contentType",
"string",
")",
"(",
"err",
"error",
")",
"{",
"h",
":=",
"Headers",
"{",
"\"",
"\"",
":",
"contentType",
"}",
"\n",
"_",
",",
"err",
"=",
"c",
".",
"ObjectCopy",
"(",
"container",
",",
"objectName",
",",
"container",
",",
"objectName",
",",
"h",
")",
"\n",
"return",
"\n",
"}"
] | // ObjectUpdateContentType updates the content type of an object
//
// This is a convenience method which calls ObjectCopy
//
// All other metadata is preserved. | [
"ObjectUpdateContentType",
"updates",
"the",
"content",
"type",
"of",
"an",
"object",
"This",
"is",
"a",
"convenience",
"method",
"which",
"calls",
"ObjectCopy",
"All",
"other",
"metadata",
"is",
"preserved",
"."
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/swift.go#L2183-L2187 |
6,238 | ncw/swift | swift.go | VersionEnable | func (c *Connection) VersionEnable(current, version string) error {
h := Headers{"X-Versions-Location": version}
if err := c.ContainerUpdate(current, h); err != nil {
return err
}
// Check to see if the header was set properly
_, headers, err := c.Container(current)
if err != nil {
return err
}
// If failed to set versions header, return Forbidden as the server doesn't support this
if headers["X-Versions-Location"] != version {
return Forbidden
}
return nil
} | go | func (c *Connection) VersionEnable(current, version string) error {
h := Headers{"X-Versions-Location": version}
if err := c.ContainerUpdate(current, h); err != nil {
return err
}
// Check to see if the header was set properly
_, headers, err := c.Container(current)
if err != nil {
return err
}
// If failed to set versions header, return Forbidden as the server doesn't support this
if headers["X-Versions-Location"] != version {
return Forbidden
}
return nil
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"VersionEnable",
"(",
"current",
",",
"version",
"string",
")",
"error",
"{",
"h",
":=",
"Headers",
"{",
"\"",
"\"",
":",
"version",
"}",
"\n",
"if",
"err",
":=",
"c",
".",
"ContainerUpdate",
"(",
"current",
",",
"h",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"// Check to see if the header was set properly",
"_",
",",
"headers",
",",
"err",
":=",
"c",
".",
"Container",
"(",
"current",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"// If failed to set versions header, return Forbidden as the server doesn't support this",
"if",
"headers",
"[",
"\"",
"\"",
"]",
"!=",
"version",
"{",
"return",
"Forbidden",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // VersionEnable enables versioning on the current container with version as the tracking container.
//
// May return Forbidden if this isn't supported by the server | [
"VersionEnable",
"enables",
"versioning",
"on",
"the",
"current",
"container",
"with",
"version",
"as",
"the",
"tracking",
"container",
".",
"May",
"return",
"Forbidden",
"if",
"this",
"isn",
"t",
"supported",
"by",
"the",
"server"
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/swift.go#L2213-L2228 |
6,239 | ncw/swift | swift.go | VersionDisable | func (c *Connection) VersionDisable(current string) error {
h := Headers{"X-Versions-Location": ""}
if err := c.ContainerUpdate(current, h); err != nil {
return err
}
return nil
} | go | func (c *Connection) VersionDisable(current string) error {
h := Headers{"X-Versions-Location": ""}
if err := c.ContainerUpdate(current, h); err != nil {
return err
}
return nil
} | [
"func",
"(",
"c",
"*",
"Connection",
")",
"VersionDisable",
"(",
"current",
"string",
")",
"error",
"{",
"h",
":=",
"Headers",
"{",
"\"",
"\"",
":",
"\"",
"\"",
"}",
"\n",
"if",
"err",
":=",
"c",
".",
"ContainerUpdate",
"(",
"current",
",",
"h",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // VersionDisable disables versioning on the current container. | [
"VersionDisable",
"disables",
"versioning",
"on",
"the",
"current",
"container",
"."
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/swift.go#L2231-L2237 |
6,240 | ncw/swift | compatibility_1_0.go | resetTimer | func resetTimer(t *time.Timer, d time.Duration) {
t.Stop()
// Very likely this doesn't actually work if we are already
// selecting on t.C. However we've stopped the original timer
// so won't break transfers but may not time them out :-(
*t = *time.NewTimer(d)
} | go | func resetTimer(t *time.Timer, d time.Duration) {
t.Stop()
// Very likely this doesn't actually work if we are already
// selecting on t.C. However we've stopped the original timer
// so won't break transfers but may not time them out :-(
*t = *time.NewTimer(d)
} | [
"func",
"resetTimer",
"(",
"t",
"*",
"time",
".",
"Timer",
",",
"d",
"time",
".",
"Duration",
")",
"{",
"t",
".",
"Stop",
"(",
")",
"\n",
"// Very likely this doesn't actually work if we are already",
"// selecting on t.C. However we've stopped the original timer",
"// so won't break transfers but may not time them out :-(",
"*",
"t",
"=",
"*",
"time",
".",
"NewTimer",
"(",
"d",
")",
"\n",
"}"
] | // Reset a timer - Doesn't work properly < go 1.1
//
// This is quite hard to do properly under go < 1.1 so we do a crude
// approximation and hope that everyone upgrades to go 1.1 quickly | [
"Reset",
"a",
"timer",
"-",
"Doesn",
"t",
"work",
"properly",
"<",
"go",
"1",
".",
"1",
"This",
"is",
"quite",
"hard",
"to",
"do",
"properly",
"under",
"go",
"<",
"1",
".",
"1",
"so",
"we",
"do",
"a",
"crude",
"approximation",
"and",
"hope",
"that",
"everyone",
"upgrades",
"to",
"go",
"1",
".",
"1",
"quickly"
] | 753d2090bb62619675997bd87a8e3af423a00f2d | https://github.com/ncw/swift/blob/753d2090bb62619675997bd87a8e3af423a00f2d/compatibility_1_0.go#L22-L28 |
6,241 | mattn/go-runewidth | runewidth.go | StringWidth | func (c *Condition) StringWidth(s string) (width int) {
if c.ZeroWidthJoiner {
return c.stringWidthZeroJoiner(s)
}
return c.stringWidth(s)
} | go | func (c *Condition) StringWidth(s string) (width int) {
if c.ZeroWidthJoiner {
return c.stringWidthZeroJoiner(s)
}
return c.stringWidth(s)
} | [
"func",
"(",
"c",
"*",
"Condition",
")",
"StringWidth",
"(",
"s",
"string",
")",
"(",
"width",
"int",
")",
"{",
"if",
"c",
".",
"ZeroWidthJoiner",
"{",
"return",
"c",
".",
"stringWidthZeroJoiner",
"(",
"s",
")",
"\n",
"}",
"\n",
"return",
"c",
".",
"stringWidth",
"(",
"s",
")",
"\n",
"}"
] | // StringWidth return width as you can see | [
"StringWidth",
"return",
"width",
"as",
"you",
"can",
"see"
] | 703b5e6b11ae25aeb2af9ebb5d5fdf8fa2575211 | https://github.com/mattn/go-runewidth/blob/703b5e6b11ae25aeb2af9ebb5d5fdf8fa2575211/runewidth.go#L860-L865 |
6,242 | mattn/go-runewidth | runewidth.go | FillRight | func FillRight(s string, w int) string {
return DefaultCondition.FillRight(s, w)
} | go | func FillRight(s string, w int) string {
return DefaultCondition.FillRight(s, w)
} | [
"func",
"FillRight",
"(",
"s",
"string",
",",
"w",
"int",
")",
"string",
"{",
"return",
"DefaultCondition",
".",
"FillRight",
"(",
"s",
",",
"w",
")",
"\n",
"}"
] | // FillRight return string filled in left by spaces in w cells | [
"FillRight",
"return",
"string",
"filled",
"in",
"left",
"by",
"spaces",
"in",
"w",
"cells"
] | 703b5e6b11ae25aeb2af9ebb5d5fdf8fa2575211 | https://github.com/mattn/go-runewidth/blob/703b5e6b11ae25aeb2af9ebb5d5fdf8fa2575211/runewidth.go#L975-L977 |
6,243 | tendermint/iavl | proof_path.go | computeRootHash | func (pwl pathWithLeaf) computeRootHash() []byte {
leafHash := pwl.Leaf.Hash()
return pwl.Path.computeRootHash(leafHash)
} | go | func (pwl pathWithLeaf) computeRootHash() []byte {
leafHash := pwl.Leaf.Hash()
return pwl.Path.computeRootHash(leafHash)
} | [
"func",
"(",
"pwl",
"pathWithLeaf",
")",
"computeRootHash",
"(",
")",
"[",
"]",
"byte",
"{",
"leafHash",
":=",
"pwl",
".",
"Leaf",
".",
"Hash",
"(",
")",
"\n",
"return",
"pwl",
".",
"Path",
".",
"computeRootHash",
"(",
"leafHash",
")",
"\n",
"}"
] | // `computeRootHash` computes the root hash with leaf node.
// Does not verify the root hash. | [
"computeRootHash",
"computes",
"the",
"root",
"hash",
"with",
"leaf",
"node",
".",
"Does",
"not",
"verify",
"the",
"root",
"hash",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/proof_path.go#L41-L44 |
6,244 | tendermint/iavl | proof_path.go | computeRootHash | func (pl PathToLeaf) computeRootHash(leafHash []byte) []byte {
hash := leafHash
for i := len(pl) - 1; i >= 0; i-- {
pin := pl[i]
hash = pin.Hash(hash)
}
return hash
} | go | func (pl PathToLeaf) computeRootHash(leafHash []byte) []byte {
hash := leafHash
for i := len(pl) - 1; i >= 0; i-- {
pin := pl[i]
hash = pin.Hash(hash)
}
return hash
} | [
"func",
"(",
"pl",
"PathToLeaf",
")",
"computeRootHash",
"(",
"leafHash",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"hash",
":=",
"leafHash",
"\n",
"for",
"i",
":=",
"len",
"(",
"pl",
")",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
"{",
"pin",
":=",
"pl",
"[",
"i",
"]",
"\n",
"hash",
"=",
"pin",
".",
"Hash",
"(",
"hash",
")",
"\n",
"}",
"\n",
"return",
"hash",
"\n",
"}"
] | // `computeRootHash` computes the root hash assuming some leaf hash.
// Does not verify the root hash. | [
"computeRootHash",
"computes",
"the",
"root",
"hash",
"assuming",
"some",
"leaf",
"hash",
".",
"Does",
"not",
"verify",
"the",
"root",
"hash",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/proof_path.go#L93-L100 |
6,245 | tendermint/iavl | proof_path.go | Index | func (pl PathToLeaf) Index() (idx int64) {
for i, node := range pl {
if node.Left == nil {
continue
} else if node.Right == nil {
if i < len(pl)-1 {
idx += node.Size - pl[i+1].Size
} else {
idx += node.Size - 1
}
} else {
return -1
}
}
return idx
} | go | func (pl PathToLeaf) Index() (idx int64) {
for i, node := range pl {
if node.Left == nil {
continue
} else if node.Right == nil {
if i < len(pl)-1 {
idx += node.Size - pl[i+1].Size
} else {
idx += node.Size - 1
}
} else {
return -1
}
}
return idx
} | [
"func",
"(",
"pl",
"PathToLeaf",
")",
"Index",
"(",
")",
"(",
"idx",
"int64",
")",
"{",
"for",
"i",
",",
"node",
":=",
"range",
"pl",
"{",
"if",
"node",
".",
"Left",
"==",
"nil",
"{",
"continue",
"\n",
"}",
"else",
"if",
"node",
".",
"Right",
"==",
"nil",
"{",
"if",
"i",
"<",
"len",
"(",
"pl",
")",
"-",
"1",
"{",
"idx",
"+=",
"node",
".",
"Size",
"-",
"pl",
"[",
"i",
"+",
"1",
"]",
".",
"Size",
"\n",
"}",
"else",
"{",
"idx",
"+=",
"node",
".",
"Size",
"-",
"1",
"\n",
"}",
"\n",
"}",
"else",
"{",
"return",
"-",
"1",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"idx",
"\n",
"}"
] | // returns -1 if invalid. | [
"returns",
"-",
"1",
"if",
"invalid",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/proof_path.go#L152-L167 |
6,246 | tendermint/iavl | util.go | PrintTree | func PrintTree(tree *ImmutableTree) {
ndb, root := tree.ndb, tree.root
printNode(ndb, root, 0)
} | go | func PrintTree(tree *ImmutableTree) {
ndb, root := tree.ndb, tree.root
printNode(ndb, root, 0)
} | [
"func",
"PrintTree",
"(",
"tree",
"*",
"ImmutableTree",
")",
"{",
"ndb",
",",
"root",
":=",
"tree",
".",
"ndb",
",",
"tree",
".",
"root",
"\n",
"printNode",
"(",
"ndb",
",",
"root",
",",
"0",
")",
"\n",
"}"
] | // PrintTree prints the whole tree in an indented form. | [
"PrintTree",
"prints",
"the",
"whole",
"tree",
"in",
"an",
"indented",
"form",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/util.go#L10-L13 |
6,247 | tendermint/iavl | node.go | NewNode | func NewNode(key []byte, value []byte, version int64) *Node {
return &Node{
key: key,
value: value,
height: 0,
size: 1,
version: version,
}
} | go | func NewNode(key []byte, value []byte, version int64) *Node {
return &Node{
key: key,
value: value,
height: 0,
size: 1,
version: version,
}
} | [
"func",
"NewNode",
"(",
"key",
"[",
"]",
"byte",
",",
"value",
"[",
"]",
"byte",
",",
"version",
"int64",
")",
"*",
"Node",
"{",
"return",
"&",
"Node",
"{",
"key",
":",
"key",
",",
"value",
":",
"value",
",",
"height",
":",
"0",
",",
"size",
":",
"1",
",",
"version",
":",
"version",
",",
"}",
"\n",
"}"
] | // NewNode returns a new node from a key, value and version. | [
"NewNode",
"returns",
"a",
"new",
"node",
"from",
"a",
"key",
"value",
"and",
"version",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/node.go#L32-L40 |
6,248 | tendermint/iavl | node.go | String | func (node *Node) String() string {
hashstr := "<no hash>"
if len(node.hash) > 0 {
hashstr = fmt.Sprintf("%X", node.hash)
}
return fmt.Sprintf("Node{%s:%s@%d %X;%X}#%s",
cmn.ColoredBytes(node.key, cmn.Green, cmn.Blue),
cmn.ColoredBytes(node.value, cmn.Cyan, cmn.Blue),
node.version,
node.leftHash, node.rightHash,
hashstr)
} | go | func (node *Node) String() string {
hashstr := "<no hash>"
if len(node.hash) > 0 {
hashstr = fmt.Sprintf("%X", node.hash)
}
return fmt.Sprintf("Node{%s:%s@%d %X;%X}#%s",
cmn.ColoredBytes(node.key, cmn.Green, cmn.Blue),
cmn.ColoredBytes(node.value, cmn.Cyan, cmn.Blue),
node.version,
node.leftHash, node.rightHash,
hashstr)
} | [
"func",
"(",
"node",
"*",
"Node",
")",
"String",
"(",
")",
"string",
"{",
"hashstr",
":=",
"\"",
"\"",
"\n",
"if",
"len",
"(",
"node",
".",
"hash",
")",
">",
"0",
"{",
"hashstr",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"node",
".",
"hash",
")",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"cmn",
".",
"ColoredBytes",
"(",
"node",
".",
"key",
",",
"cmn",
".",
"Green",
",",
"cmn",
".",
"Blue",
")",
",",
"cmn",
".",
"ColoredBytes",
"(",
"node",
".",
"value",
",",
"cmn",
".",
"Cyan",
",",
"cmn",
".",
"Blue",
")",
",",
"node",
".",
"version",
",",
"node",
".",
"leftHash",
",",
"node",
".",
"rightHash",
",",
"hashstr",
")",
"\n",
"}"
] | // String returns a string representation of the node. | [
"String",
"returns",
"a",
"string",
"representation",
"of",
"the",
"node",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/node.go#L106-L117 |
6,249 | tendermint/iavl | node.go | clone | func (node *Node) clone(version int64) *Node {
if node.isLeaf() {
panic("Attempt to copy a leaf node")
}
return &Node{
key: node.key,
height: node.height,
version: version,
size: node.size,
hash: nil,
leftHash: node.leftHash,
leftNode: node.leftNode,
rightHash: node.rightHash,
rightNode: node.rightNode,
persisted: false,
}
} | go | func (node *Node) clone(version int64) *Node {
if node.isLeaf() {
panic("Attempt to copy a leaf node")
}
return &Node{
key: node.key,
height: node.height,
version: version,
size: node.size,
hash: nil,
leftHash: node.leftHash,
leftNode: node.leftNode,
rightHash: node.rightHash,
rightNode: node.rightNode,
persisted: false,
}
} | [
"func",
"(",
"node",
"*",
"Node",
")",
"clone",
"(",
"version",
"int64",
")",
"*",
"Node",
"{",
"if",
"node",
".",
"isLeaf",
"(",
")",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"&",
"Node",
"{",
"key",
":",
"node",
".",
"key",
",",
"height",
":",
"node",
".",
"height",
",",
"version",
":",
"version",
",",
"size",
":",
"node",
".",
"size",
",",
"hash",
":",
"nil",
",",
"leftHash",
":",
"node",
".",
"leftHash",
",",
"leftNode",
":",
"node",
".",
"leftNode",
",",
"rightHash",
":",
"node",
".",
"rightHash",
",",
"rightNode",
":",
"node",
".",
"rightNode",
",",
"persisted",
":",
"false",
",",
"}",
"\n",
"}"
] | // clone creates a shallow copy of a node with its hash set to nil. | [
"clone",
"creates",
"a",
"shallow",
"copy",
"of",
"a",
"node",
"with",
"its",
"hash",
"set",
"to",
"nil",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/node.go#L120-L136 |
6,250 | tendermint/iavl | node.go | has | func (node *Node) has(t *ImmutableTree, key []byte) (has bool) {
if bytes.Equal(node.key, key) {
return true
}
if node.isLeaf() {
return false
}
if bytes.Compare(key, node.key) < 0 {
return node.getLeftNode(t).has(t, key)
}
return node.getRightNode(t).has(t, key)
} | go | func (node *Node) has(t *ImmutableTree, key []byte) (has bool) {
if bytes.Equal(node.key, key) {
return true
}
if node.isLeaf() {
return false
}
if bytes.Compare(key, node.key) < 0 {
return node.getLeftNode(t).has(t, key)
}
return node.getRightNode(t).has(t, key)
} | [
"func",
"(",
"node",
"*",
"Node",
")",
"has",
"(",
"t",
"*",
"ImmutableTree",
",",
"key",
"[",
"]",
"byte",
")",
"(",
"has",
"bool",
")",
"{",
"if",
"bytes",
".",
"Equal",
"(",
"node",
".",
"key",
",",
"key",
")",
"{",
"return",
"true",
"\n",
"}",
"\n",
"if",
"node",
".",
"isLeaf",
"(",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"bytes",
".",
"Compare",
"(",
"key",
",",
"node",
".",
"key",
")",
"<",
"0",
"{",
"return",
"node",
".",
"getLeftNode",
"(",
"t",
")",
".",
"has",
"(",
"t",
",",
"key",
")",
"\n",
"}",
"\n",
"return",
"node",
".",
"getRightNode",
"(",
"t",
")",
".",
"has",
"(",
"t",
",",
"key",
")",
"\n",
"}"
] | // Check if the node has a descendant with the given key. | [
"Check",
"if",
"the",
"node",
"has",
"a",
"descendant",
"with",
"the",
"given",
"key",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/node.go#L143-L154 |
6,251 | tendermint/iavl | node.go | get | func (node *Node) get(t *ImmutableTree, key []byte) (index int64, value []byte) {
if node.isLeaf() {
switch bytes.Compare(node.key, key) {
case -1:
return 1, nil
case 1:
return 0, nil
default:
return 0, node.value
}
}
if bytes.Compare(key, node.key) < 0 {
return node.getLeftNode(t).get(t, key)
}
rightNode := node.getRightNode(t)
index, value = rightNode.get(t, key)
index += node.size - rightNode.size
return index, value
} | go | func (node *Node) get(t *ImmutableTree, key []byte) (index int64, value []byte) {
if node.isLeaf() {
switch bytes.Compare(node.key, key) {
case -1:
return 1, nil
case 1:
return 0, nil
default:
return 0, node.value
}
}
if bytes.Compare(key, node.key) < 0 {
return node.getLeftNode(t).get(t, key)
}
rightNode := node.getRightNode(t)
index, value = rightNode.get(t, key)
index += node.size - rightNode.size
return index, value
} | [
"func",
"(",
"node",
"*",
"Node",
")",
"get",
"(",
"t",
"*",
"ImmutableTree",
",",
"key",
"[",
"]",
"byte",
")",
"(",
"index",
"int64",
",",
"value",
"[",
"]",
"byte",
")",
"{",
"if",
"node",
".",
"isLeaf",
"(",
")",
"{",
"switch",
"bytes",
".",
"Compare",
"(",
"node",
".",
"key",
",",
"key",
")",
"{",
"case",
"-",
"1",
":",
"return",
"1",
",",
"nil",
"\n",
"case",
"1",
":",
"return",
"0",
",",
"nil",
"\n",
"default",
":",
"return",
"0",
",",
"node",
".",
"value",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"bytes",
".",
"Compare",
"(",
"key",
",",
"node",
".",
"key",
")",
"<",
"0",
"{",
"return",
"node",
".",
"getLeftNode",
"(",
"t",
")",
".",
"get",
"(",
"t",
",",
"key",
")",
"\n",
"}",
"\n",
"rightNode",
":=",
"node",
".",
"getRightNode",
"(",
"t",
")",
"\n",
"index",
",",
"value",
"=",
"rightNode",
".",
"get",
"(",
"t",
",",
"key",
")",
"\n",
"index",
"+=",
"node",
".",
"size",
"-",
"rightNode",
".",
"size",
"\n",
"return",
"index",
",",
"value",
"\n",
"}"
] | // Get a key under the node. | [
"Get",
"a",
"key",
"under",
"the",
"node",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/node.go#L157-L176 |
6,252 | tendermint/iavl | node.go | _hash | func (node *Node) _hash() []byte {
if node.hash != nil {
return node.hash
}
h := tmhash.New()
buf := new(bytes.Buffer)
if err := node.writeHashBytes(buf); err != nil {
panic(err)
}
h.Write(buf.Bytes())
node.hash = h.Sum(nil)
return node.hash
} | go | func (node *Node) _hash() []byte {
if node.hash != nil {
return node.hash
}
h := tmhash.New()
buf := new(bytes.Buffer)
if err := node.writeHashBytes(buf); err != nil {
panic(err)
}
h.Write(buf.Bytes())
node.hash = h.Sum(nil)
return node.hash
} | [
"func",
"(",
"node",
"*",
"Node",
")",
"_hash",
"(",
")",
"[",
"]",
"byte",
"{",
"if",
"node",
".",
"hash",
"!=",
"nil",
"{",
"return",
"node",
".",
"hash",
"\n",
"}",
"\n\n",
"h",
":=",
"tmhash",
".",
"New",
"(",
")",
"\n",
"buf",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n",
"if",
"err",
":=",
"node",
".",
"writeHashBytes",
"(",
"buf",
")",
";",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"h",
".",
"Write",
"(",
"buf",
".",
"Bytes",
"(",
")",
")",
"\n",
"node",
".",
"hash",
"=",
"h",
".",
"Sum",
"(",
"nil",
")",
"\n\n",
"return",
"node",
".",
"hash",
"\n",
"}"
] | // Computes the hash of the node without computing its descendants. Must be
// called on nodes which have descendant node hashes already computed. | [
"Computes",
"the",
"hash",
"of",
"the",
"node",
"without",
"computing",
"its",
"descendants",
".",
"Must",
"be",
"called",
"on",
"nodes",
"which",
"have",
"descendant",
"node",
"hashes",
"already",
"computed",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/node.go#L197-L211 |
6,253 | tendermint/iavl | node.go | hashWithCount | func (node *Node) hashWithCount() ([]byte, int64) {
if node.hash != nil {
return node.hash, 0
}
h := tmhash.New()
buf := new(bytes.Buffer)
hashCount, err := node.writeHashBytesRecursively(buf)
if err != nil {
panic(err)
}
h.Write(buf.Bytes())
node.hash = h.Sum(nil)
return node.hash, hashCount + 1
} | go | func (node *Node) hashWithCount() ([]byte, int64) {
if node.hash != nil {
return node.hash, 0
}
h := tmhash.New()
buf := new(bytes.Buffer)
hashCount, err := node.writeHashBytesRecursively(buf)
if err != nil {
panic(err)
}
h.Write(buf.Bytes())
node.hash = h.Sum(nil)
return node.hash, hashCount + 1
} | [
"func",
"(",
"node",
"*",
"Node",
")",
"hashWithCount",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"int64",
")",
"{",
"if",
"node",
".",
"hash",
"!=",
"nil",
"{",
"return",
"node",
".",
"hash",
",",
"0",
"\n",
"}",
"\n\n",
"h",
":=",
"tmhash",
".",
"New",
"(",
")",
"\n",
"buf",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n",
"hashCount",
",",
"err",
":=",
"node",
".",
"writeHashBytesRecursively",
"(",
"buf",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"h",
".",
"Write",
"(",
"buf",
".",
"Bytes",
"(",
")",
")",
"\n",
"node",
".",
"hash",
"=",
"h",
".",
"Sum",
"(",
"nil",
")",
"\n\n",
"return",
"node",
".",
"hash",
",",
"hashCount",
"+",
"1",
"\n",
"}"
] | // Hash the node and its descendants recursively. This usually mutates all
// descendant nodes. Returns the node hash and number of nodes hashed. | [
"Hash",
"the",
"node",
"and",
"its",
"descendants",
"recursively",
".",
"This",
"usually",
"mutates",
"all",
"descendant",
"nodes",
".",
"Returns",
"the",
"node",
"hash",
"and",
"number",
"of",
"nodes",
"hashed",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/node.go#L215-L230 |
6,254 | tendermint/iavl | node.go | writeHashBytes | func (node *Node) writeHashBytes(w io.Writer) cmn.Error {
err := amino.EncodeInt8(w, node.height)
if err != nil {
return cmn.ErrorWrap(err, "writing height")
}
err = amino.EncodeVarint(w, node.size)
if err != nil {
return cmn.ErrorWrap(err, "writing size")
}
err = amino.EncodeVarint(w, node.version)
if err != nil {
return cmn.ErrorWrap(err, "writing version")
}
// Key is not written for inner nodes, unlike writeBytes.
if node.isLeaf() {
err = amino.EncodeByteSlice(w, node.key)
if err != nil {
return cmn.ErrorWrap(err, "writing key")
}
// Indirection needed to provide proofs without values.
// (e.g. proofLeafNode.ValueHash)
valueHash := tmhash.Sum(node.value)
err = amino.EncodeByteSlice(w, valueHash)
if err != nil {
return cmn.ErrorWrap(err, "writing value")
}
} else {
if node.leftHash == nil || node.rightHash == nil {
panic("Found an empty child hash")
}
err = amino.EncodeByteSlice(w, node.leftHash)
if err != nil {
return cmn.ErrorWrap(err, "writing left hash")
}
err = amino.EncodeByteSlice(w, node.rightHash)
if err != nil {
return cmn.ErrorWrap(err, "writing right hash")
}
}
return nil
} | go | func (node *Node) writeHashBytes(w io.Writer) cmn.Error {
err := amino.EncodeInt8(w, node.height)
if err != nil {
return cmn.ErrorWrap(err, "writing height")
}
err = amino.EncodeVarint(w, node.size)
if err != nil {
return cmn.ErrorWrap(err, "writing size")
}
err = amino.EncodeVarint(w, node.version)
if err != nil {
return cmn.ErrorWrap(err, "writing version")
}
// Key is not written for inner nodes, unlike writeBytes.
if node.isLeaf() {
err = amino.EncodeByteSlice(w, node.key)
if err != nil {
return cmn.ErrorWrap(err, "writing key")
}
// Indirection needed to provide proofs without values.
// (e.g. proofLeafNode.ValueHash)
valueHash := tmhash.Sum(node.value)
err = amino.EncodeByteSlice(w, valueHash)
if err != nil {
return cmn.ErrorWrap(err, "writing value")
}
} else {
if node.leftHash == nil || node.rightHash == nil {
panic("Found an empty child hash")
}
err = amino.EncodeByteSlice(w, node.leftHash)
if err != nil {
return cmn.ErrorWrap(err, "writing left hash")
}
err = amino.EncodeByteSlice(w, node.rightHash)
if err != nil {
return cmn.ErrorWrap(err, "writing right hash")
}
}
return nil
} | [
"func",
"(",
"node",
"*",
"Node",
")",
"writeHashBytes",
"(",
"w",
"io",
".",
"Writer",
")",
"cmn",
".",
"Error",
"{",
"err",
":=",
"amino",
".",
"EncodeInt8",
"(",
"w",
",",
"node",
".",
"height",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"cmn",
".",
"ErrorWrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"err",
"=",
"amino",
".",
"EncodeVarint",
"(",
"w",
",",
"node",
".",
"size",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"cmn",
".",
"ErrorWrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"err",
"=",
"amino",
".",
"EncodeVarint",
"(",
"w",
",",
"node",
".",
"version",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"cmn",
".",
"ErrorWrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Key is not written for inner nodes, unlike writeBytes.",
"if",
"node",
".",
"isLeaf",
"(",
")",
"{",
"err",
"=",
"amino",
".",
"EncodeByteSlice",
"(",
"w",
",",
"node",
".",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"cmn",
".",
"ErrorWrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"// Indirection needed to provide proofs without values.",
"// (e.g. proofLeafNode.ValueHash)",
"valueHash",
":=",
"tmhash",
".",
"Sum",
"(",
"node",
".",
"value",
")",
"\n",
"err",
"=",
"amino",
".",
"EncodeByteSlice",
"(",
"w",
",",
"valueHash",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"cmn",
".",
"ErrorWrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"if",
"node",
".",
"leftHash",
"==",
"nil",
"||",
"node",
".",
"rightHash",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"err",
"=",
"amino",
".",
"EncodeByteSlice",
"(",
"w",
",",
"node",
".",
"leftHash",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"cmn",
".",
"ErrorWrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"err",
"=",
"amino",
".",
"EncodeByteSlice",
"(",
"w",
",",
"node",
".",
"rightHash",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"cmn",
".",
"ErrorWrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Writes the node's hash to the given io.Writer. This function expects
// child hashes to be already set. | [
"Writes",
"the",
"node",
"s",
"hash",
"to",
"the",
"given",
"io",
".",
"Writer",
".",
"This",
"function",
"expects",
"child",
"hashes",
"to",
"be",
"already",
"set",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/node.go#L234-L277 |
6,255 | tendermint/iavl | node.go | writeHashBytesRecursively | func (node *Node) writeHashBytesRecursively(w io.Writer) (hashCount int64, err cmn.Error) {
if node.leftNode != nil {
leftHash, leftCount := node.leftNode.hashWithCount()
node.leftHash = leftHash
hashCount += leftCount
}
if node.rightNode != nil {
rightHash, rightCount := node.rightNode.hashWithCount()
node.rightHash = rightHash
hashCount += rightCount
}
err = node.writeHashBytes(w)
return
} | go | func (node *Node) writeHashBytesRecursively(w io.Writer) (hashCount int64, err cmn.Error) {
if node.leftNode != nil {
leftHash, leftCount := node.leftNode.hashWithCount()
node.leftHash = leftHash
hashCount += leftCount
}
if node.rightNode != nil {
rightHash, rightCount := node.rightNode.hashWithCount()
node.rightHash = rightHash
hashCount += rightCount
}
err = node.writeHashBytes(w)
return
} | [
"func",
"(",
"node",
"*",
"Node",
")",
"writeHashBytesRecursively",
"(",
"w",
"io",
".",
"Writer",
")",
"(",
"hashCount",
"int64",
",",
"err",
"cmn",
".",
"Error",
")",
"{",
"if",
"node",
".",
"leftNode",
"!=",
"nil",
"{",
"leftHash",
",",
"leftCount",
":=",
"node",
".",
"leftNode",
".",
"hashWithCount",
"(",
")",
"\n",
"node",
".",
"leftHash",
"=",
"leftHash",
"\n",
"hashCount",
"+=",
"leftCount",
"\n",
"}",
"\n",
"if",
"node",
".",
"rightNode",
"!=",
"nil",
"{",
"rightHash",
",",
"rightCount",
":=",
"node",
".",
"rightNode",
".",
"hashWithCount",
"(",
")",
"\n",
"node",
".",
"rightHash",
"=",
"rightHash",
"\n",
"hashCount",
"+=",
"rightCount",
"\n",
"}",
"\n",
"err",
"=",
"node",
".",
"writeHashBytes",
"(",
"w",
")",
"\n\n",
"return",
"\n",
"}"
] | // Writes the node's hash to the given io.Writer.
// This function has the side-effect of calling hashWithCount. | [
"Writes",
"the",
"node",
"s",
"hash",
"to",
"the",
"given",
"io",
".",
"Writer",
".",
"This",
"function",
"has",
"the",
"side",
"-",
"effect",
"of",
"calling",
"hashWithCount",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/node.go#L281-L295 |
6,256 | tendermint/iavl | node.go | writeBytes | func (node *Node) writeBytes(w io.Writer) cmn.Error {
var cause error
cause = amino.EncodeInt8(w, node.height)
if cause != nil {
return cmn.ErrorWrap(cause, "writing height")
}
cause = amino.EncodeVarint(w, node.size)
if cause != nil {
return cmn.ErrorWrap(cause, "writing size")
}
cause = amino.EncodeVarint(w, node.version)
if cause != nil {
return cmn.ErrorWrap(cause, "writing version")
}
// Unlike writeHashBytes, key is written for inner nodes.
cause = amino.EncodeByteSlice(w, node.key)
if cause != nil {
return cmn.ErrorWrap(cause, "writing key")
}
if node.isLeaf() {
cause = amino.EncodeByteSlice(w, node.value)
if cause != nil {
return cmn.ErrorWrap(cause, "writing value")
}
} else {
if node.leftHash == nil {
panic("node.leftHash was nil in writeBytes")
}
cause = amino.EncodeByteSlice(w, node.leftHash)
if cause != nil {
return cmn.ErrorWrap(cause, "writing left hash")
}
if node.rightHash == nil {
panic("node.rightHash was nil in writeBytes")
}
cause = amino.EncodeByteSlice(w, node.rightHash)
if cause != nil {
return cmn.ErrorWrap(cause, "writing right hash")
}
}
return nil
} | go | func (node *Node) writeBytes(w io.Writer) cmn.Error {
var cause error
cause = amino.EncodeInt8(w, node.height)
if cause != nil {
return cmn.ErrorWrap(cause, "writing height")
}
cause = amino.EncodeVarint(w, node.size)
if cause != nil {
return cmn.ErrorWrap(cause, "writing size")
}
cause = amino.EncodeVarint(w, node.version)
if cause != nil {
return cmn.ErrorWrap(cause, "writing version")
}
// Unlike writeHashBytes, key is written for inner nodes.
cause = amino.EncodeByteSlice(w, node.key)
if cause != nil {
return cmn.ErrorWrap(cause, "writing key")
}
if node.isLeaf() {
cause = amino.EncodeByteSlice(w, node.value)
if cause != nil {
return cmn.ErrorWrap(cause, "writing value")
}
} else {
if node.leftHash == nil {
panic("node.leftHash was nil in writeBytes")
}
cause = amino.EncodeByteSlice(w, node.leftHash)
if cause != nil {
return cmn.ErrorWrap(cause, "writing left hash")
}
if node.rightHash == nil {
panic("node.rightHash was nil in writeBytes")
}
cause = amino.EncodeByteSlice(w, node.rightHash)
if cause != nil {
return cmn.ErrorWrap(cause, "writing right hash")
}
}
return nil
} | [
"func",
"(",
"node",
"*",
"Node",
")",
"writeBytes",
"(",
"w",
"io",
".",
"Writer",
")",
"cmn",
".",
"Error",
"{",
"var",
"cause",
"error",
"\n",
"cause",
"=",
"amino",
".",
"EncodeInt8",
"(",
"w",
",",
"node",
".",
"height",
")",
"\n",
"if",
"cause",
"!=",
"nil",
"{",
"return",
"cmn",
".",
"ErrorWrap",
"(",
"cause",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"cause",
"=",
"amino",
".",
"EncodeVarint",
"(",
"w",
",",
"node",
".",
"size",
")",
"\n",
"if",
"cause",
"!=",
"nil",
"{",
"return",
"cmn",
".",
"ErrorWrap",
"(",
"cause",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"cause",
"=",
"amino",
".",
"EncodeVarint",
"(",
"w",
",",
"node",
".",
"version",
")",
"\n",
"if",
"cause",
"!=",
"nil",
"{",
"return",
"cmn",
".",
"ErrorWrap",
"(",
"cause",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Unlike writeHashBytes, key is written for inner nodes.",
"cause",
"=",
"amino",
".",
"EncodeByteSlice",
"(",
"w",
",",
"node",
".",
"key",
")",
"\n",
"if",
"cause",
"!=",
"nil",
"{",
"return",
"cmn",
".",
"ErrorWrap",
"(",
"cause",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"node",
".",
"isLeaf",
"(",
")",
"{",
"cause",
"=",
"amino",
".",
"EncodeByteSlice",
"(",
"w",
",",
"node",
".",
"value",
")",
"\n",
"if",
"cause",
"!=",
"nil",
"{",
"return",
"cmn",
".",
"ErrorWrap",
"(",
"cause",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"if",
"node",
".",
"leftHash",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"cause",
"=",
"amino",
".",
"EncodeByteSlice",
"(",
"w",
",",
"node",
".",
"leftHash",
")",
"\n",
"if",
"cause",
"!=",
"nil",
"{",
"return",
"cmn",
".",
"ErrorWrap",
"(",
"cause",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"node",
".",
"rightHash",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"cause",
"=",
"amino",
".",
"EncodeByteSlice",
"(",
"w",
",",
"node",
".",
"rightHash",
")",
"\n",
"if",
"cause",
"!=",
"nil",
"{",
"return",
"cmn",
".",
"ErrorWrap",
"(",
"cause",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Writes the node as a serialized byte slice to the supplied io.Writer. | [
"Writes",
"the",
"node",
"as",
"a",
"serialized",
"byte",
"slice",
"to",
"the",
"supplied",
"io",
".",
"Writer",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/node.go#L298-L342 |
6,257 | tendermint/iavl | node.go | traverse | func (node *Node) traverse(t *ImmutableTree, ascending bool, cb func(*Node) bool) bool {
return node.traverseInRange(t, nil, nil, ascending, false, 0, func(node *Node, depth uint8) bool {
return cb(node)
})
} | go | func (node *Node) traverse(t *ImmutableTree, ascending bool, cb func(*Node) bool) bool {
return node.traverseInRange(t, nil, nil, ascending, false, 0, func(node *Node, depth uint8) bool {
return cb(node)
})
} | [
"func",
"(",
"node",
"*",
"Node",
")",
"traverse",
"(",
"t",
"*",
"ImmutableTree",
",",
"ascending",
"bool",
",",
"cb",
"func",
"(",
"*",
"Node",
")",
"bool",
")",
"bool",
"{",
"return",
"node",
".",
"traverseInRange",
"(",
"t",
",",
"nil",
",",
"nil",
",",
"ascending",
",",
"false",
",",
"0",
",",
"func",
"(",
"node",
"*",
"Node",
",",
"depth",
"uint8",
")",
"bool",
"{",
"return",
"cb",
"(",
"node",
")",
"\n",
"}",
")",
"\n",
"}"
] | // traverse is a wrapper over traverseInRange when we want the whole tree | [
"traverse",
"is",
"a",
"wrapper",
"over",
"traverseInRange",
"when",
"we",
"want",
"the",
"whole",
"tree"
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/node.go#L369-L373 |
6,258 | tendermint/iavl | node.go | lmd | func (node *Node) lmd(t *ImmutableTree) *Node {
if node.isLeaf() {
return node
}
return node.getLeftNode(t).lmd(t)
} | go | func (node *Node) lmd(t *ImmutableTree) *Node {
if node.isLeaf() {
return node
}
return node.getLeftNode(t).lmd(t)
} | [
"func",
"(",
"node",
"*",
"Node",
")",
"lmd",
"(",
"t",
"*",
"ImmutableTree",
")",
"*",
"Node",
"{",
"if",
"node",
".",
"isLeaf",
"(",
")",
"{",
"return",
"node",
"\n",
"}",
"\n",
"return",
"node",
".",
"getLeftNode",
"(",
"t",
")",
".",
"lmd",
"(",
"t",
")",
"\n",
"}"
] | // Only used in testing... | [
"Only",
"used",
"in",
"testing",
"..."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/node.go#L427-L432 |
6,259 | tendermint/iavl | proof.go | pathToLeaf | func (node *Node) pathToLeaf(t *ImmutableTree, key []byte, path *PathToLeaf) (*Node, error) {
if node.height == 0 {
if bytes.Equal(node.key, key) {
return node, nil
}
return node, cmn.NewError("key does not exist")
}
if bytes.Compare(key, node.key) < 0 {
// left side
pin := proofInnerNode{
Height: node.height,
Size: node.size,
Version: node.version,
Left: nil,
Right: node.getRightNode(t).hash,
}
*path = append(*path, pin)
n, err := node.getLeftNode(t).pathToLeaf(t, key, path)
return n, err
}
// right side
pin := proofInnerNode{
Height: node.height,
Size: node.size,
Version: node.version,
Left: node.getLeftNode(t).hash,
Right: nil,
}
*path = append(*path, pin)
n, err := node.getRightNode(t).pathToLeaf(t, key, path)
return n, err
} | go | func (node *Node) pathToLeaf(t *ImmutableTree, key []byte, path *PathToLeaf) (*Node, error) {
if node.height == 0 {
if bytes.Equal(node.key, key) {
return node, nil
}
return node, cmn.NewError("key does not exist")
}
if bytes.Compare(key, node.key) < 0 {
// left side
pin := proofInnerNode{
Height: node.height,
Size: node.size,
Version: node.version,
Left: nil,
Right: node.getRightNode(t).hash,
}
*path = append(*path, pin)
n, err := node.getLeftNode(t).pathToLeaf(t, key, path)
return n, err
}
// right side
pin := proofInnerNode{
Height: node.height,
Size: node.size,
Version: node.version,
Left: node.getLeftNode(t).hash,
Right: nil,
}
*path = append(*path, pin)
n, err := node.getRightNode(t).pathToLeaf(t, key, path)
return n, err
} | [
"func",
"(",
"node",
"*",
"Node",
")",
"pathToLeaf",
"(",
"t",
"*",
"ImmutableTree",
",",
"key",
"[",
"]",
"byte",
",",
"path",
"*",
"PathToLeaf",
")",
"(",
"*",
"Node",
",",
"error",
")",
"{",
"if",
"node",
".",
"height",
"==",
"0",
"{",
"if",
"bytes",
".",
"Equal",
"(",
"node",
".",
"key",
",",
"key",
")",
"{",
"return",
"node",
",",
"nil",
"\n",
"}",
"\n",
"return",
"node",
",",
"cmn",
".",
"NewError",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"bytes",
".",
"Compare",
"(",
"key",
",",
"node",
".",
"key",
")",
"<",
"0",
"{",
"// left side",
"pin",
":=",
"proofInnerNode",
"{",
"Height",
":",
"node",
".",
"height",
",",
"Size",
":",
"node",
".",
"size",
",",
"Version",
":",
"node",
".",
"version",
",",
"Left",
":",
"nil",
",",
"Right",
":",
"node",
".",
"getRightNode",
"(",
"t",
")",
".",
"hash",
",",
"}",
"\n",
"*",
"path",
"=",
"append",
"(",
"*",
"path",
",",
"pin",
")",
"\n",
"n",
",",
"err",
":=",
"node",
".",
"getLeftNode",
"(",
"t",
")",
".",
"pathToLeaf",
"(",
"t",
",",
"key",
",",
"path",
")",
"\n",
"return",
"n",
",",
"err",
"\n",
"}",
"\n",
"// right side",
"pin",
":=",
"proofInnerNode",
"{",
"Height",
":",
"node",
".",
"height",
",",
"Size",
":",
"node",
".",
"size",
",",
"Version",
":",
"node",
".",
"version",
",",
"Left",
":",
"node",
".",
"getLeftNode",
"(",
"t",
")",
".",
"hash",
",",
"Right",
":",
"nil",
",",
"}",
"\n",
"*",
"path",
"=",
"append",
"(",
"*",
"path",
",",
"pin",
")",
"\n",
"n",
",",
"err",
":=",
"node",
".",
"getRightNode",
"(",
"t",
")",
".",
"pathToLeaf",
"(",
"t",
",",
"key",
",",
"path",
")",
"\n",
"return",
"n",
",",
"err",
"\n",
"}"
] | // pathToLeaf is a helper which recursively constructs the PathToLeaf.
// As an optimization the already constructed path is passed in as an argument
// and is shared among recursive calls. | [
"pathToLeaf",
"is",
"a",
"helper",
"which",
"recursively",
"constructs",
"the",
"PathToLeaf",
".",
"As",
"an",
"optimization",
"the",
"already",
"constructed",
"path",
"is",
"passed",
"in",
"as",
"an",
"argument",
"and",
"is",
"shared",
"among",
"recursive",
"calls",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/proof.go#L151-L183 |
6,260 | tendermint/iavl | proof_range.go | Verify | func (proof *RangeProof) Verify(root []byte) error {
if proof == nil {
return cmn.ErrorWrap(ErrInvalidProof, "proof is nil")
}
err := proof.verify(root)
return err
} | go | func (proof *RangeProof) Verify(root []byte) error {
if proof == nil {
return cmn.ErrorWrap(ErrInvalidProof, "proof is nil")
}
err := proof.verify(root)
return err
} | [
"func",
"(",
"proof",
"*",
"RangeProof",
")",
"Verify",
"(",
"root",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"proof",
"==",
"nil",
"{",
"return",
"cmn",
".",
"ErrorWrap",
"(",
"ErrInvalidProof",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"err",
":=",
"proof",
".",
"verify",
"(",
"root",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // Verify that proof is valid. | [
"Verify",
"that",
"proof",
"is",
"valid",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/proof_range.go#L174-L180 |
6,261 | tendermint/iavl | proof_range.go | ComputeRootHash | func (proof *RangeProof) ComputeRootHash() []byte {
if proof == nil {
return nil
}
rootHash, _ := proof.computeRootHash()
return rootHash
} | go | func (proof *RangeProof) ComputeRootHash() []byte {
if proof == nil {
return nil
}
rootHash, _ := proof.computeRootHash()
return rootHash
} | [
"func",
"(",
"proof",
"*",
"RangeProof",
")",
"ComputeRootHash",
"(",
")",
"[",
"]",
"byte",
"{",
"if",
"proof",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"rootHash",
",",
"_",
":=",
"proof",
".",
"computeRootHash",
"(",
")",
"\n",
"return",
"rootHash",
"\n",
"}"
] | // ComputeRootHash computes the root hash with leaves.
// Returns nil if error or proof is nil.
// Does not verify the root hash. | [
"ComputeRootHash",
"computes",
"the",
"root",
"hash",
"with",
"leaves",
".",
"Returns",
"nil",
"if",
"error",
"or",
"proof",
"is",
"nil",
".",
"Does",
"not",
"verify",
"the",
"root",
"hash",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/proof_range.go#L202-L208 |
6,262 | tendermint/iavl | proof_range.go | GetVersionedWithProof | func (tree *MutableTree) GetVersionedWithProof(key []byte, version int64) ([]byte, *RangeProof, error) {
if tree.versions[version] {
t, err := tree.GetImmutable(version)
if err != nil {
return nil, nil, err
}
return t.GetWithProof(key)
}
return nil, nil, cmn.ErrorWrap(ErrVersionDoesNotExist, "")
} | go | func (tree *MutableTree) GetVersionedWithProof(key []byte, version int64) ([]byte, *RangeProof, error) {
if tree.versions[version] {
t, err := tree.GetImmutable(version)
if err != nil {
return nil, nil, err
}
return t.GetWithProof(key)
}
return nil, nil, cmn.ErrorWrap(ErrVersionDoesNotExist, "")
} | [
"func",
"(",
"tree",
"*",
"MutableTree",
")",
"GetVersionedWithProof",
"(",
"key",
"[",
"]",
"byte",
",",
"version",
"int64",
")",
"(",
"[",
"]",
"byte",
",",
"*",
"RangeProof",
",",
"error",
")",
"{",
"if",
"tree",
".",
"versions",
"[",
"version",
"]",
"{",
"t",
",",
"err",
":=",
"tree",
".",
"GetImmutable",
"(",
"version",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"t",
".",
"GetWithProof",
"(",
"key",
")",
"\n",
"}",
"\n",
"return",
"nil",
",",
"nil",
",",
"cmn",
".",
"ErrorWrap",
"(",
"ErrVersionDoesNotExist",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // GetVersionedWithProof gets the value under the key at the specified version
// if it exists, or returns nil. | [
"GetVersionedWithProof",
"gets",
"the",
"value",
"under",
"the",
"key",
"at",
"the",
"specified",
"version",
"if",
"it",
"exists",
"or",
"returns",
"nil",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/proof_range.go#L471-L481 |
6,263 | tendermint/iavl | immutable_tree.go | NewImmutableTree | func NewImmutableTree(db dbm.DB, cacheSize int) *ImmutableTree {
if db == nil {
// In-memory Tree.
return &ImmutableTree{}
}
return &ImmutableTree{
// NodeDB-backed Tree.
ndb: newNodeDB(db, cacheSize),
}
} | go | func NewImmutableTree(db dbm.DB, cacheSize int) *ImmutableTree {
if db == nil {
// In-memory Tree.
return &ImmutableTree{}
}
return &ImmutableTree{
// NodeDB-backed Tree.
ndb: newNodeDB(db, cacheSize),
}
} | [
"func",
"NewImmutableTree",
"(",
"db",
"dbm",
".",
"DB",
",",
"cacheSize",
"int",
")",
"*",
"ImmutableTree",
"{",
"if",
"db",
"==",
"nil",
"{",
"// In-memory Tree.",
"return",
"&",
"ImmutableTree",
"{",
"}",
"\n",
"}",
"\n",
"return",
"&",
"ImmutableTree",
"{",
"// NodeDB-backed Tree.",
"ndb",
":",
"newNodeDB",
"(",
"db",
",",
"cacheSize",
")",
",",
"}",
"\n",
"}"
] | // NewImmutableTree creates both in-memory and persistent instances | [
"NewImmutableTree",
"creates",
"both",
"in",
"-",
"memory",
"and",
"persistent",
"instances"
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/immutable_tree.go#L20-L29 |
6,264 | tendermint/iavl | immutable_tree.go | String | func (t *ImmutableTree) String() string {
leaves := []string{}
t.Iterate(func(key []byte, val []byte) (stop bool) {
leaves = append(leaves, fmt.Sprintf("%x: %x", key, val))
return false
})
return "Tree{" + strings.Join(leaves, ", ") + "}"
} | go | func (t *ImmutableTree) String() string {
leaves := []string{}
t.Iterate(func(key []byte, val []byte) (stop bool) {
leaves = append(leaves, fmt.Sprintf("%x: %x", key, val))
return false
})
return "Tree{" + strings.Join(leaves, ", ") + "}"
} | [
"func",
"(",
"t",
"*",
"ImmutableTree",
")",
"String",
"(",
")",
"string",
"{",
"leaves",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"t",
".",
"Iterate",
"(",
"func",
"(",
"key",
"[",
"]",
"byte",
",",
"val",
"[",
"]",
"byte",
")",
"(",
"stop",
"bool",
")",
"{",
"leaves",
"=",
"append",
"(",
"leaves",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"key",
",",
"val",
")",
")",
"\n",
"return",
"false",
"\n",
"}",
")",
"\n",
"return",
"\"",
"\"",
"+",
"strings",
".",
"Join",
"(",
"leaves",
",",
"\"",
"\"",
")",
"+",
"\"",
"\"",
"\n",
"}"
] | // String returns a string representation of Tree. | [
"String",
"returns",
"a",
"string",
"representation",
"of",
"Tree",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/immutable_tree.go#L32-L39 |
6,265 | tendermint/iavl | immutable_tree.go | Size | func (t *ImmutableTree) Size() int64 {
if t.root == nil {
return 0
}
return t.root.size
} | go | func (t *ImmutableTree) Size() int64 {
if t.root == nil {
return 0
}
return t.root.size
} | [
"func",
"(",
"t",
"*",
"ImmutableTree",
")",
"Size",
"(",
")",
"int64",
"{",
"if",
"t",
".",
"root",
"==",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n",
"return",
"t",
".",
"root",
".",
"size",
"\n",
"}"
] | // Size returns the number of leaf nodes in the tree. | [
"Size",
"returns",
"the",
"number",
"of",
"leaf",
"nodes",
"in",
"the",
"tree",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/immutable_tree.go#L42-L47 |
6,266 | tendermint/iavl | immutable_tree.go | Height | func (t *ImmutableTree) Height() int8 {
if t.root == nil {
return 0
}
return t.root.height
} | go | func (t *ImmutableTree) Height() int8 {
if t.root == nil {
return 0
}
return t.root.height
} | [
"func",
"(",
"t",
"*",
"ImmutableTree",
")",
"Height",
"(",
")",
"int8",
"{",
"if",
"t",
".",
"root",
"==",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n",
"return",
"t",
".",
"root",
".",
"height",
"\n",
"}"
] | // Height returns the height of the tree. | [
"Height",
"returns",
"the",
"height",
"of",
"the",
"tree",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/immutable_tree.go#L55-L60 |
6,267 | tendermint/iavl | immutable_tree.go | Has | func (t *ImmutableTree) Has(key []byte) bool {
if t.root == nil {
return false
}
return t.root.has(t, key)
} | go | func (t *ImmutableTree) Has(key []byte) bool {
if t.root == nil {
return false
}
return t.root.has(t, key)
} | [
"func",
"(",
"t",
"*",
"ImmutableTree",
")",
"Has",
"(",
"key",
"[",
"]",
"byte",
")",
"bool",
"{",
"if",
"t",
".",
"root",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"t",
".",
"root",
".",
"has",
"(",
"t",
",",
"key",
")",
"\n",
"}"
] | // Has returns whether or not a key exists. | [
"Has",
"returns",
"whether",
"or",
"not",
"a",
"key",
"exists",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/immutable_tree.go#L63-L68 |
6,268 | tendermint/iavl | immutable_tree.go | Hash | func (t *ImmutableTree) Hash() []byte {
if t.root == nil {
return nil
}
hash, _ := t.root.hashWithCount()
return hash
} | go | func (t *ImmutableTree) Hash() []byte {
if t.root == nil {
return nil
}
hash, _ := t.root.hashWithCount()
return hash
} | [
"func",
"(",
"t",
"*",
"ImmutableTree",
")",
"Hash",
"(",
")",
"[",
"]",
"byte",
"{",
"if",
"t",
".",
"root",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"hash",
",",
"_",
":=",
"t",
".",
"root",
".",
"hashWithCount",
"(",
")",
"\n",
"return",
"hash",
"\n",
"}"
] | // Hash returns the root hash. | [
"Hash",
"returns",
"the",
"root",
"hash",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/immutable_tree.go#L71-L77 |
6,269 | tendermint/iavl | immutable_tree.go | hashWithCount | func (t *ImmutableTree) hashWithCount() ([]byte, int64) {
if t.root == nil {
return nil, 0
}
return t.root.hashWithCount()
} | go | func (t *ImmutableTree) hashWithCount() ([]byte, int64) {
if t.root == nil {
return nil, 0
}
return t.root.hashWithCount()
} | [
"func",
"(",
"t",
"*",
"ImmutableTree",
")",
"hashWithCount",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"int64",
")",
"{",
"if",
"t",
".",
"root",
"==",
"nil",
"{",
"return",
"nil",
",",
"0",
"\n",
"}",
"\n",
"return",
"t",
".",
"root",
".",
"hashWithCount",
"(",
")",
"\n",
"}"
] | // hashWithCount returns the root hash and hash count. | [
"hashWithCount",
"returns",
"the",
"root",
"hash",
"and",
"hash",
"count",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/immutable_tree.go#L80-L85 |
6,270 | tendermint/iavl | immutable_tree.go | Get | func (t *ImmutableTree) Get(key []byte) (index int64, value []byte) {
if t.root == nil {
return 0, nil
}
return t.root.get(t, key)
} | go | func (t *ImmutableTree) Get(key []byte) (index int64, value []byte) {
if t.root == nil {
return 0, nil
}
return t.root.get(t, key)
} | [
"func",
"(",
"t",
"*",
"ImmutableTree",
")",
"Get",
"(",
"key",
"[",
"]",
"byte",
")",
"(",
"index",
"int64",
",",
"value",
"[",
"]",
"byte",
")",
"{",
"if",
"t",
".",
"root",
"==",
"nil",
"{",
"return",
"0",
",",
"nil",
"\n",
"}",
"\n",
"return",
"t",
".",
"root",
".",
"get",
"(",
"t",
",",
"key",
")",
"\n",
"}"
] | // Get returns the index and value of the specified key if it exists, or nil
// and the next index, if it doesn't. | [
"Get",
"returns",
"the",
"index",
"and",
"value",
"of",
"the",
"specified",
"key",
"if",
"it",
"exists",
"or",
"nil",
"and",
"the",
"next",
"index",
"if",
"it",
"doesn",
"t",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/immutable_tree.go#L89-L94 |
6,271 | tendermint/iavl | immutable_tree.go | GetByIndex | func (t *ImmutableTree) GetByIndex(index int64) (key []byte, value []byte) {
if t.root == nil {
return nil, nil
}
return t.root.getByIndex(t, index)
} | go | func (t *ImmutableTree) GetByIndex(index int64) (key []byte, value []byte) {
if t.root == nil {
return nil, nil
}
return t.root.getByIndex(t, index)
} | [
"func",
"(",
"t",
"*",
"ImmutableTree",
")",
"GetByIndex",
"(",
"index",
"int64",
")",
"(",
"key",
"[",
"]",
"byte",
",",
"value",
"[",
"]",
"byte",
")",
"{",
"if",
"t",
".",
"root",
"==",
"nil",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"return",
"t",
".",
"root",
".",
"getByIndex",
"(",
"t",
",",
"index",
")",
"\n",
"}"
] | // GetByIndex gets the key and value at the specified index. | [
"GetByIndex",
"gets",
"the",
"key",
"and",
"value",
"at",
"the",
"specified",
"index",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/immutable_tree.go#L97-L102 |
6,272 | tendermint/iavl | immutable_tree.go | Iterate | func (t *ImmutableTree) Iterate(fn func(key []byte, value []byte) bool) (stopped bool) {
if t.root == nil {
return false
}
return t.root.traverse(t, true, func(node *Node) bool {
if node.height == 0 {
return fn(node.key, node.value)
}
return false
})
} | go | func (t *ImmutableTree) Iterate(fn func(key []byte, value []byte) bool) (stopped bool) {
if t.root == nil {
return false
}
return t.root.traverse(t, true, func(node *Node) bool {
if node.height == 0 {
return fn(node.key, node.value)
}
return false
})
} | [
"func",
"(",
"t",
"*",
"ImmutableTree",
")",
"Iterate",
"(",
"fn",
"func",
"(",
"key",
"[",
"]",
"byte",
",",
"value",
"[",
"]",
"byte",
")",
"bool",
")",
"(",
"stopped",
"bool",
")",
"{",
"if",
"t",
".",
"root",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"t",
".",
"root",
".",
"traverse",
"(",
"t",
",",
"true",
",",
"func",
"(",
"node",
"*",
"Node",
")",
"bool",
"{",
"if",
"node",
".",
"height",
"==",
"0",
"{",
"return",
"fn",
"(",
"node",
".",
"key",
",",
"node",
".",
"value",
")",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}",
")",
"\n",
"}"
] | // Iterate iterates over all keys of the tree, in order. | [
"Iterate",
"iterates",
"over",
"all",
"keys",
"of",
"the",
"tree",
"in",
"order",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/immutable_tree.go#L105-L115 |
6,273 | tendermint/iavl | immutable_tree.go | clone | func (t *ImmutableTree) clone() *ImmutableTree {
return &ImmutableTree{
root: t.root,
ndb: t.ndb,
version: t.version,
}
} | go | func (t *ImmutableTree) clone() *ImmutableTree {
return &ImmutableTree{
root: t.root,
ndb: t.ndb,
version: t.version,
}
} | [
"func",
"(",
"t",
"*",
"ImmutableTree",
")",
"clone",
"(",
")",
"*",
"ImmutableTree",
"{",
"return",
"&",
"ImmutableTree",
"{",
"root",
":",
"t",
".",
"root",
",",
"ndb",
":",
"t",
".",
"ndb",
",",
"version",
":",
"t",
".",
"version",
",",
"}",
"\n",
"}"
] | // Clone creates a clone of the tree.
// Used internally by MutableTree. | [
"Clone",
"creates",
"a",
"clone",
"of",
"the",
"tree",
".",
"Used",
"internally",
"by",
"MutableTree",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/immutable_tree.go#L147-L153 |
6,274 | tendermint/iavl | immutable_tree.go | nodeSize | func (t *ImmutableTree) nodeSize() int {
size := 0
t.root.traverse(t, true, func(n *Node) bool {
size++
return false
})
return size
} | go | func (t *ImmutableTree) nodeSize() int {
size := 0
t.root.traverse(t, true, func(n *Node) bool {
size++
return false
})
return size
} | [
"func",
"(",
"t",
"*",
"ImmutableTree",
")",
"nodeSize",
"(",
")",
"int",
"{",
"size",
":=",
"0",
"\n",
"t",
".",
"root",
".",
"traverse",
"(",
"t",
",",
"true",
",",
"func",
"(",
"n",
"*",
"Node",
")",
"bool",
"{",
"size",
"++",
"\n",
"return",
"false",
"\n",
"}",
")",
"\n",
"return",
"size",
"\n",
"}"
] | // nodeSize is like Size, but includes inner nodes too. | [
"nodeSize",
"is",
"like",
"Size",
"but",
"includes",
"inner",
"nodes",
"too",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/immutable_tree.go#L156-L163 |
6,275 | tendermint/iavl | mutable_tree.go | NewMutableTree | func NewMutableTree(db dbm.DB, cacheSize int) *MutableTree {
ndb := newNodeDB(db, cacheSize)
head := &ImmutableTree{ndb: ndb}
return &MutableTree{
ImmutableTree: head,
lastSaved: head.clone(),
orphans: map[string]int64{},
versions: map[int64]bool{},
ndb: ndb,
}
} | go | func NewMutableTree(db dbm.DB, cacheSize int) *MutableTree {
ndb := newNodeDB(db, cacheSize)
head := &ImmutableTree{ndb: ndb}
return &MutableTree{
ImmutableTree: head,
lastSaved: head.clone(),
orphans: map[string]int64{},
versions: map[int64]bool{},
ndb: ndb,
}
} | [
"func",
"NewMutableTree",
"(",
"db",
"dbm",
".",
"DB",
",",
"cacheSize",
"int",
")",
"*",
"MutableTree",
"{",
"ndb",
":=",
"newNodeDB",
"(",
"db",
",",
"cacheSize",
")",
"\n",
"head",
":=",
"&",
"ImmutableTree",
"{",
"ndb",
":",
"ndb",
"}",
"\n\n",
"return",
"&",
"MutableTree",
"{",
"ImmutableTree",
":",
"head",
",",
"lastSaved",
":",
"head",
".",
"clone",
"(",
")",
",",
"orphans",
":",
"map",
"[",
"string",
"]",
"int64",
"{",
"}",
",",
"versions",
":",
"map",
"[",
"int64",
"]",
"bool",
"{",
"}",
",",
"ndb",
":",
"ndb",
",",
"}",
"\n",
"}"
] | // NewMutableTree returns a new tree with the specified cache size and datastore. | [
"NewMutableTree",
"returns",
"a",
"new",
"tree",
"with",
"the",
"specified",
"cache",
"size",
"and",
"datastore",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/mutable_tree.go#L24-L35 |
6,276 | tendermint/iavl | mutable_tree.go | Hash | func (tree *MutableTree) Hash() []byte {
if tree.version > 0 {
return tree.lastSaved.Hash()
}
return nil
} | go | func (tree *MutableTree) Hash() []byte {
if tree.version > 0 {
return tree.lastSaved.Hash()
}
return nil
} | [
"func",
"(",
"tree",
"*",
"MutableTree",
")",
"Hash",
"(",
")",
"[",
"]",
"byte",
"{",
"if",
"tree",
".",
"version",
">",
"0",
"{",
"return",
"tree",
".",
"lastSaved",
".",
"Hash",
"(",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Hash returns the hash of the latest saved version of the tree, as returned
// by SaveVersion. If no versions have been saved, Hash returns nil. | [
"Hash",
"returns",
"the",
"hash",
"of",
"the",
"latest",
"saved",
"version",
"of",
"the",
"tree",
"as",
"returned",
"by",
"SaveVersion",
".",
"If",
"no",
"versions",
"have",
"been",
"saved",
"Hash",
"returns",
"nil",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/mutable_tree.go#L50-L55 |
6,277 | tendermint/iavl | mutable_tree.go | Set | func (tree *MutableTree) Set(key, value []byte) bool {
orphaned, updated := tree.set(key, value)
tree.addOrphans(orphaned)
return updated
} | go | func (tree *MutableTree) Set(key, value []byte) bool {
orphaned, updated := tree.set(key, value)
tree.addOrphans(orphaned)
return updated
} | [
"func",
"(",
"tree",
"*",
"MutableTree",
")",
"Set",
"(",
"key",
",",
"value",
"[",
"]",
"byte",
")",
"bool",
"{",
"orphaned",
",",
"updated",
":=",
"tree",
".",
"set",
"(",
"key",
",",
"value",
")",
"\n",
"tree",
".",
"addOrphans",
"(",
"orphaned",
")",
"\n",
"return",
"updated",
"\n",
"}"
] | // Set sets a key in the working tree. Nil values are not supported. | [
"Set",
"sets",
"a",
"key",
"in",
"the",
"working",
"tree",
".",
"Nil",
"values",
"are",
"not",
"supported",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/mutable_tree.go#L68-L72 |
6,278 | tendermint/iavl | mutable_tree.go | Remove | func (tree *MutableTree) Remove(key []byte) ([]byte, bool) {
val, orphaned, removed := tree.remove(key)
tree.addOrphans(orphaned)
return val, removed
} | go | func (tree *MutableTree) Remove(key []byte) ([]byte, bool) {
val, orphaned, removed := tree.remove(key)
tree.addOrphans(orphaned)
return val, removed
} | [
"func",
"(",
"tree",
"*",
"MutableTree",
")",
"Remove",
"(",
"key",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"bool",
")",
"{",
"val",
",",
"orphaned",
",",
"removed",
":=",
"tree",
".",
"remove",
"(",
"key",
")",
"\n",
"tree",
".",
"addOrphans",
"(",
"orphaned",
")",
"\n",
"return",
"val",
",",
"removed",
"\n",
"}"
] | // Remove removes a key from the working tree. | [
"Remove",
"removes",
"a",
"key",
"from",
"the",
"working",
"tree",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/mutable_tree.go#L141-L145 |
6,279 | tendermint/iavl | mutable_tree.go | remove | func (tree *MutableTree) remove(key []byte) (value []byte, orphans []*Node, removed bool) {
if tree.root == nil {
return nil, nil, false
}
newRootHash, newRoot, _, value, orphaned := tree.recursiveRemove(tree.root, key)
if len(orphaned) == 0 {
return nil, nil, false
}
if newRoot == nil && newRootHash != nil {
tree.root = tree.ndb.GetNode(newRootHash)
} else {
tree.root = newRoot
}
return value, orphaned, true
} | go | func (tree *MutableTree) remove(key []byte) (value []byte, orphans []*Node, removed bool) {
if tree.root == nil {
return nil, nil, false
}
newRootHash, newRoot, _, value, orphaned := tree.recursiveRemove(tree.root, key)
if len(orphaned) == 0 {
return nil, nil, false
}
if newRoot == nil && newRootHash != nil {
tree.root = tree.ndb.GetNode(newRootHash)
} else {
tree.root = newRoot
}
return value, orphaned, true
} | [
"func",
"(",
"tree",
"*",
"MutableTree",
")",
"remove",
"(",
"key",
"[",
"]",
"byte",
")",
"(",
"value",
"[",
"]",
"byte",
",",
"orphans",
"[",
"]",
"*",
"Node",
",",
"removed",
"bool",
")",
"{",
"if",
"tree",
".",
"root",
"==",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"false",
"\n",
"}",
"\n",
"newRootHash",
",",
"newRoot",
",",
"_",
",",
"value",
",",
"orphaned",
":=",
"tree",
".",
"recursiveRemove",
"(",
"tree",
".",
"root",
",",
"key",
")",
"\n",
"if",
"len",
"(",
"orphaned",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"nil",
",",
"false",
"\n",
"}",
"\n\n",
"if",
"newRoot",
"==",
"nil",
"&&",
"newRootHash",
"!=",
"nil",
"{",
"tree",
".",
"root",
"=",
"tree",
".",
"ndb",
".",
"GetNode",
"(",
"newRootHash",
")",
"\n",
"}",
"else",
"{",
"tree",
".",
"root",
"=",
"newRoot",
"\n",
"}",
"\n",
"return",
"value",
",",
"orphaned",
",",
"true",
"\n",
"}"
] | // remove tries to remove a key from the tree and if removed, returns its
// value, nodes orphaned and 'true'. | [
"remove",
"tries",
"to",
"remove",
"a",
"key",
"from",
"the",
"tree",
"and",
"if",
"removed",
"returns",
"its",
"value",
"nodes",
"orphaned",
"and",
"true",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/mutable_tree.go#L149-L164 |
6,280 | tendermint/iavl | mutable_tree.go | LoadVersion | func (tree *MutableTree) LoadVersion(targetVersion int64) (int64, error) {
roots, err := tree.ndb.getRoots()
if err != nil {
return 0, err
}
if len(roots) == 0 {
return 0, nil
}
latestVersion := int64(0)
var latestRoot []byte
for version, r := range roots {
tree.versions[version] = true
if version > latestVersion &&
(targetVersion == 0 || version <= targetVersion) {
latestVersion = version
latestRoot = r
}
}
if !(targetVersion == 0 || latestVersion == targetVersion) {
return latestVersion, fmt.Errorf("wanted to load target %v but only found up to %v",
targetVersion, latestVersion)
}
t := &ImmutableTree{
ndb: tree.ndb,
version: latestVersion,
}
if len(latestRoot) != 0 {
t.root = tree.ndb.GetNode(latestRoot)
}
tree.orphans = map[string]int64{}
tree.ImmutableTree = t
tree.lastSaved = t.clone()
return latestVersion, nil
} | go | func (tree *MutableTree) LoadVersion(targetVersion int64) (int64, error) {
roots, err := tree.ndb.getRoots()
if err != nil {
return 0, err
}
if len(roots) == 0 {
return 0, nil
}
latestVersion := int64(0)
var latestRoot []byte
for version, r := range roots {
tree.versions[version] = true
if version > latestVersion &&
(targetVersion == 0 || version <= targetVersion) {
latestVersion = version
latestRoot = r
}
}
if !(targetVersion == 0 || latestVersion == targetVersion) {
return latestVersion, fmt.Errorf("wanted to load target %v but only found up to %v",
targetVersion, latestVersion)
}
t := &ImmutableTree{
ndb: tree.ndb,
version: latestVersion,
}
if len(latestRoot) != 0 {
t.root = tree.ndb.GetNode(latestRoot)
}
tree.orphans = map[string]int64{}
tree.ImmutableTree = t
tree.lastSaved = t.clone()
return latestVersion, nil
} | [
"func",
"(",
"tree",
"*",
"MutableTree",
")",
"LoadVersion",
"(",
"targetVersion",
"int64",
")",
"(",
"int64",
",",
"error",
")",
"{",
"roots",
",",
"err",
":=",
"tree",
".",
"ndb",
".",
"getRoots",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"roots",
")",
"==",
"0",
"{",
"return",
"0",
",",
"nil",
"\n",
"}",
"\n",
"latestVersion",
":=",
"int64",
"(",
"0",
")",
"\n",
"var",
"latestRoot",
"[",
"]",
"byte",
"\n",
"for",
"version",
",",
"r",
":=",
"range",
"roots",
"{",
"tree",
".",
"versions",
"[",
"version",
"]",
"=",
"true",
"\n",
"if",
"version",
">",
"latestVersion",
"&&",
"(",
"targetVersion",
"==",
"0",
"||",
"version",
"<=",
"targetVersion",
")",
"{",
"latestVersion",
"=",
"version",
"\n",
"latestRoot",
"=",
"r",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"!",
"(",
"targetVersion",
"==",
"0",
"||",
"latestVersion",
"==",
"targetVersion",
")",
"{",
"return",
"latestVersion",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"targetVersion",
",",
"latestVersion",
")",
"\n",
"}",
"\n\n",
"t",
":=",
"&",
"ImmutableTree",
"{",
"ndb",
":",
"tree",
".",
"ndb",
",",
"version",
":",
"latestVersion",
",",
"}",
"\n",
"if",
"len",
"(",
"latestRoot",
")",
"!=",
"0",
"{",
"t",
".",
"root",
"=",
"tree",
".",
"ndb",
".",
"GetNode",
"(",
"latestRoot",
")",
"\n",
"}",
"\n\n",
"tree",
".",
"orphans",
"=",
"map",
"[",
"string",
"]",
"int64",
"{",
"}",
"\n",
"tree",
".",
"ImmutableTree",
"=",
"t",
"\n",
"tree",
".",
"lastSaved",
"=",
"t",
".",
"clone",
"(",
")",
"\n",
"return",
"latestVersion",
",",
"nil",
"\n",
"}"
] | // Returns the version number of the latest version found | [
"Returns",
"the",
"version",
"number",
"of",
"the",
"latest",
"version",
"found"
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/mutable_tree.go#L228-L264 |
6,281 | tendermint/iavl | mutable_tree.go | LoadVersionForOverwriting | func (tree *MutableTree) LoadVersionForOverwriting(targetVersion int64) (int64, error) {
latestVersion, err := tree.LoadVersion(targetVersion)
if err != nil {
return latestVersion, err
}
tree.deleteVersionsFrom(targetVersion+1)
return targetVersion, nil
} | go | func (tree *MutableTree) LoadVersionForOverwriting(targetVersion int64) (int64, error) {
latestVersion, err := tree.LoadVersion(targetVersion)
if err != nil {
return latestVersion, err
}
tree.deleteVersionsFrom(targetVersion+1)
return targetVersion, nil
} | [
"func",
"(",
"tree",
"*",
"MutableTree",
")",
"LoadVersionForOverwriting",
"(",
"targetVersion",
"int64",
")",
"(",
"int64",
",",
"error",
")",
"{",
"latestVersion",
",",
"err",
":=",
"tree",
".",
"LoadVersion",
"(",
"targetVersion",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"latestVersion",
",",
"err",
"\n",
"}",
"\n",
"tree",
".",
"deleteVersionsFrom",
"(",
"targetVersion",
"+",
"1",
")",
"\n",
"return",
"targetVersion",
",",
"nil",
"\n",
"}"
] | // LoadVersionOverwrite returns the version number of targetVersion.
// Higher versions' data will be deleted. | [
"LoadVersionOverwrite",
"returns",
"the",
"version",
"number",
"of",
"targetVersion",
".",
"Higher",
"versions",
"data",
"will",
"be",
"deleted",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/mutable_tree.go#L268-L275 |
6,282 | tendermint/iavl | mutable_tree.go | GetImmutable | func (tree *MutableTree) GetImmutable(version int64) (*ImmutableTree, error) {
rootHash := tree.ndb.getRoot(version)
if rootHash == nil {
return nil, ErrVersionDoesNotExist
} else if len(rootHash) == 0 {
return &ImmutableTree{
ndb: tree.ndb,
version: version,
}, nil
}
return &ImmutableTree{
root: tree.ndb.GetNode(rootHash),
ndb: tree.ndb,
version: version,
}, nil
} | go | func (tree *MutableTree) GetImmutable(version int64) (*ImmutableTree, error) {
rootHash := tree.ndb.getRoot(version)
if rootHash == nil {
return nil, ErrVersionDoesNotExist
} else if len(rootHash) == 0 {
return &ImmutableTree{
ndb: tree.ndb,
version: version,
}, nil
}
return &ImmutableTree{
root: tree.ndb.GetNode(rootHash),
ndb: tree.ndb,
version: version,
}, nil
} | [
"func",
"(",
"tree",
"*",
"MutableTree",
")",
"GetImmutable",
"(",
"version",
"int64",
")",
"(",
"*",
"ImmutableTree",
",",
"error",
")",
"{",
"rootHash",
":=",
"tree",
".",
"ndb",
".",
"getRoot",
"(",
"version",
")",
"\n",
"if",
"rootHash",
"==",
"nil",
"{",
"return",
"nil",
",",
"ErrVersionDoesNotExist",
"\n",
"}",
"else",
"if",
"len",
"(",
"rootHash",
")",
"==",
"0",
"{",
"return",
"&",
"ImmutableTree",
"{",
"ndb",
":",
"tree",
".",
"ndb",
",",
"version",
":",
"version",
",",
"}",
",",
"nil",
"\n",
"}",
"\n",
"return",
"&",
"ImmutableTree",
"{",
"root",
":",
"tree",
".",
"ndb",
".",
"GetNode",
"(",
"rootHash",
")",
",",
"ndb",
":",
"tree",
".",
"ndb",
",",
"version",
":",
"version",
",",
"}",
",",
"nil",
"\n",
"}"
] | // GetImmutable loads an ImmutableTree at a given version for querying | [
"GetImmutable",
"loads",
"an",
"ImmutableTree",
"at",
"a",
"given",
"version",
"for",
"querying"
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/mutable_tree.go#L278-L293 |
6,283 | tendermint/iavl | mutable_tree.go | Rollback | func (tree *MutableTree) Rollback() {
if tree.version > 0 {
tree.ImmutableTree = tree.lastSaved.clone()
} else {
tree.ImmutableTree = &ImmutableTree{ndb: tree.ndb, version: 0}
}
tree.orphans = map[string]int64{}
} | go | func (tree *MutableTree) Rollback() {
if tree.version > 0 {
tree.ImmutableTree = tree.lastSaved.clone()
} else {
tree.ImmutableTree = &ImmutableTree{ndb: tree.ndb, version: 0}
}
tree.orphans = map[string]int64{}
} | [
"func",
"(",
"tree",
"*",
"MutableTree",
")",
"Rollback",
"(",
")",
"{",
"if",
"tree",
".",
"version",
">",
"0",
"{",
"tree",
".",
"ImmutableTree",
"=",
"tree",
".",
"lastSaved",
".",
"clone",
"(",
")",
"\n",
"}",
"else",
"{",
"tree",
".",
"ImmutableTree",
"=",
"&",
"ImmutableTree",
"{",
"ndb",
":",
"tree",
".",
"ndb",
",",
"version",
":",
"0",
"}",
"\n",
"}",
"\n",
"tree",
".",
"orphans",
"=",
"map",
"[",
"string",
"]",
"int64",
"{",
"}",
"\n",
"}"
] | // Rollback resets the working tree to the latest saved version, discarding
// any unsaved modifications. | [
"Rollback",
"resets",
"the",
"working",
"tree",
"to",
"the",
"latest",
"saved",
"version",
"discarding",
"any",
"unsaved",
"modifications",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/mutable_tree.go#L297-L304 |
6,284 | tendermint/iavl | mutable_tree.go | GetVersioned | func (tree *MutableTree) GetVersioned(key []byte, version int64) (
index int64, value []byte,
) {
if tree.versions[version] {
t, err := tree.GetImmutable(version)
if err != nil {
return -1, nil
}
return t.Get(key)
}
return -1, nil
} | go | func (tree *MutableTree) GetVersioned(key []byte, version int64) (
index int64, value []byte,
) {
if tree.versions[version] {
t, err := tree.GetImmutable(version)
if err != nil {
return -1, nil
}
return t.Get(key)
}
return -1, nil
} | [
"func",
"(",
"tree",
"*",
"MutableTree",
")",
"GetVersioned",
"(",
"key",
"[",
"]",
"byte",
",",
"version",
"int64",
")",
"(",
"index",
"int64",
",",
"value",
"[",
"]",
"byte",
",",
")",
"{",
"if",
"tree",
".",
"versions",
"[",
"version",
"]",
"{",
"t",
",",
"err",
":=",
"tree",
".",
"GetImmutable",
"(",
"version",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"-",
"1",
",",
"nil",
"\n",
"}",
"\n",
"return",
"t",
".",
"Get",
"(",
"key",
")",
"\n",
"}",
"\n",
"return",
"-",
"1",
",",
"nil",
"\n",
"}"
] | // GetVersioned gets the value at the specified key and version. | [
"GetVersioned",
"gets",
"the",
"value",
"at",
"the",
"specified",
"key",
"and",
"version",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/mutable_tree.go#L307-L318 |
6,285 | tendermint/iavl | mutable_tree.go | SaveVersion | func (tree *MutableTree) SaveVersion() ([]byte, int64, error) {
version := tree.version + 1
if tree.versions[version] {
//version already exists, throw an error if attempting to overwrite
// Same hash means idempotent. Return success.
existingHash := tree.ndb.getRoot(version)
var newHash = tree.WorkingHash()
if bytes.Equal(existingHash, newHash) {
tree.version = version
tree.ImmutableTree = tree.ImmutableTree.clone()
tree.lastSaved = tree.ImmutableTree.clone()
tree.orphans = map[string]int64{}
return existingHash, version, nil
}
return nil, version, fmt.Errorf("version %d was already saved to different hash %X (existing hash %X)",
version, newHash, existingHash)
}
if tree.root == nil {
// There can still be orphans, for example if the root is the node being
// removed.
debug("SAVE EMPTY TREE %v\n", version)
tree.ndb.SaveOrphans(version, tree.orphans)
tree.ndb.SaveEmptyRoot(version)
} else {
debug("SAVE TREE %v\n", version)
// Save the current tree.
tree.ndb.SaveBranch(tree.root)
tree.ndb.SaveOrphans(version, tree.orphans)
tree.ndb.SaveRoot(tree.root, version)
}
tree.ndb.Commit()
tree.version = version
tree.versions[version] = true
// Set new working tree.
tree.ImmutableTree = tree.ImmutableTree.clone()
tree.lastSaved = tree.ImmutableTree.clone()
tree.orphans = map[string]int64{}
return tree.Hash(), version, nil
} | go | func (tree *MutableTree) SaveVersion() ([]byte, int64, error) {
version := tree.version + 1
if tree.versions[version] {
//version already exists, throw an error if attempting to overwrite
// Same hash means idempotent. Return success.
existingHash := tree.ndb.getRoot(version)
var newHash = tree.WorkingHash()
if bytes.Equal(existingHash, newHash) {
tree.version = version
tree.ImmutableTree = tree.ImmutableTree.clone()
tree.lastSaved = tree.ImmutableTree.clone()
tree.orphans = map[string]int64{}
return existingHash, version, nil
}
return nil, version, fmt.Errorf("version %d was already saved to different hash %X (existing hash %X)",
version, newHash, existingHash)
}
if tree.root == nil {
// There can still be orphans, for example if the root is the node being
// removed.
debug("SAVE EMPTY TREE %v\n", version)
tree.ndb.SaveOrphans(version, tree.orphans)
tree.ndb.SaveEmptyRoot(version)
} else {
debug("SAVE TREE %v\n", version)
// Save the current tree.
tree.ndb.SaveBranch(tree.root)
tree.ndb.SaveOrphans(version, tree.orphans)
tree.ndb.SaveRoot(tree.root, version)
}
tree.ndb.Commit()
tree.version = version
tree.versions[version] = true
// Set new working tree.
tree.ImmutableTree = tree.ImmutableTree.clone()
tree.lastSaved = tree.ImmutableTree.clone()
tree.orphans = map[string]int64{}
return tree.Hash(), version, nil
} | [
"func",
"(",
"tree",
"*",
"MutableTree",
")",
"SaveVersion",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"int64",
",",
"error",
")",
"{",
"version",
":=",
"tree",
".",
"version",
"+",
"1",
"\n\n",
"if",
"tree",
".",
"versions",
"[",
"version",
"]",
"{",
"//version already exists, throw an error if attempting to overwrite",
"// Same hash means idempotent. Return success.",
"existingHash",
":=",
"tree",
".",
"ndb",
".",
"getRoot",
"(",
"version",
")",
"\n",
"var",
"newHash",
"=",
"tree",
".",
"WorkingHash",
"(",
")",
"\n",
"if",
"bytes",
".",
"Equal",
"(",
"existingHash",
",",
"newHash",
")",
"{",
"tree",
".",
"version",
"=",
"version",
"\n",
"tree",
".",
"ImmutableTree",
"=",
"tree",
".",
"ImmutableTree",
".",
"clone",
"(",
")",
"\n",
"tree",
".",
"lastSaved",
"=",
"tree",
".",
"ImmutableTree",
".",
"clone",
"(",
")",
"\n",
"tree",
".",
"orphans",
"=",
"map",
"[",
"string",
"]",
"int64",
"{",
"}",
"\n",
"return",
"existingHash",
",",
"version",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"version",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"version",
",",
"newHash",
",",
"existingHash",
")",
"\n",
"}",
"\n\n",
"if",
"tree",
".",
"root",
"==",
"nil",
"{",
"// There can still be orphans, for example if the root is the node being",
"// removed.",
"debug",
"(",
"\"",
"\\n",
"\"",
",",
"version",
")",
"\n",
"tree",
".",
"ndb",
".",
"SaveOrphans",
"(",
"version",
",",
"tree",
".",
"orphans",
")",
"\n",
"tree",
".",
"ndb",
".",
"SaveEmptyRoot",
"(",
"version",
")",
"\n",
"}",
"else",
"{",
"debug",
"(",
"\"",
"\\n",
"\"",
",",
"version",
")",
"\n",
"// Save the current tree.",
"tree",
".",
"ndb",
".",
"SaveBranch",
"(",
"tree",
".",
"root",
")",
"\n",
"tree",
".",
"ndb",
".",
"SaveOrphans",
"(",
"version",
",",
"tree",
".",
"orphans",
")",
"\n",
"tree",
".",
"ndb",
".",
"SaveRoot",
"(",
"tree",
".",
"root",
",",
"version",
")",
"\n",
"}",
"\n",
"tree",
".",
"ndb",
".",
"Commit",
"(",
")",
"\n",
"tree",
".",
"version",
"=",
"version",
"\n",
"tree",
".",
"versions",
"[",
"version",
"]",
"=",
"true",
"\n\n",
"// Set new working tree.",
"tree",
".",
"ImmutableTree",
"=",
"tree",
".",
"ImmutableTree",
".",
"clone",
"(",
")",
"\n",
"tree",
".",
"lastSaved",
"=",
"tree",
".",
"ImmutableTree",
".",
"clone",
"(",
")",
"\n",
"tree",
".",
"orphans",
"=",
"map",
"[",
"string",
"]",
"int64",
"{",
"}",
"\n\n",
"return",
"tree",
".",
"Hash",
"(",
")",
",",
"version",
",",
"nil",
"\n",
"}"
] | // SaveVersion saves a new tree version to disk, based on the current state of
// the tree. Returns the hash and new version number. | [
"SaveVersion",
"saves",
"a",
"new",
"tree",
"version",
"to",
"disk",
"based",
"on",
"the",
"current",
"state",
"of",
"the",
"tree",
".",
"Returns",
"the",
"hash",
"and",
"new",
"version",
"number",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/mutable_tree.go#L322-L364 |
6,286 | tendermint/iavl | mutable_tree.go | DeleteVersion | func (tree *MutableTree) DeleteVersion(version int64) error {
if version == 0 {
return cmn.NewError("version must be greater than 0")
}
if version == tree.version {
return cmn.NewError("cannot delete latest saved version (%d)", version)
}
if _, ok := tree.versions[version]; !ok {
return cmn.ErrorWrap(ErrVersionDoesNotExist, "")
}
tree.ndb.DeleteVersion(version, true)
tree.ndb.Commit()
delete(tree.versions, version)
return nil
} | go | func (tree *MutableTree) DeleteVersion(version int64) error {
if version == 0 {
return cmn.NewError("version must be greater than 0")
}
if version == tree.version {
return cmn.NewError("cannot delete latest saved version (%d)", version)
}
if _, ok := tree.versions[version]; !ok {
return cmn.ErrorWrap(ErrVersionDoesNotExist, "")
}
tree.ndb.DeleteVersion(version, true)
tree.ndb.Commit()
delete(tree.versions, version)
return nil
} | [
"func",
"(",
"tree",
"*",
"MutableTree",
")",
"DeleteVersion",
"(",
"version",
"int64",
")",
"error",
"{",
"if",
"version",
"==",
"0",
"{",
"return",
"cmn",
".",
"NewError",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"version",
"==",
"tree",
".",
"version",
"{",
"return",
"cmn",
".",
"NewError",
"(",
"\"",
"\"",
",",
"version",
")",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"tree",
".",
"versions",
"[",
"version",
"]",
";",
"!",
"ok",
"{",
"return",
"cmn",
".",
"ErrorWrap",
"(",
"ErrVersionDoesNotExist",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"tree",
".",
"ndb",
".",
"DeleteVersion",
"(",
"version",
",",
"true",
")",
"\n",
"tree",
".",
"ndb",
".",
"Commit",
"(",
")",
"\n\n",
"delete",
"(",
"tree",
".",
"versions",
",",
"version",
")",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // DeleteVersion deletes a tree version from disk. The version can then no
// longer be accessed. | [
"DeleteVersion",
"deletes",
"a",
"tree",
"version",
"from",
"disk",
".",
"The",
"version",
"can",
"then",
"no",
"longer",
"be",
"accessed",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/mutable_tree.go#L368-L385 |
6,287 | tendermint/iavl | mutable_tree.go | deleteVersionsFrom | func (tree *MutableTree) deleteVersionsFrom(version int64) error {
if version <= 0 {
return cmn.NewError("version must be greater than 0")
}
newLatestVersion := version - 1
lastestVersion := tree.ndb.getLatestVersion()
for ; version <= lastestVersion; version++ {
if version == tree.version {
return cmn.NewError("cannot delete latest saved version (%d)", version)
}
if _, ok := tree.versions[version]; !ok {
return cmn.ErrorWrap(ErrVersionDoesNotExist, "")
}
tree.ndb.DeleteVersion(version, false)
delete(tree.versions, version)
}
tree.ndb.Commit()
tree.ndb.resetLatestVersion(newLatestVersion)
return nil
} | go | func (tree *MutableTree) deleteVersionsFrom(version int64) error {
if version <= 0 {
return cmn.NewError("version must be greater than 0")
}
newLatestVersion := version - 1
lastestVersion := tree.ndb.getLatestVersion()
for ; version <= lastestVersion; version++ {
if version == tree.version {
return cmn.NewError("cannot delete latest saved version (%d)", version)
}
if _, ok := tree.versions[version]; !ok {
return cmn.ErrorWrap(ErrVersionDoesNotExist, "")
}
tree.ndb.DeleteVersion(version, false)
delete(tree.versions, version)
}
tree.ndb.Commit()
tree.ndb.resetLatestVersion(newLatestVersion)
return nil
} | [
"func",
"(",
"tree",
"*",
"MutableTree",
")",
"deleteVersionsFrom",
"(",
"version",
"int64",
")",
"error",
"{",
"if",
"version",
"<=",
"0",
"{",
"return",
"cmn",
".",
"NewError",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"newLatestVersion",
":=",
"version",
"-",
"1",
"\n",
"lastestVersion",
":=",
"tree",
".",
"ndb",
".",
"getLatestVersion",
"(",
")",
"\n",
"for",
";",
"version",
"<=",
"lastestVersion",
";",
"version",
"++",
"{",
"if",
"version",
"==",
"tree",
".",
"version",
"{",
"return",
"cmn",
".",
"NewError",
"(",
"\"",
"\"",
",",
"version",
")",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"tree",
".",
"versions",
"[",
"version",
"]",
";",
"!",
"ok",
"{",
"return",
"cmn",
".",
"ErrorWrap",
"(",
"ErrVersionDoesNotExist",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"tree",
".",
"ndb",
".",
"DeleteVersion",
"(",
"version",
",",
"false",
")",
"\n",
"delete",
"(",
"tree",
".",
"versions",
",",
"version",
")",
"\n",
"}",
"\n",
"tree",
".",
"ndb",
".",
"Commit",
"(",
")",
"\n",
"tree",
".",
"ndb",
".",
"resetLatestVersion",
"(",
"newLatestVersion",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // deleteVersionsFrom deletes tree version from disk specified version to latest version. The version can then no
// longer be accessed. | [
"deleteVersionsFrom",
"deletes",
"tree",
"version",
"from",
"disk",
"specified",
"version",
"to",
"latest",
"version",
".",
"The",
"version",
"can",
"then",
"no",
"longer",
"be",
"accessed",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/mutable_tree.go#L389-L408 |
6,288 | tendermint/iavl | mutable_tree.go | rotateRight | func (tree *MutableTree) rotateRight(node *Node) (*Node, *Node) {
version := tree.version + 1
// TODO: optimize balance & rotate.
node = node.clone(version)
orphaned := node.getLeftNode(tree.ImmutableTree)
newNode := orphaned.clone(version)
newNoderHash, newNoderCached := newNode.rightHash, newNode.rightNode
newNode.rightHash, newNode.rightNode = node.hash, node
node.leftHash, node.leftNode = newNoderHash, newNoderCached
node.calcHeightAndSize(tree.ImmutableTree)
newNode.calcHeightAndSize(tree.ImmutableTree)
return newNode, orphaned
} | go | func (tree *MutableTree) rotateRight(node *Node) (*Node, *Node) {
version := tree.version + 1
// TODO: optimize balance & rotate.
node = node.clone(version)
orphaned := node.getLeftNode(tree.ImmutableTree)
newNode := orphaned.clone(version)
newNoderHash, newNoderCached := newNode.rightHash, newNode.rightNode
newNode.rightHash, newNode.rightNode = node.hash, node
node.leftHash, node.leftNode = newNoderHash, newNoderCached
node.calcHeightAndSize(tree.ImmutableTree)
newNode.calcHeightAndSize(tree.ImmutableTree)
return newNode, orphaned
} | [
"func",
"(",
"tree",
"*",
"MutableTree",
")",
"rotateRight",
"(",
"node",
"*",
"Node",
")",
"(",
"*",
"Node",
",",
"*",
"Node",
")",
"{",
"version",
":=",
"tree",
".",
"version",
"+",
"1",
"\n\n",
"// TODO: optimize balance & rotate.",
"node",
"=",
"node",
".",
"clone",
"(",
"version",
")",
"\n",
"orphaned",
":=",
"node",
".",
"getLeftNode",
"(",
"tree",
".",
"ImmutableTree",
")",
"\n",
"newNode",
":=",
"orphaned",
".",
"clone",
"(",
"version",
")",
"\n\n",
"newNoderHash",
",",
"newNoderCached",
":=",
"newNode",
".",
"rightHash",
",",
"newNode",
".",
"rightNode",
"\n",
"newNode",
".",
"rightHash",
",",
"newNode",
".",
"rightNode",
"=",
"node",
".",
"hash",
",",
"node",
"\n",
"node",
".",
"leftHash",
",",
"node",
".",
"leftNode",
"=",
"newNoderHash",
",",
"newNoderCached",
"\n\n",
"node",
".",
"calcHeightAndSize",
"(",
"tree",
".",
"ImmutableTree",
")",
"\n",
"newNode",
".",
"calcHeightAndSize",
"(",
"tree",
".",
"ImmutableTree",
")",
"\n\n",
"return",
"newNode",
",",
"orphaned",
"\n",
"}"
] | // Rotate right and return the new node and orphan. | [
"Rotate",
"right",
"and",
"return",
"the",
"new",
"node",
"and",
"orphan",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/mutable_tree.go#L411-L427 |
6,289 | tendermint/iavl | mutable_tree.go | rotateLeft | func (tree *MutableTree) rotateLeft(node *Node) (*Node, *Node) {
version := tree.version + 1
// TODO: optimize balance & rotate.
node = node.clone(version)
orphaned := node.getRightNode(tree.ImmutableTree)
newNode := orphaned.clone(version)
newNodelHash, newNodelCached := newNode.leftHash, newNode.leftNode
newNode.leftHash, newNode.leftNode = node.hash, node
node.rightHash, node.rightNode = newNodelHash, newNodelCached
node.calcHeightAndSize(tree.ImmutableTree)
newNode.calcHeightAndSize(tree.ImmutableTree)
return newNode, orphaned
} | go | func (tree *MutableTree) rotateLeft(node *Node) (*Node, *Node) {
version := tree.version + 1
// TODO: optimize balance & rotate.
node = node.clone(version)
orphaned := node.getRightNode(tree.ImmutableTree)
newNode := orphaned.clone(version)
newNodelHash, newNodelCached := newNode.leftHash, newNode.leftNode
newNode.leftHash, newNode.leftNode = node.hash, node
node.rightHash, node.rightNode = newNodelHash, newNodelCached
node.calcHeightAndSize(tree.ImmutableTree)
newNode.calcHeightAndSize(tree.ImmutableTree)
return newNode, orphaned
} | [
"func",
"(",
"tree",
"*",
"MutableTree",
")",
"rotateLeft",
"(",
"node",
"*",
"Node",
")",
"(",
"*",
"Node",
",",
"*",
"Node",
")",
"{",
"version",
":=",
"tree",
".",
"version",
"+",
"1",
"\n\n",
"// TODO: optimize balance & rotate.",
"node",
"=",
"node",
".",
"clone",
"(",
"version",
")",
"\n",
"orphaned",
":=",
"node",
".",
"getRightNode",
"(",
"tree",
".",
"ImmutableTree",
")",
"\n",
"newNode",
":=",
"orphaned",
".",
"clone",
"(",
"version",
")",
"\n\n",
"newNodelHash",
",",
"newNodelCached",
":=",
"newNode",
".",
"leftHash",
",",
"newNode",
".",
"leftNode",
"\n",
"newNode",
".",
"leftHash",
",",
"newNode",
".",
"leftNode",
"=",
"node",
".",
"hash",
",",
"node",
"\n",
"node",
".",
"rightHash",
",",
"node",
".",
"rightNode",
"=",
"newNodelHash",
",",
"newNodelCached",
"\n\n",
"node",
".",
"calcHeightAndSize",
"(",
"tree",
".",
"ImmutableTree",
")",
"\n",
"newNode",
".",
"calcHeightAndSize",
"(",
"tree",
".",
"ImmutableTree",
")",
"\n\n",
"return",
"newNode",
",",
"orphaned",
"\n",
"}"
] | // Rotate left and return the new node and orphan. | [
"Rotate",
"left",
"and",
"return",
"the",
"new",
"node",
"and",
"orphan",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/mutable_tree.go#L430-L446 |
6,290 | tendermint/iavl | nodedb.go | GetNode | func (ndb *nodeDB) GetNode(hash []byte) *Node {
ndb.mtx.Lock()
defer ndb.mtx.Unlock()
if len(hash) == 0 {
panic("nodeDB.GetNode() requires hash")
}
// Check the cache.
if elem, ok := ndb.nodeCache[string(hash)]; ok {
// Already exists. Move to back of nodeCacheQueue.
ndb.nodeCacheQueue.MoveToBack(elem)
return elem.Value.(*Node)
}
// Doesn't exist, load.
buf := ndb.db.Get(ndb.nodeKey(hash))
if buf == nil {
panic(fmt.Sprintf("Value missing for hash %x corresponding to nodeKey %s", hash, ndb.nodeKey(hash)))
}
node, err := MakeNode(buf)
if err != nil {
panic(fmt.Sprintf("Error reading Node. bytes: %x, error: %v", buf, err))
}
node.hash = hash
node.persisted = true
ndb.cacheNode(node)
return node
} | go | func (ndb *nodeDB) GetNode(hash []byte) *Node {
ndb.mtx.Lock()
defer ndb.mtx.Unlock()
if len(hash) == 0 {
panic("nodeDB.GetNode() requires hash")
}
// Check the cache.
if elem, ok := ndb.nodeCache[string(hash)]; ok {
// Already exists. Move to back of nodeCacheQueue.
ndb.nodeCacheQueue.MoveToBack(elem)
return elem.Value.(*Node)
}
// Doesn't exist, load.
buf := ndb.db.Get(ndb.nodeKey(hash))
if buf == nil {
panic(fmt.Sprintf("Value missing for hash %x corresponding to nodeKey %s", hash, ndb.nodeKey(hash)))
}
node, err := MakeNode(buf)
if err != nil {
panic(fmt.Sprintf("Error reading Node. bytes: %x, error: %v", buf, err))
}
node.hash = hash
node.persisted = true
ndb.cacheNode(node)
return node
} | [
"func",
"(",
"ndb",
"*",
"nodeDB",
")",
"GetNode",
"(",
"hash",
"[",
"]",
"byte",
")",
"*",
"Node",
"{",
"ndb",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"ndb",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"len",
"(",
"hash",
")",
"==",
"0",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Check the cache.",
"if",
"elem",
",",
"ok",
":=",
"ndb",
".",
"nodeCache",
"[",
"string",
"(",
"hash",
")",
"]",
";",
"ok",
"{",
"// Already exists. Move to back of nodeCacheQueue.",
"ndb",
".",
"nodeCacheQueue",
".",
"MoveToBack",
"(",
"elem",
")",
"\n",
"return",
"elem",
".",
"Value",
".",
"(",
"*",
"Node",
")",
"\n",
"}",
"\n\n",
"// Doesn't exist, load.",
"buf",
":=",
"ndb",
".",
"db",
".",
"Get",
"(",
"ndb",
".",
"nodeKey",
"(",
"hash",
")",
")",
"\n",
"if",
"buf",
"==",
"nil",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"hash",
",",
"ndb",
".",
"nodeKey",
"(",
"hash",
")",
")",
")",
"\n",
"}",
"\n\n",
"node",
",",
"err",
":=",
"MakeNode",
"(",
"buf",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"buf",
",",
"err",
")",
")",
"\n",
"}",
"\n\n",
"node",
".",
"hash",
"=",
"hash",
"\n",
"node",
".",
"persisted",
"=",
"true",
"\n",
"ndb",
".",
"cacheNode",
"(",
"node",
")",
"\n\n",
"return",
"node",
"\n",
"}"
] | // GetNode gets a node from cache or disk. If it is an inner node, it does not
// load its children. | [
"GetNode",
"gets",
"a",
"node",
"from",
"cache",
"or",
"disk",
".",
"If",
"it",
"is",
"an",
"inner",
"node",
"it",
"does",
"not",
"load",
"its",
"children",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/nodedb.go#L60-L91 |
6,291 | tendermint/iavl | nodedb.go | SaveNode | func (ndb *nodeDB) SaveNode(node *Node) {
ndb.mtx.Lock()
defer ndb.mtx.Unlock()
if node.hash == nil {
panic("Expected to find node.hash, but none found.")
}
if node.persisted {
panic("Shouldn't be calling save on an already persisted node.")
}
// Save node bytes to db.
buf := new(bytes.Buffer)
if err := node.writeBytes(buf); err != nil {
panic(err)
}
ndb.batch.Set(ndb.nodeKey(node.hash), buf.Bytes())
debug("BATCH SAVE %X %p\n", node.hash, node)
node.persisted = true
ndb.cacheNode(node)
} | go | func (ndb *nodeDB) SaveNode(node *Node) {
ndb.mtx.Lock()
defer ndb.mtx.Unlock()
if node.hash == nil {
panic("Expected to find node.hash, but none found.")
}
if node.persisted {
panic("Shouldn't be calling save on an already persisted node.")
}
// Save node bytes to db.
buf := new(bytes.Buffer)
if err := node.writeBytes(buf); err != nil {
panic(err)
}
ndb.batch.Set(ndb.nodeKey(node.hash), buf.Bytes())
debug("BATCH SAVE %X %p\n", node.hash, node)
node.persisted = true
ndb.cacheNode(node)
} | [
"func",
"(",
"ndb",
"*",
"nodeDB",
")",
"SaveNode",
"(",
"node",
"*",
"Node",
")",
"{",
"ndb",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"ndb",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"node",
".",
"hash",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"node",
".",
"persisted",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Save node bytes to db.",
"buf",
":=",
"new",
"(",
"bytes",
".",
"Buffer",
")",
"\n",
"if",
"err",
":=",
"node",
".",
"writeBytes",
"(",
"buf",
")",
";",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"ndb",
".",
"batch",
".",
"Set",
"(",
"ndb",
".",
"nodeKey",
"(",
"node",
".",
"hash",
")",
",",
"buf",
".",
"Bytes",
"(",
")",
")",
"\n",
"debug",
"(",
"\"",
"\\n",
"\"",
",",
"node",
".",
"hash",
",",
"node",
")",
"\n\n",
"node",
".",
"persisted",
"=",
"true",
"\n",
"ndb",
".",
"cacheNode",
"(",
"node",
")",
"\n",
"}"
] | // SaveNode saves a node to disk. | [
"SaveNode",
"saves",
"a",
"node",
"to",
"disk",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/nodedb.go#L94-L115 |
6,292 | tendermint/iavl | nodedb.go | Has | func (ndb *nodeDB) Has(hash []byte) bool {
key := ndb.nodeKey(hash)
if ldb, ok := ndb.db.(*dbm.GoLevelDB); ok {
exists, err := ldb.DB().Has(key, nil)
if err != nil {
panic("Got error from leveldb: " + err.Error())
}
return exists
}
return ndb.db.Get(key) != nil
} | go | func (ndb *nodeDB) Has(hash []byte) bool {
key := ndb.nodeKey(hash)
if ldb, ok := ndb.db.(*dbm.GoLevelDB); ok {
exists, err := ldb.DB().Has(key, nil)
if err != nil {
panic("Got error from leveldb: " + err.Error())
}
return exists
}
return ndb.db.Get(key) != nil
} | [
"func",
"(",
"ndb",
"*",
"nodeDB",
")",
"Has",
"(",
"hash",
"[",
"]",
"byte",
")",
"bool",
"{",
"key",
":=",
"ndb",
".",
"nodeKey",
"(",
"hash",
")",
"\n\n",
"if",
"ldb",
",",
"ok",
":=",
"ndb",
".",
"db",
".",
"(",
"*",
"dbm",
".",
"GoLevelDB",
")",
";",
"ok",
"{",
"exists",
",",
"err",
":=",
"ldb",
".",
"DB",
"(",
")",
".",
"Has",
"(",
"key",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
"+",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"exists",
"\n",
"}",
"\n",
"return",
"ndb",
".",
"db",
".",
"Get",
"(",
"key",
")",
"!=",
"nil",
"\n",
"}"
] | // Has checks if a hash exists in the database. | [
"Has",
"checks",
"if",
"a",
"hash",
"exists",
"in",
"the",
"database",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/nodedb.go#L118-L129 |
6,293 | tendermint/iavl | nodedb.go | DeleteVersion | func (ndb *nodeDB) DeleteVersion(version int64, checkLatestVersion bool) {
ndb.mtx.Lock()
defer ndb.mtx.Unlock()
ndb.deleteOrphans(version)
ndb.deleteRoot(version, checkLatestVersion)
} | go | func (ndb *nodeDB) DeleteVersion(version int64, checkLatestVersion bool) {
ndb.mtx.Lock()
defer ndb.mtx.Unlock()
ndb.deleteOrphans(version)
ndb.deleteRoot(version, checkLatestVersion)
} | [
"func",
"(",
"ndb",
"*",
"nodeDB",
")",
"DeleteVersion",
"(",
"version",
"int64",
",",
"checkLatestVersion",
"bool",
")",
"{",
"ndb",
".",
"mtx",
".",
"Lock",
"(",
")",
"\n",
"defer",
"ndb",
".",
"mtx",
".",
"Unlock",
"(",
")",
"\n\n",
"ndb",
".",
"deleteOrphans",
"(",
"version",
")",
"\n",
"ndb",
".",
"deleteRoot",
"(",
"version",
",",
"checkLatestVersion",
")",
"\n",
"}"
] | // DeleteVersion deletes a tree version from disk. | [
"DeleteVersion",
"deletes",
"a",
"tree",
"version",
"from",
"disk",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/nodedb.go#L157-L163 |
6,294 | tendermint/iavl | nodedb.go | saveOrphan | func (ndb *nodeDB) saveOrphan(hash []byte, fromVersion, toVersion int64) {
if fromVersion > toVersion {
panic(fmt.Sprintf("Orphan expires before it comes alive. %d > %d", fromVersion, toVersion))
}
key := ndb.orphanKey(fromVersion, toVersion, hash)
ndb.batch.Set(key, hash)
} | go | func (ndb *nodeDB) saveOrphan(hash []byte, fromVersion, toVersion int64) {
if fromVersion > toVersion {
panic(fmt.Sprintf("Orphan expires before it comes alive. %d > %d", fromVersion, toVersion))
}
key := ndb.orphanKey(fromVersion, toVersion, hash)
ndb.batch.Set(key, hash)
} | [
"func",
"(",
"ndb",
"*",
"nodeDB",
")",
"saveOrphan",
"(",
"hash",
"[",
"]",
"byte",
",",
"fromVersion",
",",
"toVersion",
"int64",
")",
"{",
"if",
"fromVersion",
">",
"toVersion",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"fromVersion",
",",
"toVersion",
")",
")",
"\n",
"}",
"\n",
"key",
":=",
"ndb",
".",
"orphanKey",
"(",
"fromVersion",
",",
"toVersion",
",",
"hash",
")",
"\n",
"ndb",
".",
"batch",
".",
"Set",
"(",
"key",
",",
"hash",
")",
"\n",
"}"
] | // Saves a single orphan to disk. | [
"Saves",
"a",
"single",
"orphan",
"to",
"disk",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/nodedb.go#L180-L186 |
6,295 | tendermint/iavl | nodedb.go | deleteOrphans | func (ndb *nodeDB) deleteOrphans(version int64) {
// Will be zero if there is no previous version.
predecessor := ndb.getPreviousVersion(version)
// Traverse orphans with a lifetime ending at the version specified.
// TODO optimize.
ndb.traverseOrphansVersion(version, func(key, hash []byte) {
var fromVersion, toVersion int64
// See comment on `orphanKeyFmt`. Note that here, `version` and
// `toVersion` are always equal.
orphanKeyFormat.Scan(key, &toVersion, &fromVersion)
// Delete orphan key and reverse-lookup key.
ndb.batch.Delete(key)
// If there is no predecessor, or the predecessor is earlier than the
// beginning of the lifetime (ie: negative lifetime), or the lifetime
// spans a single version and that version is the one being deleted, we
// can delete the orphan. Otherwise, we shorten its lifetime, by
// moving its endpoint to the previous version.
if predecessor < fromVersion || fromVersion == toVersion {
debug("DELETE predecessor:%v fromVersion:%v toVersion:%v %X\n", predecessor, fromVersion, toVersion, hash)
ndb.batch.Delete(ndb.nodeKey(hash))
ndb.uncacheNode(hash)
} else {
debug("MOVE predecessor:%v fromVersion:%v toVersion:%v %X\n", predecessor, fromVersion, toVersion, hash)
ndb.saveOrphan(hash, fromVersion, predecessor)
}
})
} | go | func (ndb *nodeDB) deleteOrphans(version int64) {
// Will be zero if there is no previous version.
predecessor := ndb.getPreviousVersion(version)
// Traverse orphans with a lifetime ending at the version specified.
// TODO optimize.
ndb.traverseOrphansVersion(version, func(key, hash []byte) {
var fromVersion, toVersion int64
// See comment on `orphanKeyFmt`. Note that here, `version` and
// `toVersion` are always equal.
orphanKeyFormat.Scan(key, &toVersion, &fromVersion)
// Delete orphan key and reverse-lookup key.
ndb.batch.Delete(key)
// If there is no predecessor, or the predecessor is earlier than the
// beginning of the lifetime (ie: negative lifetime), or the lifetime
// spans a single version and that version is the one being deleted, we
// can delete the orphan. Otherwise, we shorten its lifetime, by
// moving its endpoint to the previous version.
if predecessor < fromVersion || fromVersion == toVersion {
debug("DELETE predecessor:%v fromVersion:%v toVersion:%v %X\n", predecessor, fromVersion, toVersion, hash)
ndb.batch.Delete(ndb.nodeKey(hash))
ndb.uncacheNode(hash)
} else {
debug("MOVE predecessor:%v fromVersion:%v toVersion:%v %X\n", predecessor, fromVersion, toVersion, hash)
ndb.saveOrphan(hash, fromVersion, predecessor)
}
})
} | [
"func",
"(",
"ndb",
"*",
"nodeDB",
")",
"deleteOrphans",
"(",
"version",
"int64",
")",
"{",
"// Will be zero if there is no previous version.",
"predecessor",
":=",
"ndb",
".",
"getPreviousVersion",
"(",
"version",
")",
"\n\n",
"// Traverse orphans with a lifetime ending at the version specified.",
"// TODO optimize.",
"ndb",
".",
"traverseOrphansVersion",
"(",
"version",
",",
"func",
"(",
"key",
",",
"hash",
"[",
"]",
"byte",
")",
"{",
"var",
"fromVersion",
",",
"toVersion",
"int64",
"\n\n",
"// See comment on `orphanKeyFmt`. Note that here, `version` and",
"// `toVersion` are always equal.",
"orphanKeyFormat",
".",
"Scan",
"(",
"key",
",",
"&",
"toVersion",
",",
"&",
"fromVersion",
")",
"\n\n",
"// Delete orphan key and reverse-lookup key.",
"ndb",
".",
"batch",
".",
"Delete",
"(",
"key",
")",
"\n\n",
"// If there is no predecessor, or the predecessor is earlier than the",
"// beginning of the lifetime (ie: negative lifetime), or the lifetime",
"// spans a single version and that version is the one being deleted, we",
"// can delete the orphan. Otherwise, we shorten its lifetime, by",
"// moving its endpoint to the previous version.",
"if",
"predecessor",
"<",
"fromVersion",
"||",
"fromVersion",
"==",
"toVersion",
"{",
"debug",
"(",
"\"",
"\\n",
"\"",
",",
"predecessor",
",",
"fromVersion",
",",
"toVersion",
",",
"hash",
")",
"\n",
"ndb",
".",
"batch",
".",
"Delete",
"(",
"ndb",
".",
"nodeKey",
"(",
"hash",
")",
")",
"\n",
"ndb",
".",
"uncacheNode",
"(",
"hash",
")",
"\n",
"}",
"else",
"{",
"debug",
"(",
"\"",
"\\n",
"\"",
",",
"predecessor",
",",
"fromVersion",
",",
"toVersion",
",",
"hash",
")",
"\n",
"ndb",
".",
"saveOrphan",
"(",
"hash",
",",
"fromVersion",
",",
"predecessor",
")",
"\n",
"}",
"\n",
"}",
")",
"\n",
"}"
] | // deleteOrphans deletes orphaned nodes from disk, and the associated orphan
// entries. | [
"deleteOrphans",
"deletes",
"orphaned",
"nodes",
"from",
"disk",
"and",
"the",
"associated",
"orphan",
"entries",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/nodedb.go#L190-L220 |
6,296 | tendermint/iavl | nodedb.go | deleteRoot | func (ndb *nodeDB) deleteRoot(version int64, checkLatestVersion bool) {
if checkLatestVersion && version == ndb.getLatestVersion() {
panic("Tried to delete latest version")
}
key := ndb.rootKey(version)
ndb.batch.Delete(key)
} | go | func (ndb *nodeDB) deleteRoot(version int64, checkLatestVersion bool) {
if checkLatestVersion && version == ndb.getLatestVersion() {
panic("Tried to delete latest version")
}
key := ndb.rootKey(version)
ndb.batch.Delete(key)
} | [
"func",
"(",
"ndb",
"*",
"nodeDB",
")",
"deleteRoot",
"(",
"version",
"int64",
",",
"checkLatestVersion",
"bool",
")",
"{",
"if",
"checkLatestVersion",
"&&",
"version",
"==",
"ndb",
".",
"getLatestVersion",
"(",
")",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"key",
":=",
"ndb",
".",
"rootKey",
"(",
"version",
")",
"\n",
"ndb",
".",
"batch",
".",
"Delete",
"(",
"key",
")",
"\n",
"}"
] | // deleteRoot deletes the root entry from disk, but not the node it points to. | [
"deleteRoot",
"deletes",
"the",
"root",
"entry",
"from",
"disk",
"but",
"not",
"the",
"node",
"it",
"points",
"to",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/nodedb.go#L269-L276 |
6,297 | tendermint/iavl | nodedb.go | traverseOrphansVersion | func (ndb *nodeDB) traverseOrphansVersion(version int64, fn func(k, v []byte)) {
ndb.traversePrefix(orphanKeyFormat.Key(version), fn)
} | go | func (ndb *nodeDB) traverseOrphansVersion(version int64, fn func(k, v []byte)) {
ndb.traversePrefix(orphanKeyFormat.Key(version), fn)
} | [
"func",
"(",
"ndb",
"*",
"nodeDB",
")",
"traverseOrphansVersion",
"(",
"version",
"int64",
",",
"fn",
"func",
"(",
"k",
",",
"v",
"[",
"]",
"byte",
")",
")",
"{",
"ndb",
".",
"traversePrefix",
"(",
"orphanKeyFormat",
".",
"Key",
"(",
"version",
")",
",",
"fn",
")",
"\n",
"}"
] | // Traverse orphans ending at a certain version. | [
"Traverse",
"orphans",
"ending",
"at",
"a",
"certain",
"version",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/nodedb.go#L283-L285 |
6,298 | tendermint/iavl | nodedb.go | traverse | func (ndb *nodeDB) traverse(fn func(key, value []byte)) {
itr := ndb.db.Iterator(nil, nil)
defer itr.Close()
for ; itr.Valid(); itr.Next() {
fn(itr.Key(), itr.Value())
}
} | go | func (ndb *nodeDB) traverse(fn func(key, value []byte)) {
itr := ndb.db.Iterator(nil, nil)
defer itr.Close()
for ; itr.Valid(); itr.Next() {
fn(itr.Key(), itr.Value())
}
} | [
"func",
"(",
"ndb",
"*",
"nodeDB",
")",
"traverse",
"(",
"fn",
"func",
"(",
"key",
",",
"value",
"[",
"]",
"byte",
")",
")",
"{",
"itr",
":=",
"ndb",
".",
"db",
".",
"Iterator",
"(",
"nil",
",",
"nil",
")",
"\n",
"defer",
"itr",
".",
"Close",
"(",
")",
"\n\n",
"for",
";",
"itr",
".",
"Valid",
"(",
")",
";",
"itr",
".",
"Next",
"(",
")",
"{",
"fn",
"(",
"itr",
".",
"Key",
"(",
")",
",",
"itr",
".",
"Value",
"(",
")",
")",
"\n",
"}",
"\n",
"}"
] | // Traverse all keys. | [
"Traverse",
"all",
"keys",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/nodedb.go#L288-L295 |
6,299 | tendermint/iavl | nodedb.go | traversePrefix | func (ndb *nodeDB) traversePrefix(prefix []byte, fn func(k, v []byte)) {
itr := dbm.IteratePrefix(ndb.db, prefix)
defer itr.Close()
for ; itr.Valid(); itr.Next() {
fn(itr.Key(), itr.Value())
}
} | go | func (ndb *nodeDB) traversePrefix(prefix []byte, fn func(k, v []byte)) {
itr := dbm.IteratePrefix(ndb.db, prefix)
defer itr.Close()
for ; itr.Valid(); itr.Next() {
fn(itr.Key(), itr.Value())
}
} | [
"func",
"(",
"ndb",
"*",
"nodeDB",
")",
"traversePrefix",
"(",
"prefix",
"[",
"]",
"byte",
",",
"fn",
"func",
"(",
"k",
",",
"v",
"[",
"]",
"byte",
")",
")",
"{",
"itr",
":=",
"dbm",
".",
"IteratePrefix",
"(",
"ndb",
".",
"db",
",",
"prefix",
")",
"\n",
"defer",
"itr",
".",
"Close",
"(",
")",
"\n\n",
"for",
";",
"itr",
".",
"Valid",
"(",
")",
";",
"itr",
".",
"Next",
"(",
")",
"{",
"fn",
"(",
"itr",
".",
"Key",
"(",
")",
",",
"itr",
".",
"Value",
"(",
")",
")",
"\n",
"}",
"\n",
"}"
] | // Traverse all keys with a certain prefix. | [
"Traverse",
"all",
"keys",
"with",
"a",
"certain",
"prefix",
"."
] | a0c58a289b0cdceb468b1e1246b6dc09ba4311eb | https://github.com/tendermint/iavl/blob/a0c58a289b0cdceb468b1e1246b6dc09ba4311eb/nodedb.go#L298-L305 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.