Repository: buyalsky/ordered-hash-set

Issue:
Returning indexes 
OrderedSet's `add` method should return index of the added item. If the item is already in the OrderedSet instance, the method should return the index it already had.
Similarly, `remove` method should return index of the removed item.

Example:
```python3
s = OrderedSet()
s.add('Foo') # Should return 0
s.add('Bar') # Should return 1
s.add('Foo') # Should return 0 since 'Foo' is already in OrderedSet and its index is 0
s.remove('Bar') # Should return 1
```

Discussion:

Patch:
diff --git a/src/ordered_hash_set.py b/src/ordered_hash_set.py
index 27ae04b..95a4647 100644
--- a/src/ordered_hash_set.py
+++ b/src/ordered_hash_set.py
@@ -9,6 +9,7 @@ class OrderedSet:
     def add(self, item):
         """
         Adds the item to set if it is not exist.
+        Returns the index of added item (or already existing item) in the respective set.
         Raises TypeError if specified item is not hashable
 
         :param item: (object), item to be added.
@@ -21,6 +22,9 @@ class OrderedSet:
             if len(self._items) != 1:
                 self._items[self._last][1][1] = item
             self._last = item
+            return self.__len__() - 1
+        else:
+            return self.get_all().index(item)
 
     def update(self, *items):
         """
@@ -35,10 +39,12 @@ class OrderedSet:
     def remove(self, item):
         """
         Removes given item from set.
-        Raises KeyError if item is not found.
+        Returns the used index of the removed item in the respective set.
+        Raises ValueError if item is not found.
 
         :param item: (object), Removed item
         """
+        index = self.get_all().index(item)
         removed_item = self._items.pop(item)
         previous_item, next_item = removed_item[1]
         if item == self._first:
@@ -54,6 +60,7 @@ class OrderedSet:
                 self._items[previous_item][1][1] = next_item
             if next_item:
                 self._items[next_item][1][0] = previous_item
+        return index
 
     def remove_all(self, *items):
         """


Test patch:
diff --git a/src/tests/test_cases.py b/src/tests/test_cases.py
index 592e97d..8f3bfee 100644
--- a/src/tests/test_cases.py
+++ b/src/tests/test_cases.py
@@ -34,39 +34,33 @@ def test_remove(filled_set):
     filled_set.remove_all(4, 6)
     print(filled_set)
     assert filled_set == OrderedSet(1, 2, 3, 5, "str")
-    with pytest.raises(KeyError):
+    with pytest.raises(ValueError):
         filled_set.remove(-1)
 
 
 def test_remove_first(filled_set):
-    filled_set.remove(1)
+    assert 0 == filled_set.remove(1)
     assert filled_set[0] == 2
     assert filled_set == OrderedSet(2, 3, 4, 5, 6)
 
 
 def test_remove_last(filled_set):
-    filled_set.remove(6)
+    assert 5 == filled_set.remove(6)
     assert filled_set[-1] == 5
 
 
 def test_add_remove_mixed(filled_set):
-    filled_set.remove(1)
+    assert 0 == filled_set.remove(1)
     assert filled_set[0] == 2
     assert filled_set == OrderedSet(2, 3, 4, 5, 6)
-    filled_set.remove(6)
+    assert 4 == filled_set.remove(6)
     assert filled_set == OrderedSet(2, 3, 4, 5)
-    filled_set.add(7)
+    assert 4 == filled_set.add(7)
     assert filled_set == OrderedSet(2, 3, 4, 5, 7)
 
 
 def test_len(filled_set):
-    s = OrderedSet()
-    s.add(1)
-    s.add(1)
-    s.add(1)
-    s.add(2)
-    s.add(3)
-    s.remove(1)
+    s = OrderedSet(1, 3)
     assert len(s) == 2
     assert len(filled_set) == 6