Skip to content

Commit

Permalink
index: introduce delete_node
Browse files Browse the repository at this point in the history
  • Loading branch information
efiop committed Jun 9, 2023
1 parent c7bb74b commit 0f38a0f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ install_requires=
diskcache>=5.2.1
nanotime>=0.5.2
attrs>=21.3.0
sqltrie>=0.3.1,<1
sqltrie>=0.5.0,<1

[options.extras_require]
cli =
Expand Down
11 changes: 11 additions & 0 deletions src/dvc_data/index/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ def __delitem__(self, key):
self._cache.pop(key, None)
super().__delitem__(key)

def delete_node(self, key):
self._cache.pop(key, None)
super().delete_node(key)


class Storage(ABC):
def __init__(self, key: "DataIndexKey"):
Expand Down Expand Up @@ -390,6 +394,10 @@ def traverse(self, node_factory: Callable, **kwargs) -> Any:
def has_node(self, key: DataIndexKey) -> bool:
pass

@abstractmethod
def delete_node(self, key: DataIndexKey) -> None:
pass

@abstractmethod
def longest_prefix(
self, key: DataIndexKey
Expand Down Expand Up @@ -629,6 +637,9 @@ def load(self, **kwargs):
def has_node(self, key: DataIndexKey) -> bool:
return self._trie.has_node(key)

def delete_node(self, key: DataIndexKey) -> None:
return self._trie.delete_node(key)

def shortest_prefix(self, *args, **kwargs):
return self._trie.shortest_prefix(*args, **kwargs)

Expand Down
5 changes: 5 additions & 0 deletions src/dvc_data/index/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ def _filter_fn(entry):
def has_node(self, key: DataIndexKey) -> bool:
return self.filter_fn(key) and self._index.has_node(key)

def delete_node(self, key: DataIndexKey) -> None:
if not self.filter_fn(key):
raise KeyError
self._index.delete_node(key)

def longest_prefix(
self, key: DataIndexKey
) -> Tuple[Optional[DataIndexKey], Optional[DataIndexEntry]]:
Expand Down

0 comments on commit 0f38a0f

Please sign in to comment.