Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
add discard and remove function
Browse files Browse the repository at this point in the history
  • Loading branch information
pymia authored and miachang committed Sep 13, 2017
1 parent 64ee083 commit fd72748
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions pygtrie.py
Original file line number Diff line number Diff line change
Expand Up @@ -1364,13 +1364,35 @@ def add(self, key):
self._trie[key:] = True

def discard(self, key):
raise NotImplementedError(
'Removing keys from PrefixSet is not implemented.')
try:
node, _ = self._get_node(key)
except:
pass

if node and node.children:
for child in node.children:
self.discard(child)
else:
node.children = {}
node.value = _SENTINEL



# Raises KeyError if elem is not contained in the set.
def remove(self, key):
raise NotImplementedError(
'Removing keys from PrefixSet is not implemented.')
try:
node, _ = self._get_node(key)
except KeyError:
return 0

if node and node.children:
for child in node.children:
self.discard(child)
else:
node.children = {}
node.value = _SENTINEL

def pop(self):

raise NotImplementedError(
'Removing keys from PrefixSet is not implemented.')

0 comments on commit fd72748

Please sign in to comment.