Skip to content

Commit

Permalink
And same for HashTrieMap.
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian committed Jan 10, 2024
1 parent 579e1ca commit f3d713c
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::hash::{Hash, Hasher};
use std::vec::IntoIter;

use pyo3::exceptions::PyIndexError;
use pyo3::pyclass::CompareOp;
Expand Down Expand Up @@ -111,13 +110,10 @@ impl HashTrieMapPy {
self.inner.contains_key(&key)
}

fn __iter__(slf: PyRef<'_, Self>) -> PyResult<Py<KeyIterator>> {
Py::new(
slf.py(),
KeyIterator {
inner: slf.keys().into_iter(),
},
)
fn __iter__(slf: PyRef<'_, Self>) -> KeyIterator {
KeyIterator {
inner: slf.inner.clone(),
}
}

fn __getitem__(&self, key: Key) -> PyResult<PyObject> {
Expand Down Expand Up @@ -274,7 +270,7 @@ impl HashTrieMapPy {

#[pyclass(module = "rpds")]
struct KeyIterator {
inner: IntoIter<Key>,
inner: HashTrieMapSync<Key, PyObject>,
}

#[pymethods]
Expand All @@ -284,7 +280,9 @@ impl KeyIterator {
}

fn __next__(mut slf: PyRefMut<'_, Self>) -> Option<Key> {
slf.inner.next()
let first = slf.inner.keys().next()?.to_owned();
slf.inner = slf.inner.remove(&first);
Some(first)
}
}

Expand Down

0 comments on commit f3d713c

Please sign in to comment.