Ranides Atterwim преди 11 години
родител
ревизия
6561b7ea35

+ 0 - 12
assira/src/main/java/net/ranides/assira/collection/maps/AMap.java

@@ -45,18 +45,6 @@ public abstract class AMap<K, V> implements Map<K, V>, java.io.Serializable {
         // do nothing
     }
 
-    @Override
-    @SuppressWarnings("element-type-mismatch")
-    public boolean containsValue(Object value) {
-        return values().contains(value);
-    }
-
-    @Override
-    @SuppressWarnings("element-type-mismatch")
-    public boolean containsKey(Object key) {
-        return keySet().contains(key);
-    }
-
     /**
      * Puts all pairs in the given map. If the map implements the interface of
      * this map, it uses the faster iterators.

+ 16 - 98
assira/src/main/java/net/ranides/assira/collection/maps/AVLTreeMap.java

@@ -170,12 +170,12 @@ public final class AVLTreeMap<K, V> extends ASortedMap<K, V> implements java.io.
 
     @Override
     protected ListIterator<Entry<K, V>> entryIterator() {
-        return new EntryIterator();
+        return new TreeIterator();
     }
     
     @Override
     protected ListIterator<Entry<K, V>> entryIterator(K begin) {
-        return new EntryIterator(begin);
+        return new TreeIterator(begin);
     }
     
     @Override
@@ -661,10 +661,10 @@ public final class AVLTreeMap<K, V> extends ASortedMap<K, V> implements java.io.
     
     private void writeObject(java.io.ObjectOutputStream ostream) throws java.io.IOException {
         int n = count;
-        EntryIterator iterator = new EntryIterator();
+        TreeIterator iterator = new TreeIterator();
         ostream.defaultWriteObject();
         while (n-- != 0) {
-            AVLEntry<K, V> entry = iterator.nextEntry();
+            AVLEntry<K, V> entry = iterator.next();
             ostream.writeObject(entry.key);
             ostream.writeObject(entry.value);
         }
@@ -1062,12 +1062,12 @@ public final class AVLTreeMap<K, V> extends ASortedMap<K, V> implements java.io.
 
         @Override
         protected ListIterator<Entry<K, V>> entryIterator() {
-            return new SubmapEntryIterator();
+            return new SubTreeIterator();
         }
         
         @Override
         protected ListIterator<Entry<K, V>> entryIterator(K begin) {
-            return new SubmapEntryIterator(begin);
+            return new SubTreeIterator(begin);
         }
 
         @Override
@@ -1143,13 +1143,13 @@ public final class AVLTreeMap<K, V> extends ASortedMap<K, V> implements java.io.
          * with
          * <code>null</code>.
          */
