EDChainedHashSet & EDTreeSet Implementations
EDChainedHashSet and EDTreeSet Implementations
EDChainedHashSet
Description
Generic class implementing the Set<T> interface using a hash table with collision resolution through chaining. Supports null elements as valid. Does not implement iterators.
Constructors
EDChainedHashSet(int capacity, double loadFactor)EDChainedHashSet(int capacity)EDChainedHashSet(double loadFactor)EDChainedHashSet()
Private Methods
hash(Object item): Calculates the hash of an item.compareNull(Object item1, Object item2): Compares two objects, handling null values.rehash(): Increases the table size (rehashing).
Public Methods
size(): Returns the number of elements in the set.isEmpty(): Returns true if the set is empty.clear(): Clears the set.getCapacity(): Returns the capacity of the hash table.add(T item): Adds an item to the set.contains(Object item): Checks if the set contains an item.remove(Object item): Removes an item from the set.retainAll(Collection<?> c): Retains only the elements in this set that are contained in the specified collection.
EDTreeSet
Description
Generic class implementing the Set<E> interface using a binary search tree. Elements must be comparable or a comparator must be provided.
Constructors
EDTreeSet()EDTreeSet(Comparator<? super E> comp)EDTreeSet(Collection<? extends E> c)EDTreeSet(SortedSet<E> s)
Methods
clear(): Clears the tree.isEmpty(): Returns true if the tree is empty.first(): Returns the first (lowest) element currently in this set.last(): Returns the last (highest) element currently in this set.add(E item): Adds an element to the tree.contains(Object arg0): Checks if the tree contains an element.remove(Object arg0): Removes an element from the tree.ceiling(E e): Returns the least element in this set greater than or equal to the given element, or null if there is no such element.
