From b291a11f383666941381e9842e7fb90b2fed4b91 Mon Sep 17 00:00:00 2001 From: Mariusz Gronczewski Date: Thu, 1 Apr 2021 22:07:41 +0200 Subject: [PATCH] inherit custom PathTrie segmenter in child nodes --- path_trie.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/path_trie.go b/path_trie.go index 4f4f6d2..c0b8d96 100644 --- a/path_trie.go +++ b/path_trie.go @@ -38,6 +38,13 @@ func NewPathTrieWithConfig(config *PathTrieConfig) *PathTrie { } } +// newPathTrieFromTrie returns new trie while preserving its config +func (trie *PathTrie) newPathTrie() *PathTrie { + return &PathTrie{ + segmenter: trie.segmenter, + } +} + // Get returns the value stored at the given key. Returns nil for internal // nodes or for nodes with a value of nil. func (trie *PathTrie) Get(key string) interface{} { @@ -64,7 +71,7 @@ func (trie *PathTrie) Put(key string, value interface{}) bool { if node.children == nil { node.children = map[string]*PathTrie{} } - child = NewPathTrie() + child = trie.newPathTrie() node.children[part] = child } node = child