Skip to content

Commit

Permalink
iter_keys_upto_delimiter => iter_prefixes_upto_delimiter
Browse files Browse the repository at this point in the history
  • Loading branch information
crepererum committed Jun 17, 2019
1 parent 9063f74 commit e1324c4
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 18 deletions.
10 changes: 6 additions & 4 deletions simplekv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,14 @@ def iter_keys(self, prefix=u""):
"""
raise NotImplementedError

def iter_keys_upto_delimiter(self, delimiter, prefix=u""):
"""Returns an Iterator over all keys currently in the store, in any order. The keys are listed up to the given delimiter.
def iter_prefixes_upto_delimiter(self, delimiter, prefix=u""):
"""Returns an Iterator over all prefixes currently in the store, in any order. The
prefixes are listed up to the given delimiter.
If the prefix contains the delimiter, the first delimiter after the prefix is used as a cut-off point.
If the prefix contains the delimiter, the first delimiter after the prefix is used
as a cut-off point.
The uniqueness of the keys is ensured.
The uniqueness of the prefixes is ensured.
:raises exceptions.IOError: If there was an error accessing the store.
"""
Expand Down
2 changes: 1 addition & 1 deletion simplekv/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def iter_keys(self, prefix=u""):
return (self._unmap_key(k) for k in self._dstore.iter_keys(self._map_key_prefix(prefix))
if self._filter(k))

def iter_keys_upto_delimiter(self, delimiter, prefix=u""):
def iter_prefixes_upto_delimiter(self, delimiter, prefix=u""):
dlen = len(delimiter)
plen = len(prefix)
memory = set()
Expand Down
8 changes: 4 additions & 4 deletions simplekv/fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,15 @@ def keys(self, prefix=u""):
def iter_keys(self, prefix=u""):
return iter(self.keys(prefix))

def iter_keys_upto_delimiter(self, delimiter, prefix=u""):
def iter_prefixes_upto_delimiter(self, delimiter, prefix=u""):
if delimiter != os.sep:
return super(FilesystemStore, self).iter_keys_upto_delimiter(
return super(FilesystemStore, self).iter_prefixes_upto_delimiter(
delimiter,
prefix,
)
return self._iter_keys_upto_delimiter_efficient(delimiter, prefix)
return self._iter_prefixes_upto_delimiter_efficient(delimiter, prefix)

def _iter_keys_upto_delimiter_efficient(self, delimiter, prefix=u""):
def _iter_prefixes_upto_delimiter_efficient(self, delimiter, prefix=u""):
if delimiter in prefix:
pos = prefix.rfind(delimiter)
search_prefix = prefix[:pos]
Expand Down
2 changes: 1 addition & 1 deletion simplekv/net/azurestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def iter_keys(self, prefix=u""):
return (blob.decode('utf-8') if isinstance(blob, binary_type)
else blob for blob in blobs)

def iter_keys_upto_delimiter(self, delimiter, prefix=u""):
def iter_prefixes_upto_delimiter(self, delimiter, prefix=u""):
if prefix == "":
prefix = None
with map_azure_exceptions():
Expand Down
8 changes: 4 additions & 4 deletions tests/basic_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def test_key_iterator_with_prefix(self, store, key, key2, value):
l.sort()
assert l == sorted([key_prefix_1, key_prefix_2])

def test_key_iterator_upto_delimiter(self, store, value):
def test_prefix_iterator_upto_delimiter(self, store, value):
delimiter = u"X"
for k in [
u"X",
Expand All @@ -237,13 +237,13 @@ def test_key_iterator_upto_delimiter(self, store, value):
]:
store.put(k, value)

l = sorted(store.iter_keys_upto_delimiter(u"X"))
l = sorted(store.iter_prefixes_upto_delimiter(u"X"))
assert l == [u"X", u"a1X", u"a2X", u"a3", u"a4X"]

l = sorted(store.iter_keys_upto_delimiter(u"X", prefix=u"a4X"))
l = sorted(store.iter_prefixes_upto_delimiter(u"X", prefix=u"a4X"))
assert l == [u"a4Xb1X", u"a4Xb2X", u"a4Xb3"]

l = sorted(store.iter_keys_upto_delimiter(u"X", prefix=u"foo"))
l = sorted(store.iter_prefixes_upto_delimiter(u"X", prefix=u"foo"))
assert l == []

def test_keys(self, store, key, key2, value, value2):
Expand Down
8 changes: 4 additions & 4 deletions tests/test_filesystem_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class ExtendedKeyspaceStore(ExtendedKeyspaceMixin, FilesystemStore):
pass
return ExtendedKeyspaceStore(tmpdir)

def test_key_iterator_upto_delimiter_ossep(self, store, value):
def test_prefix_iterator_upto_delimiter_ossep(self, store, value):
delimiter = u"X"
for k in [
u"a1" + os.sep + u"b1",
Expand All @@ -188,15 +188,15 @@ def test_key_iterator_upto_delimiter_ossep(self, store, value):
]:
store.put(k, value)

l = sorted(store.iter_keys_upto_delimiter(os.sep))
l = sorted(store.iter_prefixes_upto_delimiter(os.sep))
assert l == [
u"a1" + os.sep,
u"a2" + os.sep,
u"a3",
u"a4" + os.sep,
]

l = sorted(store.iter_keys_upto_delimiter(
l = sorted(store.iter_prefixes_upto_delimiter(
os.sep,
prefix=u"a4" + os.sep,
))
Expand All @@ -206,7 +206,7 @@ def test_key_iterator_upto_delimiter_ossep(self, store, value):
u"a4" + os.sep + "b3",
]

l = sorted(store.iter_keys_upto_delimiter(
l = sorted(store.iter_prefixes_upto_delimiter(
os.sep,
prefix=u"foo" + os.sep,
))
Expand Down

0 comments on commit e1324c4

Please sign in to comment.