From 962a86dc9203e5ffe19a0e49abc8a2b245bb11dc Mon Sep 17 00:00:00 2001 From: Paul Cruickshank Date: Mon, 29 Jun 2020 16:24:04 +0100 Subject: [PATCH] Create an iterator at a specific node --- trees/redblacktree/iterator.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/trees/redblacktree/iterator.go b/trees/redblacktree/iterator.go index 90b84af..9cde5e4 100644 --- a/trees/redblacktree/iterator.go +++ b/trees/redblacktree/iterator.go @@ -28,6 +28,11 @@ func (tree *Tree) Iterator() Iterator { return Iterator{tree: tree, node: nil, position: begin} } +// IteratorAt returns a stateful iterator whose elements are key/value pairs that is initialised at a particular node. +func (tree *Tree) IteratorAt(node *Node) Iterator { + return Iterator{tree: tree, node: node, position: between} +} + // Next moves the iterator to the next element and returns true if there was a next element in the container. // If Next() returns true, then next element's key and value can be retrieved by Key() and Value(). // If Next() was called for the first time, then it will point the iterator to the first element if it exists.