Class BSTMap<K extends java.lang.Comparable<K>,​V>

  • All Implemented Interfaces:
    Map<K,​V>

    public class BSTMap<K extends java.lang.Comparable<K>,​V>
    extends java.lang.Object
    implements Map<K,​V>
    • Constructor Summary

      Constructors 
      Constructor Description
      BSTMap()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean containsKey​(K key)
      Returns true if the key has been put into this map (and not removed).
      V get​(K key)
      Retrieves the value associated with the given key.
      void put​(K key, V value)
      Associates the given value to the given key.
      void remove​(K key)
      Removes the key and any associated value from the map, if present.
      int size()
      Returns the number of distinct keys that have been put in the map (and not yet removed).
      java.util.Deque<K> traverse()
      Returns a new Deque with all of the keys of this map.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • BSTMap

        public BSTMap()
    • Method Detail

      • get

        public V get​(K key)
        Description copied from interface: Map
        Retrieves the value associated with the given key. If the key is not in the map, null is returned.
        Specified by:
        get in interface Map<K extends java.lang.Comparable<K>,​V>
      • containsKey

        public boolean containsKey​(K key)
        Description copied from interface: Map
        Returns true if the key has been put into this map (and not removed).
        Specified by:
        containsKey in interface Map<K extends java.lang.Comparable<K>,​V>
      • put

        public void put​(K key,
                        V value)
        Description copied from interface: Map
        Associates the given value to the given key. If the key was not in the map, it is added and the size increases. Otherwise the size stays the same, but the new value should update the value previously associated to that key.
        Specified by:
        put in interface Map<K extends java.lang.Comparable<K>,​V>
      • size

        public int size()
        Description copied from interface: Map
        Returns the number of distinct keys that have been put in the map (and not yet removed).
        Specified by:
        size in interface Map<K extends java.lang.Comparable<K>,​V>
      • traverse

        public java.util.Deque<K> traverse()
        Description copied from interface: Map
        Returns a new Deque with all of the keys of this map. When feasible based on the underlying data structure (such as a binary search tree), the keys should be added to the tail end of the Deque in sorted order.
        Specified by:
        traverse in interface Map<K extends java.lang.Comparable<K>,​V>
      • remove

        public void remove​(K key)
        Description copied from interface: Map
        Removes the key and any associated value from the map, if present. If the key is not in the map, nothing happens (no error should be raised). This method is optional; the default just throws an exception.
        Specified by:
        remove in interface Map<K extends java.lang.Comparable<K>,​V>