package edu.umd.cmsc132A; import java.util.Optional; import java.util.function.BiPredicate; import java.util.function.Predicate; // Similar to a Map, but requires keys implement Comparable interface interface MapComp, V> { // Add given key-value to this map MapComp add(K k, V v); // Count the number of key-values in this map Integer count(); // Look up the value associated with given key in this map (if it exists) Optional lookup(K k); // Produce a set of key-values in this map Set> keyVals(); // Produce a list of key-values in ascending sorted order Listof> sortedKeyVals(); // Produce a set of keys in this map Set keys(); // Produce a set of keys in ascending sorted order Listof sortedKeys(); // Produce a list of values in this map (order is unspecified) Listof vals(); // Produce a list of values in the ascending sorted order // of their keys in this map // NOTE: list is not itself sorted Listof sortedVals(); // Is this map the same as m? // (Does it have the same keys mapping to the same values?) Boolean same(MapComp m); // Remove any key-value with the given key from this map MapComp remove(K k); // Remove all key-values with keys that satisfy given predicate MapComp removeAll(Predicate p); // Remove all key-values w/ key-values that satisfy given binary predicate MapComp removeAllPairs(BiPredicate p); // Join this map and given map (entries in this map take precedence) MapComp join(MapComp m); } // Implementation of MapComp that uses a BST for efficient operations class MapBST, V> implements MapComp { // A Pairof where comparisons are done on the left component class KVPairof, V> extends Pairof implements Comparable> { KVPairof(K left, V right) { super(left, right); } public int compareTo(KVPairof p) { return this.left.compareTo(p.left); } } BST> bst; MapBST() { this.bst = new Leaf<>(); } // Add given key-value to this map public MapComp add(K k, V v) { return null; } // Count the number of key-values in this map public Integer count() { return null; } // Look up the value associated with given key in this map (if it exists) public Optional lookup(K k) { return null; } // Produce a set of key-values in this map public Set> keyVals() { return null; } // Produce a list of key-values in ascending sorted order public Listof> sortedKeyVals() { return null; } // Produce a set of keys in this map public Set keys() { return null; } // Produce a set of keys in ascending sorted order public Listof sortedKeys() { return null; } // Produce a list of values in this map (order is unspecified) public Listof vals() { return null; } // Produce a list of values in the ascending sorted order // of their keys in this map // NOTE: list is not itself sorted public Listof sortedVals() { return null; } // Is this map the same as m? // (Does it have the same keys mapping to the same values?) public Boolean same(MapComp m) { return null; } // Remove any key-value with the given key from this map public MapComp remove(K k) { return null; } // Remove all key-values with keys that satisfy given predicate public MapComp removeAll(Predicate p) { return null; } // Remove all key-values w/ key-values that satisfy given binary predicate public MapComp removeAllPairs(BiPredicate p) { return null; } // Join this map and given map (entries in this map take precedence) public MapComp join(MapComp m) { return null; } }