projects
/
pyutils.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Improve documentation.
[pyutils.git]
/
src
/
pyutils
/
collectionz
/
trie.py
diff --git
a/src/pyutils/collectionz/trie.py
b/src/pyutils/collectionz/trie.py
index 607f5316f45eef35cef7ed5897e2fbca5af18e7e..762ae3a992fcc860f69a1e2897d73ea1af17c4cb 100644
(file)
--- a/
src/pyutils/collectionz/trie.py
+++ b/
src/pyutils/collectionz/trie.py
@@
-73,12
+73,12
@@
class Trie(object):
be a full item.
>>> t = Trie()
be a full item.
>>> t = Trie()
- >>> t.insert('t
esti
cle')
- >>> t.contains_prefix('t
est
')
+ >>> t.insert('t
ricy
cle')
+ >>> t.contains_prefix('t
ri
')
True
True
- >>> t.contains_prefix('t
esti
cle')
+ >>> t.contains_prefix('t
ricy
cle')
True
True
- >>> t.contains_prefix('t
essel
')
+ >>> t.contains_prefix('t
riad
')
False
"""
False
"""
@@
-255,13
+255,16
@@
class Trie(object):
return None
return [x for x in node if x != self.end]
return None
return [x for x in node if x != self.end]
- def repr_fancy(
+ def
_
repr_fancy(
self,
padding: str,
pointer: str,
node: Any,
has_sibling: bool,
self,
padding: str,
pointer: str,
node: Any,
has_sibling: bool,
- ):
+ ) -> str:
+ """
+ Helper that return a fancy representation of the Trie:
+ """
if node is None:
return ''
if node is not self.root:
if node is None:
return ''
if node is not self.root:
@@
-288,7
+291,7
@@
class Trie(object):
has_sibling = False
pointer += f'{child}'
child_count -= 1
has_sibling = False
pointer += f'{child}'
child_count -= 1
- ret += self.repr_fancy(padding, pointer, node[child], has_sibling)
+ ret += self.
_
repr_fancy(padding, pointer, node[child], has_sibling)
return ret
def repr_brief(self, node, delimiter):
return ret
def repr_brief(self, node, delimiter):
@@
-323,7
+326,7
@@
class Trie(object):
def __repr__(self):
"""
A friendly string representation of the contents of the Trie. Under
def __repr__(self):
"""
A friendly string representation of the contents of the Trie. Under
- the covers uses repr_fancy.
+ the covers uses
_
repr_fancy.
>>> t = Trie()
>>> t.insert([10, 0, 0, 1])
>>> t = Trie()
>>> t.insert([10, 0, 0, 1])
@@
-343,4
+346,4
@@
class Trie(object):
└──2
"""
└──2
"""
- return self.repr_fancy('', '*', self.root, False)
+ return self.
_
repr_fancy('', '*', self.root, False)