Commit 0071c4e2 authored by Xavier Thompson's avatar Xavier Thompson

Fix cypclass dict __delitem__ implementation

parent 8f09af4d
......@@ -167,7 +167,7 @@ cdef cypclass cypdict[K, V]:
index = dereference(it).second
self._indices.erase(it)
if index < self._items.size() - 1:
self._items[index] = self._items[self._indices.size() - 1]
self._items[index] = self._items[self._items.size() - 1]
self._items.pop_back()
void update(self, const cypdict[K, V] other) except ~:
......
......@@ -147,6 +147,39 @@ def test_len():
return -2
return 0
def test_delitem():
"""
>>> test_delitem()
(1, 10)
(2, 20)
(3, 30)
(4, 40)
(5, 50)
-------
(1, 10)
(2, 20)
(5, 50)
(4, 40)
-------
(4, 40)
(2, 20)
(5, 50)
"""
d = cypdict[int, int]()
for i in range(1, 7):
d[i] = i * 10
del d[6]
for item in d.items():
print(item)
print("-------")
del d[3]
for item in d.items():
print(item)
print("-------")
del d[1]
for item in d.items():
print(item)
def test_clear():
"""
>>> test_clear()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment