Update github.com/hasicorp/go-memdb
This commit is contained in:
parent
edd8cffc3b
commit
09ef2694f7
|
@ -1,24 +0,0 @@
|
|||
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
||||
*.o
|
||||
*.a
|
||||
*.so
|
||||
|
||||
# Folders
|
||||
_obj
|
||||
_test
|
||||
|
||||
# Architecture specific extensions/prefixes
|
||||
*.[568vq]
|
||||
[568vq].out
|
||||
|
||||
*.cgo1.go
|
||||
*.cgo2.c
|
||||
_cgo_defun.c
|
||||
_cgo_gotypes.go
|
||||
_cgo_export.*
|
||||
|
||||
_testmain.go
|
||||
|
||||
*.exe
|
||||
*.test
|
||||
*.prof
|
|
@ -291,10 +291,6 @@ func (c *CompoundIndex) FromArgs(args ...interface{}) ([]byte, error) {
|
|||
if len(args) != len(c.Indexes) {
|
||||
return nil, fmt.Errorf("less arguments than index fields")
|
||||
}
|
||||
return c.PrefixFromArgs(args...)
|
||||
}
|
||||
|
||||
func (c *CompoundIndex) PrefixFromArgs(args ...interface{}) ([]byte, error) {
|
||||
var out []byte
|
||||
for i, arg := range args {
|
||||
val, err := c.Indexes[i].FromArgs(arg)
|
||||
|
@ -305,3 +301,30 @@ func (c *CompoundIndex) PrefixFromArgs(args ...interface{}) ([]byte, error) {
|
|||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *CompoundIndex) PrefixFromArgs(args ...interface{}) ([]byte, error) {
|
||||
if len(args) > len(c.Indexes) {
|
||||
return nil, fmt.Errorf("more arguments than index fields")
|
||||
}
|
||||
var out []byte
|
||||
for i, arg := range args {
|
||||
if i+1 < len(args) {
|
||||
val, err := c.Indexes[i].FromArgs(arg)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("sub-index %d error: %v", i, err)
|
||||
}
|
||||
out = append(out, val...)
|
||||
} else {
|
||||
prefixIndexer, ok := c.Indexes[i].(PrefixIndexer)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("sub-index %d does not support prefix scanning", i)
|
||||
}
|
||||
val, err := prefixIndexer.PrefixFromArgs(arg)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("sub-index %d error: %v", i, err)
|
||||
}
|
||||
out = append(out, val...)
|
||||
}
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
|
|
@ -334,6 +334,39 @@ func (txn *Txn) First(table, index string, args ...interface{}) (interface{}, er
|
|||
return value, nil
|
||||
}
|
||||
|
||||
// LongestPrefix is used to fetch the longest prefix match for the given
|
||||
// constraints on the index. Note that this will not work with the memdb
|
||||
// StringFieldIndex because it adds null terminators which prevent the
|
||||
// algorithm from correctly finding a match (it will get to right before the
|
||||
// null and fail to find a leaf node). This should only be used where the prefix
|
||||
// given is capable of matching indexed entries directly, which typically only
|
||||
// applies to a custom indexer. See the unit test for an example.
|
||||
func (txn *Txn) LongestPrefix(table, index string, args ...interface{}) (interface{}, error) {
|
||||
// Enforce that this only works on prefix indexes.
|
||||
if !strings.HasSuffix(index, "_prefix") {
|
||||
return nil, fmt.Errorf("must use '%s_prefix' on index", index)
|
||||
}
|
||||
|
||||
// Get the index value.
|
||||
indexSchema, val, err := txn.getIndexValue(table, index, args...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// This algorithm only makes sense against a unique index, otherwise the
|
||||
// index keys will have the IDs appended to them.
|
||||
if !indexSchema.Unique {
|
||||
return nil, fmt.Errorf("index '%s' is not unique", index)
|
||||
}
|
||||
|
||||
// Find the longest prefix match with the given index.
|
||||
indexTxn := txn.readableIndex(table, indexSchema.Name)
|
||||
if _, value, ok := indexTxn.Root().LongestPrefix(val); ok {
|
||||
return value, nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// getIndexValue is used to get the IndexSchema and the value
|
||||
// used to scan the index given the parameters. This handles prefix based
|
||||
// scans when the index has the "_prefix" suffix. The index must support
|
||||
|
|
|
@ -453,8 +453,10 @@
|
|||
"revisionTime": "2016-06-09T02:05:29Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "/V57CyN7x2NUlHoOzVL5GgGXX84=",
|
||||
"path": "github.com/hashicorp/go-memdb",
|
||||
"revision": "2cc5518f24b906e7cccfc808817ba479f5489821"
|
||||
"revision": "98f52f52d7a476958fa9da671354d270c50661a7",
|
||||
"revisionTime": "2016-03-01T23:01:42Z"
|
||||
},
|
||||
{
|
||||
"path": "github.com/hashicorp/go-msgpack/codec",
|
||||
|
|
Loading…
Reference in New Issue