lib: remove specialization link between Map and Sequence
authorJean Privat <jean@pryen.org>
Fri, 10 Feb 2012 14:08:43 +0000 (09:08 -0500)
committerJean Privat <jean@pryen.org>
Mon, 13 Feb 2012 19:04:31 +0000 (14:04 -0500)
IndexedIterator#key and Sequence#has_key are not maintained

Signed-off-by: Jean Privat <jean@pryen.org>

examples/circular_list.nit
lib/standard/collection/abstract_collection.nit
lib/standard/collection/array.nit
lib/standard/collection/list.nit
tests/sav/test_list.sav
tests/test_list.nit

index 8b99d48..86e41f6 100644 (file)
@@ -124,7 +124,7 @@ end
 private class CircularListIterator[E]
        super IndexedIterator[E]
 
-       redef var key: Int
+       redef var index: Int
 
        # The current node pointed.
        # Is null if the list is empty.
@@ -137,13 +137,13 @@ private class CircularListIterator[E]
        do
                # Empty lists are not OK.
                # Pointing again the first node is not OK.
-               return self.node != null and (self.key == 0 or self.node != self.list.node)
+               return self.node != null and (self.index == 0 or self.node != self.list.node)
        end
 
        redef fun next
        do
                self.node = self.node.next
-               self.key += 1
+               self.index += 1
        end
 
        redef fun item do return self.node.item
@@ -152,7 +152,7 @@ private class CircularListIterator[E]
        do
                self.node = list.node
                self.list = list
-               self.key = 0
+               self.index = 0
        end
 end
 
index 6f9693b..f3b92f4 100644 (file)
@@ -295,7 +295,7 @@ end
 # Indexed collection are ordoned collections.
 # The first item is 0. The last is `length'-1.
 interface SequenceRead[E]
-       super MapRead[Int, E]
+       super Collection[E]
        # Get the first item.
        # Is equivalent with `self'[0].
        redef fun first
@@ -303,7 +303,9 @@ interface SequenceRead[E]
                assert not_empty: not is_empty
                return self[0]
        end
-       
+
+       fun [](index: Int): E is abstract
+
        # Get the last item.
        # Is equivalent with `self'[`length'-1].
        fun last: E
@@ -331,7 +333,6 @@ end
 # The first item is 0. The last is `length'-1.
 interface Sequence[E]
        super SequenceRead[E]
-       super Map[Int, E]
        super SimpleCollection[E]
        # Set the first item.
        # Is equivalent with `self'[0] = `item'.
@@ -369,16 +370,18 @@ interface Sequence[E]
        # The second item become the first.
        fun shift: E is abstract
 
+       # Set the`item' at `index'.
+       fun []=(index: Int, item: E) is abstract
+
+       # Remove the item at `index' and shift all following elements
+       fun remove_at(index: Int) is abstract
 end
 
 # Iterators on indexed collections.
 interface IndexedIterator[E]
-       super MapIterator[Int, E]
+       super Iterator[E]
        # The index of the current item.
        fun index: Int is abstract
-
-       # A synonym of index.
-       redef fun key do return index
 end
 
 # Associatives arrays that internally uses couples to represent each (key, value) pairs.
index 133ea5b..1f96dd4 100644 (file)
@@ -47,8 +47,6 @@ class AbstractArrayRead[E]
                return true
        end
 
-       redef fun has_key(index) do return index >= 0 and index < length
-
        redef fun count(item)
        do
                var res = 0
index d032066..40514fc 100644 (file)
@@ -76,8 +76,6 @@ class List[E]
                return nb
        end
 
-       redef fun has_key(index) do return get_node(index) != null
-
 # Add elements
 
        # O(1)
index ae897a3..aeefd2b 100644 (file)
@@ -7,7 +7,4 @@ true
 true
 true
 true
-true
-true
-true
 -12-35-6
index fe5e79b..a54713e 100644 (file)
@@ -52,9 +52,6 @@ do
     print(l)
     print(l.has(3))
     print(not l.has(9))
-    print(l.has_key(3))
-    print(not l.has_key(-3))
-    print(not l.has_key(30))
     print(l[1] == 2)
     print(l.first == 1)
     print(l.last == 6)