-        private abstract class SubmapIterator<T> extends TreeIterator<T> {
+        private class SubTreeIterator extends TreeIterator {
 
-            SubmapIterator() {
+            SubTreeIterator() {
                 next = firstEntry();
             }
 
-            SubmapIterator(K key) {
+            SubTreeIterator(K key) {
                 this();
                 if (next != null) {
                     if (!bottom && compare(key, next.key) < 0) {
@@ -1185,36 +1185,6 @@ public final class AVLTreeMap<K, V> extends ASortedMap<K, V> implements java.io.
             }
         }
 
-        private class SubmapEntryIterator extends SubmapIterator<Entry<K, V>> {
-
-            SubmapEntryIterator() {
-            }
-
-            SubmapEntryIterator(K key) {
-                super(key);
-            }
-
-            @Override
-            public Entry<K, V> next() {
-                return nextEntry();
-            }
-
-            @Override
-            public Entry<K, V> previous() {
-                return previousEntry();
-            }
-
-            @Override
-            public void set(Entry<K, V> object) {
-                throw new UnsupportedOperationException();
-            }
-
-            @Override
-            public void add(Entry<K, V> object) {
-                throw new UnsupportedOperationException();
-            }
-        }
-
     }
 
     /**
@@ -1222,30 +1192,11 @@ public final class AVLTreeMap<K, V> extends ASortedMap<K, V> implements java.io.
      *
      * <P>This class can iterate in both directions on a threaded tree.
      */
-    private abstract class TreeIterator<T> extends AListIterator<T> {
+    private class TreeIterator extends AListIterator<Entry<K, V>> {
 
-        /**
-         * The entry that will be returned by the next call end
- {@link java.util.ListIterator#previous()} (or
-         * <code>null</code> if no previous entry exists).
-         */
         AVLEntry<K, V> prev;
-        /**
-         * The entry that will be returned by the next call end
- {@link java.util.ListIterator#next()} (or
-         * <code>null</code> if no next entry exists).
-         */
         AVLEntry<K, V> next;
-        /**
-         * The last entry that was returned (or
-         * <code>null</code> if we did not iterate or used {@link #remove()}).
-         */
         AVLEntry<K, V> curr;
-        /**
-         * The current index (in the sense of a {@link java.util.ListIterator}).
-         * Note that this value is not meaningful when this {@link TreeIterator}
-         * has been created using the nonempty constructor.
-         */
         int index = 0;
 
         TreeIterator() {
@@ -1277,7 +1228,8 @@ public final class AVLTreeMap<K, V> extends ASortedMap<K, V> implements java.io.
             next = next.next();
         }
 
-        AVLEntry<K, V> nextEntry() {
+        @Override
+        public AVLEntry<K, V> next() {
             if (!hasNext()) {
                 throw new NoSuchElementException();
             }
@@ -1291,7 +1243,8 @@ public final class AVLTreeMap<K, V> extends ASortedMap<K, V> implements java.io.
             prev = prev.prev();
         }
 
-        AVLEntry<K, V> previousEntry() {
+        @Override
+        public AVLEntry<K, V> previous() {
             if (!hasPrevious()) {
                 throw new NoSuchElementException();
             }
@@ -1331,7 +1284,7 @@ public final class AVLTreeMap<K, V> extends ASortedMap<K, V> implements java.io.
         public int skip(int n) {
             int i = n;
             while (i-- != 0 && hasNext()) {
-                nextEntry();
+                next();
             }
             return n - i - 1;
         }
@@ -1339,45 +1292,10 @@ public final class AVLTreeMap<K, V> extends ASortedMap<K, V> implements java.io.
         public int back(int n) {
             int i = n;
             while (i-- != 0 && hasPrevious()) {
-                previousEntry();
+                previous();
             }
             return n - i - 1;
         }
     }
 
-    /**
-     * An iterator on the whole range.
-     *
-     * <P>This class can iterate in both directions on a threaded tree.
-     */
-    private class EntryIterator extends TreeIterator<Entry<K, V>> {
-
-        EntryIterator() {
-        }
-
-        EntryIterator(K key) {
-            super(key);
-        }
-
-        @Override
-        public Entry<K, V> next() {
-            return nextEntry();
-        }
-
-        @Override
-        public Entry<K, V> previous() {
-            return previousEntry();
-        }
-
-        @Override
-        public void set(Entry<K, V> object) {
-            throw new UnsupportedOperationException();
-        }
-
-        @Override
-        public void add(Entry<K, V> object) {
-            throw new UnsupportedOperationException();
-        }
-    }
-
 }

Файловите разлики са ограничени, защото са твърде много
+ 71 - 965
assira/src/main/java/net/ranides/assira/collection/maps/IntAVLTreeMap.java


Файловите разлики са ограничени, защото са твърде много
+ 971 - 1013
assira/src/main/java/net/ranides/assira/collection/maps/IntHashMap.java


+ 5 - 13
assira/src/main/java/net/ranides/assira/collection/maps/IntMap.java

@@ -40,15 +40,7 @@ public abstract class IntMap<V> implements Map<Integer, V>, java.io.Serializable
         // do nothing
     }
 
-    @Override
-    @SuppressWarnings("element-type-mismatch")
-    public boolean containsValue(Object value) {
-        return values().contains(value);
-    }
-
-    public boolean containsKey(int k) {
-        return keySet().contains(k);
-    }
+    public abstract boolean containsKey(int k);
 
     @SuppressWarnings("unchecked")
     @Override
@@ -313,22 +305,22 @@ public abstract class IntMap<V> implements Map<Integer, V>, java.io.Serializable
     }
 
     @Override
-    public boolean containsKey(Object key) {
+    public final boolean containsKey(Object key) {
         return containsKey(((Integer) key).intValue());
     }
 
     @Override
-    public V get(Object key) {
+    public final V get(Object key) {
         return get( ((Integer)key).intValue() );
     }
 
     @Override
-    public V put(Integer key, V value) {
+    public final V put(Integer key, V value) {
         return put( key.intValue(), value);
     }
 
     @Override
-    public V remove(Object key) {
+    public final V remove(Object key) {
         return remove( ((Integer)key).intValue() );
     }
 

Файловите разлики са ограничени, защото са твърде много
+ 83 - 1021
assira/src/main/java/net/ranides/assira/collection/maps/IntRBTreeMap.java


+ 443 - 60
assira/src/main/java/net/ranides/assira/collection/maps/IntSortedMap.java

@@ -8,13 +8,16 @@ package net.ranides.assira.collection.maps;
 
 import net.ranides.assira.collection.sets.IntSortedSet;
 import java.util.Collection;
+import java.util.Comparator;
 import java.util.Iterator;
+import java.util.ListIterator;
 import java.util.Map;
 import java.util.SortedMap;
 import net.ranides.assira.collection.ACollection;
 import net.ranides.assira.collection.sets.ASortedSet;
 import net.ranides.assira.collection.IntComparator;
 import net.ranides.assira.collection.iterators.IntIterator;
+import net.ranides.assira.generic.ValueUtils;
 
 /**
  * An abstract base class for sorted maps with primitive int key. 
@@ -23,25 +26,136 @@ import net.ranides.assira.collection.iterators.IntIterator;
 public abstract class IntSortedMap<V> extends IntMap<V> implements SortedMap<Integer, V> {
 
     private static final long serialVersionUID = 2L;
+    
+    /**
+     * This map's comparator, as provided in the constructor.
+     */
+    private final Comparator<? super Integer> scmp;
+    /**
+     * This map's actual comparator; it may differ from
+     * {@link #scmp} because it is always a type-specific
+     * comparator, so it could be derived from the former by wrapping.
+     */
+    private transient IntComparator acmp;
+    
+    /**
+     * The value of this variable remembers, after a
+     * <code>put()</code> or a
+     * <code>remove()</code>, whether the <em>domain</em> of the map has been
+     * modified.
+     */
+    protected transient boolean modified;
+
+    protected IntSortedMap(Comparator<? super Integer> comparator) {
+        scmp = comparator;
+        acmp = IntComparator.wrap(scmp);
+    }
+    
+        
+    /**
+     * Returns the entry corresponding to the given key, if it is in the tree;
+     * <code>null</code>, otherwise.
+     *
+     * @param k the key to search for.
+     * @return the corresponding entry, or <code>null</code> if no entry with
+     * the given key exists.
+     */
+    protected abstract IntEntry<V> findEntry(int k);
+
+    /**
+     * Locates a key.
+     *
+     * @param k a key.
+     * @return the last entry on a search for the given key; this will be the
+     * given key, if it present; otherwise, it will be either the smallest
+     * greater key or the greatest smaller key.
+     */
+    protected abstract IntEntry<V> locateEntry(int k);
+    
+    protected abstract IntEntry<V> firstEntry();
+
+    protected abstract IntEntry<V> lastEntry();
+    
+    protected abstract ListIterator<IntEntry<V>> fastEntryIterator();
+    
+    protected abstract ListIterator<IntEntry<V>> fastEntryIterator(int key);
+
+    protected abstract IntSortedMap<V> submap(int begin, boolean bottom, int end, boolean top);
+
+    
+    protected final int compare(int a, int b) {
+        return ValueUtils.cmp(acmp, a, b);
+    }
+    
+    protected final int lower(int a, int b) {
+        return ValueUtils.lower(acmp, a, b);
+    }
+    
+    protected final int higher(int a, int b) {
+        return ValueUtils.higher(acmp, a, b);
+    }
+    
+    
+    /**
+     * Returns a view of the portion of this sorted map whose keys are strictly
+     * less than <code>toKey</code>.
+     *
+     * @see SortedMap#headMap(Object)
+     */
+    public IntSortedMap<V> headMap(int end) {
+        return submap(0, true, end, false);
+    }
 
-    protected IntSortedMap() {
-        // do nothing
+    /**
+     * Returns a view of the portion of this sorted map whose keys are greater
+     * than or equal to <code>fromKey</code>.
+     *
+     * @see SortedMap#tailMap(Object)
+     */
+    public IntSortedMap<V> tailMap(int begin) {
+        return submap(begin, false, 0, true);
+    }
+    
+    /**
+     * Returns a view of the portion of this sorted map whose keys range from
+     * <code>fromKey</code>, inclusive, to <code>toKey</code>, exclusive.
+     *
+     * @see SortedMap#subMap(Object,Object)
+     */
+    public IntSortedMap<V> subMap(int begin, int end) {
+        return submap(begin, false, end, false);
     }
 
+    
     @Override
-    public final IntSortedMap<V> headMap(Integer toKey) {
-        return headMap(toKey.intValue());
+    public final IntSortedMap<V> headMap(Integer end) {
+        return submap(0, true, end, false);
     }
 
     @Override
-    public final IntSortedMap<V> tailMap(Integer fromKey) {
-        return tailMap(fromKey.intValue());
+    public final IntSortedMap<V> tailMap(Integer begin) {
+        return submap(begin, false, 0, true);
     }
 
     @Override
-    public final IntSortedMap<V> subMap(Integer fromKey, Integer toKey) {
-        return subMap(fromKey.intValue(), toKey.intValue());
+    public final IntSortedMap<V> subMap(Integer begin, Integer end) {
+        return submap(begin, false, end, false);
     }
+    
+    /**
+     * @see SortedMap#firstKey()
+     */
+    public final int firstIntKey() {
+        return firstEntry().getIntKey();
+    }
+
+    /**
+     * @see SortedMap#lastKey()
+     */
+    public final int lastIntKey() {
+        return lastEntry().getIntKey();
+    }
+    
 
     @Override
     public final Integer firstKey() {
@@ -54,21 +168,52 @@ public abstract class IntSortedMap<V> extends IntMap<V> implements SortedMap<Int
     }
 
     @Override
-    public IntSortedSet keySet() {
+    public final IntSortedSet keySet() {
         return new KeySet();
     }
 
     @Override
-    public Collection<V> values() {
+    public final Collection<V> values() {
         return new ValuesCollection();
     }
 
     @SuppressWarnings({"unchecked", "rawtypes"})
     @Override
-    public ASortedSet<Map.Entry<Integer, V>> entrySet() {
+    public final ASortedSet<Map.Entry<Integer, V>> entrySet() {
         return (ASortedSet) fastEntrySet();
     }
 
+    @Override
+    public final boolean containsKey(int key) {
+        return null != findEntry(key);
+    }
+    
+    @Override
+    public final boolean containsValue(Object value) {
+        final Iterator<IntEntry<V>> i = fastEntryIterator();
+        int j = size();
+        while (j-- != 0) {
+            IntEntry<V> entry = i.next();
+            if( ValueUtils.equals(value, entry.getValue())) {
+                return true;
+            }
+        }
+        return false;
+    }
+    
+    @SuppressWarnings("unchecked")
+    @Override
+    public final V get(int key) {
+        IntEntry<V> entry = findEntry(key);
+        return entry == null ? defRetValue : entry.getValue();
+    }
+    
+    private void readObject(java.io.ObjectInputStream istream) throws java.io.IOException, ClassNotFoundException {
+        istream.defaultReadObject();
+        // we must restore on-the-fly the actualComparator
+        acmp = IntComparator.wrap(scmp);
+    }
+
     /**
      * Returns a type-specific sorted-set view of the mappings contained in this
      * map. Note that this specification strengthens the one given in the
@@ -79,8 +224,10 @@ public abstract class IntSortedMap<V> extends IntMap<V> implements SortedMap<Int
      * @see #entrySet()
      */
     @Override
-    public abstract ASortedSet<IntMap.IntEntry<V>> fastEntrySet();
-
+    public final ASortedSet<IntMap.IntEntry<V>> fastEntrySet() {
+        return new EntrySet();
+    }
+    
     /**
      * Returns the comparator associated with this sorted set, or null if it
      * uses its keys' natural ordering.
@@ -91,42 +238,10 @@ public abstract class IntSortedMap<V> extends IntMap<V> implements SortedMap<Int
      * @see SortedMap#comparator()
      */
     @Override
-    public abstract IntComparator comparator();
-
-    /**
-     * Returns a view of the portion of this sorted map whose keys range from
-     * <code>fromKey</code>, inclusive, to <code>toKey</code>, exclusive.
-     *
-     * @see SortedMap#subMap(Object,Object)
-     */
-    public abstract IntSortedMap<V> subMap(int begin, int end);
-
-    /**
-     * Returns a view of the portion of this sorted map whose keys are strictly
-     * less than <code>toKey</code>.
-     *
-     * @see SortedMap#headMap(Object)
-     */
-    public abstract IntSortedMap<V> headMap(int end);
-
-    /**
-     * Returns a view of the portion of this sorted map whose keys are greater
-     * than or equal to <code>fromKey</code>.
-     *
-     * @see SortedMap#tailMap(Object)
-     */
-    public abstract IntSortedMap<V> tailMap(int begin);
-
-    /**
-     * @see SortedMap#firstKey()
-     */
-    public abstract int firstIntKey();
+    public IntComparator comparator() {
+        return acmp;
+    }
 
-    /**
-     * @see SortedMap#lastKey()
-     */
-    public abstract int lastIntKey();
-    
     /**
      * A wrapper exhibiting the keys of a map.
      */
@@ -196,20 +311,20 @@ public abstract class IntSortedMap<V> extends IntMap<V> implements SortedMap<Int
      */
     protected static class KeySetIterator<V> extends IntIterator {
 
-        protected final Iterator<Map.Entry<Integer, V>> riv;
+        private final Iterator<Map.Entry<Integer, V>> adapter;
 
         public KeySetIterator(Iterator<Map.Entry<Integer, V>> riv) {
-            this.riv = riv;
+            this.adapter = riv;
         }
 
         @Override
         public int nextInt() {
-            return riv.next().getKey();
+            return adapter.next().getKey();
         }
 
         @Override
         public boolean hasNext() {
-            return riv.hasNext();
+            return adapter.hasNext();
         }
     }
 
@@ -220,7 +335,7 @@ public abstract class IntSortedMap<V> extends IntMap<V> implements SortedMap<Int
 
         @Override
         public Iterator<V> iterator() {
-            return new ValuesIterator<>(entrySet().iterator());
+            return new ValuesIterator<>(fastEntryIterator());
         }
 
         @Override
@@ -246,29 +361,297 @@ public abstract class IntSortedMap<V> extends IntMap<V> implements SortedMap<Int
      * <P>To provide an iterator on values, just create an instance of this
      * class using the corresponding iterator on entries.
      */
-    protected static class ValuesIterator<V> implements Iterator<V> {
+    protected static class ValuesIterator<V> implements ListIterator<V> {
 
-        private final Iterator<Map.Entry<Integer, V>> riv;
+        private final ListIterator<IntEntry<V>> adapter;
 
-        public ValuesIterator(Iterator<Map.Entry<Integer, V>> riv) {
-            this.riv = riv;
+        public ValuesIterator(ListIterator<IntEntry<V>> riv) {
+            this.adapter = riv;
         }
 
         @Override
         public V next() {
-            return riv.next().getValue();
+            return adapter.next().getValue();
         }
-
+        
         @Override
         public boolean hasNext() {
-            return riv.hasNext();
+            return adapter.hasNext();
+        }
+
+        @Override
+        public int nextIndex() {
+            return adapter.nextIndex();
         }
 
+        @Override
+        public V previous() {
+            return adapter.previous().getValue();
+        }
+
+        @Override
+        public boolean hasPrevious() {
+            return adapter.hasPrevious();
+        }
+
+        @Override
+        public int previousIndex() {
+            return adapter.previousIndex();
+        }
+
+        @Override
+        public void set(V value) {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        public void add(V value) {
+            throw new UnsupportedOperationException();
+        }
+        
         @Override
         public void remove() {
             throw new UnsupportedOperationException();
         }
     }
+    
+    protected class EntrySet extends ASortedSet<IntEntry<V>> {
+        
+        private final Comparator<? super IntEntry<V>> comparator = new Comparator<IntEntry<V>>() {
+            @Override
+            public int compare(IntEntry<V> entry1, IntEntry<V> entry2) {
+                return IntSortedMap.this.compare(entry1.getIntKey(), entry2.getIntKey());
+            }
+        };
+
+        @Override
+        public final Comparator<? super IntEntry<V>> comparator() {
+            return comparator;
+        }
+
+        @Override
+        public Iterator<IntEntry<V>> iterator() {
+            return IntSortedMap.this.fastEntryIterator();
+        }
+
+        @Override
+        public Iterator<IntEntry<V>> iterator(IntEntry<V> from) {
+            return IntSortedMap.this.fastEntryIterator(from.getIntKey());
+        }
+
+        @SuppressWarnings("unchecked")
+        @Override
+        public boolean contains(Object object) {
+            if (!(object instanceof Map.Entry)) {
+                return false;
+            }
+            Map.Entry<Integer, V> entry = (Map.Entry<Integer, V>) object;
+            return entry.equals(findEntry(entry.getKey()));
+        }
+
+        @SuppressWarnings("unchecked")
+        @Override
+        public boolean remove(Object object) {
+            if (!(object instanceof Map.Entry)) {
+                return false;
+            }
+            final Map.Entry<Integer, V> entry = (Map.Entry<Integer, V>) object;
+            final IntEntry<V> found = findEntry(entry.getKey());
+            if (found != null) {
+                IntSortedMap.this.remove(found.getIntKey());
+            }
+            return found != null;
+        }
+
+        @Override
+        public int size() {
+            return IntSortedMap.this.size();
+        }
+
+        @Override
+        public void clear() {
+            IntSortedMap.this.clear();
+        }
+
+        @Override
+        public IntEntry<V> first() {
+            return firstEntry();
+        }
+
+        @Override
+        public IntEntry<V> last() {
+            return lastEntry();
+        }
+
+        @Override
+        public ASortedSet<IntEntry<V>> subSet(IntEntry<V> begin, IntEntry<V> end) {
+            return subMap(begin.getIntKey(), end.getIntKey()).fastEntrySet();
+        }
+
+        @Override
+        public ASortedSet<IntEntry<V>> headSet(IntEntry<V> end) {
+            return headMap(end.getIntKey()).fastEntrySet();
+        }
+
+        @Override
+        public ASortedSet<IntEntry<V>> tailSet(IntEntry<V> begin) {
+            return tailMap(begin.getIntKey()).fastEntrySet();
+        }
+    }
+
+    /**
+     * A submap with given range.
+     *
+     * <P>This class represents a submap. One has end specify the left/right
+     * limits (which can be set end -&infin; or &infin;). Since the submap is a
+     * view on the map, at a given moment it could happen that the limits of the
+     * range are not any longer in the main map. Thus, things such as
+     * {@link java.util.SortedMap#firstKey()} or
+     * {@link java.util.Collection#size()} must be always computed on-the-fly.
+     */
+    protected abstract class ASubmap extends IntSortedMap<V> implements java.io.Serializable {
+
+        private static final long serialVersionUID = 1L;
+        
+        /**
+         * The start of the submap range, unless {@link #bottom} is true.
+         */
+        int begin;
+        /**
+         * The end of the submap range, unless {@link #top} is true.
+         */
+        int end;
+        /**
+         * If true, the submap range starts begin -&infin;.
+         */
+        boolean bottom;
+        /**
+         * If true, the submap range goes end &infin;.
+         */
+        boolean top;
+        
+        /**
+         * Creates a new submap with given key range.
+         *
+         * @param begin the start of the submap range.
+         * @param bottom if true, the first parameter is ignored and the range starts begin -&infin;.
+         * @param end the end of the submap range.
+         * @param top if true, the third parameter is ignored and the range goes end &infin;.
+         */
+        public ASubmap(int begin, boolean bottom, int end, boolean top) {
+            super(IntSortedMap.this.acmp);
+            if (!bottom && !top && ValueUtils.cmp(acmp, begin, end) > 0) {
+                throw new IllegalArgumentException("Start key (" + begin + ") is larger than end key (" + end + ")");
+            }
+            this.begin = begin;
+            this.bottom = bottom;
+            this.end = end;
+            this.top = top;
+            this.defRetValue = IntSortedMap.this.defRetValue;
+        }
+        
+        @Override
+        protected abstract IntEntry<V> findEntry(int key);
+
+        @Override
+        protected abstract IntEntry<V> locateEntry(int key);
+        
+        @Override
+        protected abstract IntEntry<V> firstEntry();
+
+        @Override
+        protected abstract IntEntry<V> lastEntry();
+        
+        @Override
+        protected abstract ListIterator<IntEntry<V>> fastEntryIterator();
+        
+        @Override
+        protected abstract ListIterator<IntEntry<V>> fastEntryIterator(int begin);
+
+        protected final boolean inside(int key) {
+            return (bottom || compare(key, begin) >= 0) && (top || compare(key, end) < 0);
+        }
 
+        @Override
+        public final void clear() {
+            ListIterator<IntEntry<V>> iterator = fastEntryIterator();
+            while (iterator.hasNext()) {
+                iterator.next();
+                iterator.remove();
+            }
+        }
+
+        @Override
+        public final V put(int key, V value) {
+            if (!inside(key)) {
+                throw new IllegalArgumentException("Key (" + key + ") out of range [" + (bottom ? "-" : String.valueOf(begin)) + ", " + (top ? "-" : String.valueOf(end)) + ")");
+            }
+            return IntSortedMap.this.put(key, value);
+        }
+
+        @SuppressWarnings("unchecked")
+        @Override
+        public final V remove(int key) {
+            if (!inside(key)) {
+                return IntSortedMap.this.defRetValue;
+            }
+            return IntSortedMap.this.remove(key);
+        }
+
+        @Override
+        public final int size() {
+            ListIterator<IntEntry<V>> iterator = fastEntryIterator();
+            int n = 0;
+            while (iterator.hasNext()) {
+                n++;
+                iterator.next();
+            }
+            return n;
+        }
+
+        @Override
+        public final boolean isEmpty() {
+            return !fastEntryIterator().hasNext();
+        }
+
+        @Override
+        public final IntSortedMap<V> headMap(int end) {
+            if (top) {
+                return submap(begin, bottom, end, false);
+            }
+            return ValueUtils.cmp(acmp, end, this.end) < 0 ? submap(begin, bottom, end, false) : this;
+        }
+
+        @Override
+        public final IntSortedMap<V> tailMap(int begin) {
+            if (bottom) {
+                return submap(begin, false, end, top);
+            }
+            return ValueUtils.cmp(acmp, begin, this.begin) > 0 ? submap(begin, false, end, top) : this;
+        }
+
+        @Override
+        public final IntSortedMap<V> subMap(int begin, int end) {
+            if (top && bottom) {
+                return submap(begin, false, end, false);
+            }
+            if (!top) {
+                end = lower(end, this.end);
+            }
+            if (!bottom) {
+                begin = higher(begin, this.begin);
+            }
+            if (!top && !bottom && begin == this.begin && end == this.end) {
+                return this;
+            }
+            return submap(begin, false, end, false);
+        }
+        
+        @Override
+        protected final IntSortedMap<V> submap(int begin, boolean bottom, int end, boolean top) {
+            return IntSortedMap.this.submap(begin, bottom, end, top);
+        }
+        
+    }
   
 }

+ 1 - 1
assira/src/main/java/net/ranides/assira/collection/sets/AVLTreeSet.java

@@ -35,7 +35,7 @@ import net.ranides.assira.generic.ValueUtils;
  * Moreover, the iterator returned by
  * <code>iterator()</code> can be safely cast end a type-specific
  {@linkplain java.util.ListIterator list iterator}.
- * @todo (assira # 6) review.avl 
+ * @todo (assira # 4) review.avl 
  */
 public class AVLTreeSet<K> extends ASortedSet<K> implements java.io.Serializable {
 

+ 1 - 1
assira/src/main/java/net/ranides/assira/collection/sets/IntAVLTreeSet.java

@@ -39,7 +39,7 @@ import net.ranides.assira.generic.ValueUtils;
  * Moreover, the iterator returned by
  * <code>iterator()</code> can be safely cast end a type-specific
  {@linkplain java.util.ListIterator list iterator}.
- * @todo (assira # 6) review.avl 
+ * @todo (assira # 5) review.avl 
  */
 @SuppressWarnings({
     "PMD.AvoidReassigningParameters",

+ 1 - 1
assira/src/main/java/net/ranides/assira/collection/sets/IntRBTreeSet.java

@@ -40,7 +40,7 @@ import net.ranides.assira.generic.ValueUtils;
  * Moreover, the iterator returned by
  * <code>iterator()</code> can be safely cast to a type-specific
  * {@linkplain java.util.ListIterator list iterator}.
- * @todo (assira # 6) review.rb 
+ * @todo (assira # 5) review.rb 
  */
 @SuppressWarnings({
     "PMD.AvoidReassigningParameters",

+ 1 - 1
assira/src/main/java/net/ranides/assira/collection/sets/RBTreeSet.java

@@ -36,7 +36,7 @@ import net.ranides.assira.generic.ValueUtils;
  * Moreover, the iterator returned by
  * <code>iterator()</code> can be safely cast end a type-specific
  {@linkplain java.util.ListIterator list iterator}.
- * @todo (assira # 6) review.rb 
+ * @todo (assira # 4) review.rb 
  */
 @SuppressWarnings({
     "PMD.AvoidReassigningParameters"

+ 1 - 1
assira/src/test/java/net/ranides/assira/collection/DummyTest.java

@@ -12,7 +12,7 @@ import static org.junit.Assert.*;
 /**
  *
  * @author Ranides Atterwim <ranides@gmail.com>
- * @todo (assira # 3) test
+ * @todo (assira # 9) test
  */
 public class DummyTest {