added ability to iterate over all indexes and use index.Iterate() instead of ReadDir() to walk over the graph
Signed-off-by: Roman Strashkin <roman.strashkin@gmail.com>
This commit is contained in:
parent
3314761f62
commit
1d2e175c37
2 changed files with 33 additions and 0 deletions
|
@ -108,3 +108,13 @@ func (idx *TruncIndex) Get(s string) (string, error) {
|
|||
}
|
||||
return "", fmt.Errorf("no such id: %s", s)
|
||||
}
|
||||
|
||||
// Iterates over all stored IDs, and passes each of them to the given handler
|
||||
func (idx *TruncIndex) Iterate(handler func(id string)) {
|
||||
idx.RLock()
|
||||
defer idx.RUnlock()
|
||||
idx.trie.Visit(func(prefix patricia.Prefix, item patricia.Item) error {
|
||||
handler(string(prefix))
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue