|
COT 5405 Advanced Algorithms Chris Lacher Notes 6: Associative ADTs: Set, Map, Table, AssociativeArray |
Abstract Container Types Container P|A Iterator Distinguishing Operations Vector P RandomAccess PushBack, PopBack, SetSize, Indexed BracketOperator List P BiDirectional PushFront, PopFront, PushBack, PopBack, Insert, Remove Deque P RandomAccess PushFront, PopFront, PushBack, PopBack, Indexed BracketOperator Stack P Push, Pop, Top Queue P Push, Pop, Front PriorityQueue A Push, Pop, Front OUSet A BiDirectional Ordered UniSet: Insert, Remove, Includes OMSet A BiDirectional Ordered MultiSet: Insert, Remove, Includes UUSet A BiDirectional Unordered UniSet: Insert, Remove, Includes UMSet A BiDirectional Unordered MultiSet: Insert, Remove, Includes AssociativeArray A BiDirectional Unordered Associative Bracket Operator For each operation: behavior specification, runtime constraint, runspace constraint
For each container: reason(s) to select it over the other choices
//-------------------------- // class Set<T,C> //-------------------------- template < typename T , class C > class Set { public: // Access support: SetIterator // Terminology support: value_type, Iterator // Proper type: constructors, destructors, assignment // element operations - modality determined by C Iterator Insert (const value_type& t); size_t Remove (const value_type& t); // locator operations Iterator Includes (const value_type& t) const; Iterator Begin () const; Iterator End () const; Iterator rBegin () const; Iterator rEnd () const; // size operations int Empty () const; size_t Size () const; protected: C c; } ; // class Set //---------------------------------- // class SetIterator<T,C> //---------------------------------- template <typename T , class C> class SetIterator { public: // Access support: Set // Terminology support: value_type // Proper type: constructors, destructors, assignment // operators int operator == (const SetIterator<T,C>& I2) const; int operator != (const SetIterator<T,C>& I2) const; value_type& operator * () const; // Return reference to current value SetIterator<T,C>& operator = (const SetIterator <T,C> & I); SetIterator<T,C>& operator ++ (); // prefix SetIterator<T,C> operator ++ (int); // postfix SetIterator<T,C>& operator -- (); // prefix SetIterator<T,C> operator -- (int); // postfix protected: typename C::Iterator i; } ; // class SetIterator
for (C::Iterator I = c.Begin(); I != c.End(); ++I) { // any code in the body }
Data& operator [] (const Key& k);
operation Associative Container --------- --------------------------------------------------------------- OUSet OMSet UUSet UMSet OUMap OMMap UUMap UMMap Insert(t) log n log n AO(1) AO(1) Insert(k,d) log n log n AO(1) AO(1) Remove(t) log n log n AO(1) AO(1) Remove(k) log n log n AO(1) AO(1) Includes(t) log n log n AO(1) AO(1) Includes(k) log n log n AO(1) AO(1) Includes(k,d) log n log n AO(1) AO(1) -------------- AO(1) = amortized constant runtime, depends on hash function and internal sizing parameters ----------------------------------------------------------------------------- Iterator support: Bidirectional
AssociativeArrayPriorityQueue