This chapter discusses the following skip list containers:
wcskip.h
The WCPtrSkipListDict<Key,Value> class is a templated class used to store objects in a dictionary. Dictionaries store values with an associated key, which may be of any type. One example of a dictionary used in everyday life is the phone book. The phone numbers are the data values, and the customer's name is the key. The equality operator of the key's type is used to locate the key-value pairs.
In the description of each member function, the text Key is used to indicate the template parameter defining the type of the indices pointed to by the pointers stored in the dictionary. The text Value is used to indicate the template parameter defining the type of the data pointed to by the pointers stored in the dictionary.
Pointers to the key values are stored in the dictionary. Destructors aren't called on the keys pointed to. The key values pointed to in the dictionary shouldn't be changed such that the equivalence to the old value is modified. |
The iterator classes for skip lists have the same function and operator interface as the hash iterator classes. See the chapter on Hash Iterators for more information.
The WCExcept class is a base class of the WCPtrSkipListDict<Key,Value> class and provides the exceptions() member function. This member function controls the exceptions that can be thrown by the WCPtrSkipListDict<Key,Value> object. No exceptions are enabled unless they're set by the exceptions() member function.
The WCPtrSkipListDict<Key,Value> class requires Key to have:
int operator ==( const Key & ) const
int operator <( const Key & ) const
The following member functions are declared in the public interface:
WCPtrSkipListDict( unsigned = WCSkipListDict_PROB_QUARTER, unsigned = WCDEFAULT_SKIPLIST_MAX_PTRS ); WCPtrSkipListDict( unsigned = WCSkipListDict_PROB_QUARTER, unsigned = WCDEFAULT_SKIPLIST_MAX_PTRS, void * (*user_alloc)( size_t size ), void (*user_dealloc)( void *old, size_t size ) ); WCPtrSkipListDict( const WCPtrSkipListDict & ); virtual ~WCPtrSkipListDict(); void clear(); void clearAndDestroy(); int contains( const Key * ) const; unsigned entries() const; Value * find( const Key * ) const; Value * findKeyAndValue( const Key *, Key * & ) const; void forAll( void (*user_fn)( Key *, Value *, void * ), void * ); int insert( Key *, Value * ); int isEmpty() const; Value * remove( const Key * );
The following member operators are declared in the public interface:
Value * & operator [ ]( const Key * ); Value * const & operator [ ]( const Key * ) const; WCPtrSkipListDict & operator =( const WCPtrSkipListDict & ); int operator ==( const WCPtrSkipListDict & ) const;
create a WCPtrSkipListDict<Key,Value> object
#include <wcskip.h> public: WCPtrSkipListDict( unsigned = WCSKIPLIST_PROB_QUARTER, unsigned = WCDEFAULT_SKIPLIST_MAX_PTRS ); WCPtrSkipListDict( unsigned = WCSKIPLIST_PROB_QUARTER, unsigned = WCDEFAULT_SKIPLIST_MAX_PTRS, void * (*user_alloc)( size_t ), void (*user_dealloc)( void *, size_t ) ); WCPtrSkipListDict( const WCPtrSkipListDict & );
There are three forms of the public WCPtrSkipListDict<Key,Value> constructor:
If an allocation failure occurs while creating the skip list, the out_of_memory exception is thrown if it's enabled.
The allocation function must return a zero if it can't perform the allocation. The deallocation function is passed the size as well as the pointer to the data. Your allocation system may take advantage of the characteristic that the allocation function is always called with the same size value for any particular instantiation of a list dictionary. To determine the size of the objects that the memory management functions are required to allocate and free, the following macro may be used:
WCPtrSkipListDictItemSize( Key, Value, num_of_pointers )
If there isn't enough memory to copy all of the values, then only some are copied, and the number of entries correctly reflects the number copied. If all of the elements can't be copied, then the out_of_memory exception is thrown if it's enabled.
The public WCPtrSkipListDict<Key,Value> constructor creates an initialized WCPtrSkipListDict<Key,Value> object.
WCExcept::out_of_memory, WCPtrSkipListDict<Key,Value>::~WCPtrSkipListDict(), WCPtrSkipListDict<Key,Value>::operator =()
destroy a WCPtrSkipListDict<Key,Value> object
#include <wcskip.h> public: virtual ~WCPtrSkipListDict();
The public WCPtrSkipListDict<Key,Value> destructor is the destructor for the WCPtrSkipListDict<Key,Value> class.
If the number of dictionary elements isn't zero, and the not_empty exception is enabled, the exception is thrown. Otherwise, the dictionary elements are cleared using the clear() member function.
The objects to which the dictionary elements point aren't deleted unless the clearAndDestroy() member function is explicitly called before the destructor is called. |
The call to this destructor is inserted implicitly by the compiler at the point where the WCPtrSkipListDict<Key,Value> object goes out of scope.
The public WCPtrSkipListDict<Key,Value> destructor destroys an WCPtrSkipListDict<Key,Value> object.
WCExcept::not_empty, WCPtrSkipListDict<Key,Value>::clear(), WCPtrSkipListDict<Key,Value>::clearAndDestroy()
clear the dictionary
#include <wcskip.h> public: void clear();
The clear() public member function is used to clear the dictionary so that it has no entries. Objects pointed to by the dictionary elements aren't deleted. The dictionary object isn't destroyed and re-created by this function, so the object destructor isn't invoked.
The clear() public member function clears the dictionary to have no elements.
WCPtrSkipListDict<Key,Value>::~WCPtrSkipListDict(), WCPtrSkipListDict<Key,Value>::clearAndDestroy(), WCPtrSkipListDict<Key,Value>::operator =()
clear the dictionary, destroying any elements in it
#include <wcskip.h> public: void clearAndDestroy();
The clearAndDestroy() public member function is used to clear the dictionary and delete the objects pointed to by the dictionary elements. The dictionary object isn't destroyed and re-created by this function, so the dictionary object destructor isn't invoked.
The clearAndDestroy() public member function clears the dictionary by deleting the objects pointed to by the dictionary elements.
WCPtrSkipListDict<Key,Value>::clear()
determine whether or not a given element is in the dictionary
#include <wcskip.h> public: int contains( const Key & ) const;
The contains() public member function returns non-zero if an element with the specified key is stored in the dictionary, or zero if there is no equivalent element. Note that equivalence is based on the equivalence operator of the Key type.
The contains() public member function returns a non-zero value if the Key is found in the dictionary.
WCPtrSkipListDict<Key,Value>::find(), WCPtrSkipListDict<Key,Value>::findKeyAndValue()
count the elements in the dictionary
#include <wcskip.h> public: unsigned entries() const;
The entries() public member function is used to return the current number of elements stored in the dictionary.
This function returns the number of elements in the dictionary.
WCPtrSkipListDict<Key,Value>::isEmpty()
find an element in the dictionary
#include <wcskip.h> public: Value * find( const Key * ) const;
The find() public member function is used to find an element with an equivalent key in the dictionary. If an equivalent element is found, a pointer to the element Value is returned. Zero is returned if the element isn't found. Note that equivalence is based on the equivalence operator of the Key type.
The element equivalent to the passed key is located in the dictionary.
WCPtrSkipListDict<Key,Value>::findKeyAndValue()
find an element in the dictionary
#include <wcskip.h> public: Value * findKeyAndValue( const Key *, Key * & ) const;
The findKeyAndValue() public member function is used to find an element in the dictionary with an key equivalent to the first parameter. If an equivalent element is found, a pointer to the element Value is returned. The reference to a Key passed as the second parameter is assigned the found element's key. Zero is returned if the element isn't found. Note that equivalence is based on the equivalence operator of the Key type.
The element equivalent to the passed key is located in the dictionary.
WCPtrSkipListDict<Key,Value>::find()
invoke a function for each element in the dictionary
#include <wcskip.h> public: void forAll( void (*user_fn)( Key *, Value *, void * ), void * );
The forAll() public member function causes the user-supplied function to be invoked for every key-value pair in the dictionary. The user function has the prototype
void user_func( Key * key, Value * value, void * data );
As the elements are visited, the user function is invoked with the Key and Value components of the element passed as the first two parameters. The second parameter of the forAll() function is passed as the third parameter to the user function. This value can be used to pass any appropriate data from the main program to the user function.
The elements in the dictionary are all visited, and the user function is invoked for each one.
WCPtrSkipListDict<Key,Value>::find(), WCPtrSkipListDict<Key,Value>::findKeyAndValue()
insert a key and value into the dictionary
#include <wcskip.h> public: int insert( Key *, Value * );
The insert() public member function inserts a key and value into the dictionary.
If allocation of the node to store the key-value pair fails, then the out_of_memory exception is thrown if it's enabled. If it isn't enabled, the insertion isn't completed.
The insert() public member function inserts a key and value into the dictionary. If the insertion is successful, a non-zero value is returned. A zero is returned if the insertion fails.
WCExcept::out_of_memory, WCPtrSkipListDict<Key,Value>::operator =()
determine whether or not the dictionary is empty
#include <wcskip.h> public: int isEmpty() const;
The isEmpty() public member function is used to determine if the dictionary is empty.
The isEmpty() public member function returns zero if the dictionary contains at least one entry, non-zero if it's empty.
WCPtrSkipListDict<Key,Value>::entries()
index into the dictionary to get the entry for a given Key
#include <wcskip.h> public: Value * & operator[ ]( const Key * ); Value * const & operator[ ]( const Key * ) const;
operator [ ]() is the dictionary index operator; there are two forms of it:
If no equivalent element is found, then a new key-value pair is created with the specified Key value, and initialized with the default constructor. The returned reference can then be assigned to, so that insertions can be made with the operator.
If an allocation error occurs while inserting a new key-value pair, then the out_of_memory exception is thrown if it's enabled. If the exception isn't enabled, then a reference to address zero is returned. This results in a run-time error on systems that trap references to address zero.
If no equivalent element is found, then the index_range exception is thrown if it's enabled. If the exception isn't enabled, then a reference to address zero is returned. This results in a run-time error on systems that trap references to address zero.
WCExcept::index_range, WCExcept::out_of_memory
assign one dictionary to another
#include <wcskip.h> public: WCPtrSkipListDict & operator =( const WCPtrSkipListDict & );
The operator =() public member function is the assignment operator for the WCPtrSkipListDict<Key,Value> class. The left hand side dictionary is first cleared using the clear() member function, and then the right hand side dictionary is copied. The new skip list is created with the same probability and maximum pointers, all values or pointers stored in the list, and the exception trap states.
If there isn't enough memory to copy all of the values or pointers in the dictionary, then only some are copied, and the out_of_memory exception is thrown if it's enabled. The number of entries correctly reflects the number copied.
The operator =() public member function assigns the left hand side dictionary to be a copy of the right hand side.
WCExcept::out_of_memory, WCPtrSkipListDict<Key,Value>::clear()
determine whether or not two dictionaries are equivalent
#include <wcskip.h> public: int operator ==( const WCPtrSkipListDict & ) const;
The operator ==() public member function is the equivalence operator for the WCPtrSkipListDict<Key,Value> class. Two dictionary objects are equivalent if they're the same object and share the same address.
A TRUE (non-zero) value is returned if the left hand side and right hand side dictionaries are the same object; FALSE (zero) is returned otherwise.
remove an element from the dictionary
#include <wcskip.h> public: Value * remove( const Key * );
The remove() public member function is used to remove the specified element from the dictionary. If an equivalent element is found, the pointer value is returned. Zero is returned if the element isn't found. Note that equivalence is based on the equivalence operator of the Key type.
The element is removed from the dictionary if it's found.
wcskip.h
The WCPtrSkipListSet<Type> and WCPtrSkipList<Type> classes are templated classes used to store objects in a skip list. A skip list is a probabilistic alternative to balanced trees, and provides a reasonable performance balance to insertion, search, and deletion. A skip list allows more than one copy of an element that is equivalent, while the skip list set allows only one copy. The equality operator of the element's type is used to locate the value.
In the description of each member function, the text Type is used to indicate the template parameter defining the type of the data pointed to by the pointers stored in the list.
Pointers to the elements are stored in the list. Destructors aren't called on the elements pointed to. The data values pointed to in the list shouldn't be changed such that the equivalence to the old value is modified. |
The iterator classes for skip lists have the same function and operator interface as the hash iterators classes. See the chapter on Hash Iterators for more information.
The WCExcept class is a base class of the WCPtrSkipListSet<Type> and WCPtrSkipList<Type> classes, and provides the exceptions() member function. This member function controls the exceptions that can be thrown by the WCPtrSkipListSet<Type> and WCPtrSkipList<Type> objects. No exceptions are enabled unless they're set by the exceptions() member function.
The WCPtrSkipListSet<Type> and WCPtrSkipList<Type> classes require Type to have the following:
int operator ==( const Type & ) const
int operator <( const Type & ) const
The following member functions are declared in the public interface:
WCPtrSkipList( unsigned = WCSKIPLIST_PROB_QUARTER, unsigned = WCDEFAULT_SKIPLIST_MAX_PTRS ); WCPtrSkipList( unsigned = WCSKIPLIST_PROB_QUARTER, unsigned = WCDEFAULT_SKIPLIST_MAX_PTRS, void * (*user_alloc)( size_t size ), void (*user_dealloc)( void *old, size_t size ) ); WCPtrSkipList( const WCPtrSkipList & ); virtual ~WCPtrSkipList(); WCPtrSkipListSet( unsigned = WCSKIPLIST_PROB_QUARTER, unsigned = WCDEFAULT_SKIPLIST_MAX_PTRS ); WCPtrSkipListSet( unsigned = WCSKIPLIST_PROB_QUARTER, unsigned = WCDEFAULT_SKIPLIST_MAX_PTRS, void * (*user_alloc)( size_t size ), void (*user_dealloc)( void *old, size_t size ) ); WCPtrSkipListSet( const WCPtrSkipListSet & ); virtual ~WCPtrSkipListSet(); void clear(); void clearAndDestroy(); int contains( const Type * ) const; unsigned entries() const; Type * find( const Type * ) const; void forAll( void (*user_fn)( Type *, void * ) , void * ); int insert( Type * ); int isEmpty() const; Type * remove( const Type * );
The following public member functions are available for the WCPtrSkipList class only:
unsigned occurrencesOf( const Type * ) const; unsigned removeAll( const Type * );
The following member operators are declared in the public interface:
WCPtrSkipList & operator =( const WCPtrSkipList & ); int operator ==( const WCPtrSkipList & ) const; WCPtrSkipListSet & operator =( const WCPtrSkipListSet & ); int operator ==( const WCPtrSkipListSet & ) const;
create a WCPtrSkipListSet<Type> object
#include <wcskip.h> public: WCPtrSkipListSet( unsigned = WCSKIPLIST_PROB_QUARTER, unsigned = WCDEFAULT_SKIPLIST_MAX_PTRS ); WCPtrSkipListSet( unsigned = WCSKIPLIST_PROB_QUARTER, unsigned = WCDEFAULT_SKIPLIST_MAX_PTRS, void * (*user_alloc)( size_t ), void (*user_dealloc)( void *, size_t ) ); WCPtrSkipListSet( const WCPtrSkipListSet & );
There are three forms of the WCPtrSkipListSet<Type> constructor:
The first optional parameter, which defaults to the constant WCSKIPLIST_PROB_QUARTER, determines the probability of having a certain number of pointers in each skip list node. The second optional parameter, which defaults to the constant WCDEFAULT_SKIPLIST_MAX_PTRS, determines the maximum number of pointers that are allowed in any skip list node. WCDEFAULT_SKIPLIST_MAX_PTRS is the maximum effective value of the second parameter.
If an allocation failure occurs while creating the skip list, the out_of_memory exception is thrown if it's enabled.
The allocation function must return a zero if it can't perform the allocation. The deallocation function is passed the size as well as the pointer to the data. Your allocation system may take advantage of the characteristic that the allocation function is always called with the same size value for any particular instantiation of a skip list. To determine the size of the objects that the memory management functions are required to allocate and free, the following macro may be used:
WCPtrSkipListSetItemSize( Type, num_of_pointers )
If there isn't enough memory to copy all of the values, then only some are copied, and the number of entries correctly reflects the number copied. If all of the elements can't be copied, then the out_of_memory exception is thrown if it's enabled.
The WCPtrSkipListSet<Type> constructor creates an initialized WCPtrSkipListSet object.
WCExcept::out_of_memory, WCPtrSkipListSet<Type>::~WCPtrSkipListSet(), WCPtrSkipListSet<Type>::operator =()
destroy a WCPtrSkipListSet<Type> object
#include <wcskip.h> public: virtual ~WCPtrSkipListSet();
The WCPtrSkipListSet<Type> destructor is the destructor for the WCPtrSkipListSet class.
If the number of elements isn't zero and the not_empty exception is enabled, the exception is thrown. Otherwise, the list elements are cleared using the clear() member function.
The objects to which the list elements point aren't deleted unless the clearAndDestroy() member function is explicitly called before the destructor is called. |
The call to this destructor is inserted implicitly by the compiler at the point where the WCPtrSkipListSet object goes out of scope.
The WCPtrSkipListSet object is destroyed.
WCExcept::not_empty, WCPtrSkipListSet<Type>::clear(), WCPtrSkipListSet<Type>::clearAndDestroy()
create a WCPtrSkipList<Type> object
#include <wcskip.h> public: WCPtrSkipList( unsigned = WCSKIPLIST_PROB_QUARTER, unsigned = WCDEFAULT_SKIPLIST_MAX_PTRS ); WCPtrSkipList( unsigned = WCSKIPLIST_PROB_QUARTER, unsigned = WCDEFAULT_SKIPLIST_MAX_PTRS, void * (*user_alloc)( size_t ), void (*user_dealloc)( void *, size_t ) ); WCPtrSkipList( const WCPtrSkipList & );
There are three forms of the WCPtrSkipList<Type> constructor:
The first optional parameter, which defaults to the constant WCSKIPLIST_PROB_QUARTER, determines the probability of having a certain number of pointers in each skip list node. The second optional parameter, which defaults to the constant WCDEFAULT_SKIPLIST_MAX_PTRS, determines the maximum number of pointers that are allowed in any skip list node. WCDEFAULT_SKIPLIST_MAX_PTRS is the maximum effective value of the second parameter.
If an allocation failure occurs while creating the skip list, the out_of_memory exception is thrown if it's enabled.
The allocation function must return a zero if it can't perform the allocation. The deallocation function is passed the size as well as the pointer to the data. Your allocation system may take advantage of the characteristic that the allocation function is always called with the same size value for any particular instantiation of a skip list. To determine the size of the objects that the memory management functions are required to allocate and free, the following macro may be used:
WCPtrSkipListItemSize( Type, num_of_pointers )
If there isn't enough memory to copy all of the values, then only some are copied, and the number of entries correctly reflects the number copied. If all of the elements can't be copied, then the out_of_memory exception is thrown if it's enabled.
The WCPtrSkipList<Type> constructor creates an initialized WCPtrSkipList object.
WCExcept::out_of_memory, WCPtrSkipListSet<Type>::~WCPtrSkipListSet(), WCPtrSkipListSet<Type>::operator =()
destroy a WCPtrSkipList<Type> object
#include <wcskip.h> public: virtual ~WCPtrSkipList();
The WCPtrSkipList<Type> destructor is the destructor for the WCPtrSkipList class.
If the number of elements isn't zero and the not_empty exception is enabled, the exception is thrown. Otherwise, the list elements are cleared using the clear() member function.
The objects to which the list elements point aren't deleted unless the clearAndDestroy() member function is explicitly called before the destructor is called. |
The call to this destructor is inserted implicitly by the compiler at the point where the WCPtrSkipList object goes out of scope.
The WCPtrSkipList object is destroyed.
WCExcept::not_empty, WCPtrSkipListSet<Type>::clear(), WCPtrSkipListSet<Type>::clearAndDestroy()
clear the list of all entries
#include <wcskip.h> public: void clear();
The clear() public member function is used to clear the list so that it has no entries. Objects pointed to by the list elements aren't deleted. The list object isn't destroyed and re-created by this function, so the object destructor isn't invoked.
The clear() public member function clears the list to have no elements.
WCPtrSkipListSet<Type>::~WCPtrSkipListSet(), WCPtrSkipList<Type>::~WCPtrSkipList(), WCPtrSkipListSet<Type>::clearAndDestroy(), WCPtrSkipList<Type>::clearAndDestroy(), WCPtrSkipListSet<Type>::operator =(), WCPtrSkipList<Type>::operator =(),
clear the list, destroying all the entries in it
#include <wcskip.h> public: void clearAndDestroy();
The clearAndDestroy() public member function is used to clear the list and delete the objects pointed to by the list elements. The list object isn't destroyed and re-created by this function, so the list object destructor isn't invoked.
The clearAndDestroy() public member function clears the list by deleting the objects pointed to by the list elements, and then removing the list elements from the list.
WCPtrSkipListSet<Type>::clear(), WCPtrSkipList<Type>::clear()
determine whether or not a given entry is in the list
#include <wcskip.h> public: int contains( const Type * ) const;
The contains() public member function returns non-zero if the element is stored in the list, or zero if there's no equivalent element. Note that equivalence is based on the equivalence operator of the element type.
The contains() public member function returns a non-zero value if the element is found in the list.
WCPtrSkipListSet<Type>::find(), WCPtrSkipList<Type>::find()
count the entries in the list
#include <wcskip.h> public: unsigned entries() const;
The entries() public member function is used to return the current number of elements stored in the list.
The entries() public member function returns the number of elements in the list.
WCPtrSkipListSet<Type>::isEmpty(), WCPtrSkipList<Type>::isEmpty()
find an entry in the list
#include <wcskip.h> public: Type * find( const Type * ) const;
The find() public member function is used to find an element with an equivalent value in the list. If an equivalent element is found, a pointer to the element is returned. Zero is returned if the element isn't found. Note that equivalence is based on the equivalence operator of the element type.
The element equivalent to the passed value is located in the list.
invoke a function for each entry in the list
#include <wcskip.h> public: void forAll(void (*user_fn)( Type *, void * ), void * );
The forAll() public member function causes the user-supplied function to be invoked for every value in the list. The user function has the prototype
void user_func( Type * value, void * data );
As the elements are visited, the user function is invoked with the element passed as the first parameter. The second parameter of the forAll() function is passed as the second parameter to the user function. This value can be used to pass any appropriate data from the main program to the user function.
The elements in the list are all visited, and the user function is invoked for each one.
WCPtrSkipListSet<Type>::find(), WCPtrSkipList<Type>::find()
insert an entry into the list
#include <wcskip.h> public: int insert( Type * );
The insert() public member function inserts a value into the list.
If allocation of the node to store the value fails, then the out_of_memory exception is thrown if it's enabled. If the exception isn't enabled, the insertion isn't completed.
With a WCPtrSkipListSet, there must be only one equivalent element in the set. If an element equivalent to the inserted element is already in the list set, the list set remains unchanged, and the not_unique exception is thrown if it's enabled. If the exception isn't enabled, the insertion isn't completed.
The insert() public member function inserts a value into the list. If the insertion is successful, a non-zero value is returned; zero is returned if it fails.
WCExcept::out_of_memory, WCExcept::not_unique, WCPtrSkipListSet<Type>::operator =(), WCPtrSkipList<Type>::operator =()
determine whether or not the list is empty
#include <wcskip.h> public: int isEmpty() const;
The isEmpty() public member function is used to determine if the list is empty.
The isEmpty() public member function returns zero if the list contains at least one entry, non-zero if it's empty.
WCPtrSkipListSet<Type>::entries(), WCPtrSkipList<Type>::entries()
count the occurrences of the given value in the list
#include <wcskip.h> public: unsigned occurrencesOf( const Type * ) const;
The occurrencesOf() public member function is used to return the current number of elements stored in the list that are equivalent to the passed value. Note that equivalence is based on the equivalence operator of the element type.
The occurrencesOf() public member function returns the number of elements in the list that are equivalent to the passed value.
WCPtrSkipList<Type>::entries(), WCPtrSkipList<Type>::find(), WCPtrSkipList<Type>::isEmpty()
assign one list to another
#include <wcskip.h> public: WCPtrSkipList & operator =( const WCPtrSkipList & ); WCPtrSkipListSet & operator =( const WCPtrSkipListSet & );
The operator =() public member function is the assignment operator for the WCPtrSkipListSet<Type> and WCPtrSkipList<Type> classes. The left hand side list is first cleared using the clear() member function, and then the right hand side list is copied. The list function, exception trap states, and all of the list elements are copied.
If there isn't enough memory to copy all of the values or pointers in the list, then only some are copied, and the out_of_memory exception is thrown if it's enabled. The number of entries correctly reflects the number copied.
The operator =() public member function assigns the left hand side list to be a copy of the right hand side.
WCExcept::out_of_memory, WCPtrSkipListSet<Type>::clear(), WCPtrSkipList<Type>::clear()
determine whether or not two lists are equivalent
#include <wcskip.h> public: int operator ==( const WCPtrSkipList & ) const; int operator ==( const WCPtrSkipListSet & ) const;
The operator ==() public member function is the equivalence operator for the WCPtrSkipListSet<Type> and WCPtrSkipList<Type> classes. Two list objects are equivalent if they're the same object and share the same address.
A TRUE (non-zero) value is returned if the left hand side and right hand side list are the same object. A FALSE (zero) value is returned otherwise.
remove an entry from the list
#include <wcskip.h> public: Type * remove( const Type * );
The remove() public member function is used to remove the specified element from the list. If an equivalent element is found, the pointer value is returned. Zero is returned if the element isn't found. If the list is a WCPtrSkipList and there's more than one element equivalent to the specified element, then the last equivalent element added to the skip list is removed. Note that equivalence is based on the equivalence operator of the element type.
The element is removed from the list.
remove all occurences of an element from the list
#include <wcskip.h> public: unsigned removeAll( const Type * );
The removeAll() public member function is used to remove all elements equivalent to the specified element from the list. Zero is returned if no equivalent elements are found. Note that equivalence is based on the equivalence operator of the element type.
All equivalent elements are removed from the list.
wcskip.h
The WCValSkipListDict<Key,Value> class is a templated class used to store objects in a dictionary. Dictionaries store values with an associated key, which may be of any type. One example of a dictionary used in everyday life is the phone book. The phone numbers are the data values, and the customer's name is the key. The equality operator of the key's type is used to locate the key-value pairs.
In the description of each member function, the text Key is used to indicate the template parameter defining the type of the indices used to store data in the dictionary. The text Value is used to indicate the template parameter defining the type of the data stored in the dictionary.
Values are copied into the dictionary, which could be undesirable if the stored objects are complicated and copying is expensive. Value dictionaries shouldn't be used to store objects of a base class if any derived types of different sizes would be stored in the dictionary, or if the destructor for a derived class must be called.
The iterator classes for skip lists have the same function and operator interface as the hash iterator classes. See the chapter on Hash Iterators for more information.
The WCExcept class is a base class of the WCValSkipListDict<Key,Value> class, and provides the exceptions() member function. This member function controls the exceptions that can be thrown by the WCValSkipListDict<Key,Value> object. No exceptions are enabled unless they're set by the exceptions() member function.
The WCValSkipListDict<Key,Value> class requires Key to have:
Key::Key()
Key::Key( const Key & )
Key & operator =( const Key & )
int operator ==( const Key & ) const
int operator <( const Key & ) const
The WCValSkipListDict<Key,Value> class requires Value to have:
Value::Value()
Value::Value( const Value & )
Value & operator =( const Value & )
The following member functions are declared in the public interface:
WCValSkipListDict( unsigned = WCSkipListDict_PROB_QUARTER, unsigned = WCDEFAULT_SKIPLIST_MAX_PTRS); WCValSkipListDict( unsigned = WCSkipListDict_PROB_QUARTER, unsigned = WCDEFAULT_SKIPLIST_MAX_PTRS, void * (*user_alloc)( size_t size ), void (*user_dealloc)( void *old, size_t size ) ); WCValSkipListDict( const WCValSkipListDict & ); virtual ~WCValSkipListDict(); void clear(); int contains( const Key & ) const; unsigned entries() const; int find( const Key &, Value & ) const; int findKeyAndValue( const Key &, Key &, Value & ) const; void forAll( void (*user_fn)( Key, Value, void * ), void * ); int insert( const Key &, const Value & ); int isEmpty() const; int remove( const Key & );
The following member operators are declared in the public interface:
Value & operator [ ]( const Key & ); const Value & operator [ ]( const Key & ) const; WCValSkipListDict & operator =( const WCValSkipListDict & ); int operator ==( const WCValSkipListDict & ) const;
create a WCValSkipListDict<Key,Value> object
#include <wcskip.h> public: WCValSkipListDict( unsigned = WCSKIPLIST_PROB_QUARTER, unsigned = WCDEFAULT_SKIPLIST_MAX_PTRS ); WCValSkipListDict( unsigned = WCSKIPLIST_PROB_QUARTER, unsigned = WCDEFAULT_SKIPLIST_MAX_PTRS, void * (*user_alloc)( size_t ), void (*user_dealloc)( void *, size_t ) ); WCValSkipListDict( const WCValSkipListDict & );
There are three forms of the public WCValSkipListDict<Key,Value> constructor:
The first optional parameter, which defaults to the constant WCSKIPLIST_PROB_QUARTER, determines the probability of having a certain number of pointers in each skip list node. The second optional parameter, which defaults to the constant WCDEFAULT_SKIPLIST_MAX_PTRS, determines the maximum number of pointers that are allowed in any skip list node. WCDEFAULT_SKIPLIST_MAX_PTRS is the maximum effective value of the second parameter.
If an allocation failure occurs while creating the skip list, the out_of_memory exception is thrown if it's enabled.
The allocation function must return a zero if it can't perform the allocation. The deallocation function is passed the size as well as the pointer to the data. Your allocation system may take advantage of the characteristic that the allocation function is always called with the same size value for any particular instantiation of a list dictionary. To determine the size of the objects that the memory management functions are required to allocate and free, the following macro may be used:
WCValSkipListDictItemSize( Key, Value, num_of_pointers )
If there isn't enough memory to copy all of the values, then only some are copied, and the number of entries correctly reflects the number copied. If all of the elements can't be copied, then the out_of_memory exception is thrown if it's enabled.
The public WCValSkipListDict<Key,Value> constructor creates an initialized WCValSkipListDict<Key,Value> object.
WCExcept::out_of_memory, WCValSkipListDict<Key,Value>::~WCValSkipListDict(), WCValSkipListDict<Key,Value>::operator =()
destroy a WCValSkipListDict<Key,Value> object
#include <wcskip.h> public: virtual ~WCValSkipListDict();
The public WCValSkipListDict<Key,Value> destructor is the destructor for the WCValSkipListDict<Key,Value> class.
If the number of dictionary elements isn't zero and the not_empty exception is enabled, it's thrown. Otherwise, the dictionary elements are cleared using the clear() member function.
The call to this destructor is inserted implicitly by the compiler at the point where the WCValSkipListDict<Key,Value> object goes out of scope.
The WCValSkipListDict<Key,Value> object is destroyed.
WCExcept::not_empty, WCValSkipListDict<Key,Value>::clear()
clear all the entries from the dictionary
#include <wcskip.h> public: void clear();
The clear() public member function is used to clear the dictionary so that it has no entries. Elements stored in the dictionary are destroyed using the destructors of Key and of Value. The dictionary object isn't destroyed and re-created by this function, so the object destructor isn't invoked.
The clear() public member function clears the dictionary to have no elements.
WCValSkipListDict<Key,Value>::~WCValSkipListDict(), WCValSkipListDict<Key,Value>::operator =()
determine whether or not a given element is in the dictionary
#include <wcskip.h> public: int contains( const Key & ) const;
The contains() public member function returns non-zero if an element with the specified key is stored in the dictionary, or zero if there is no equivalent element. Note that equivalence is based on the equivalence operator of the Key type.
The contains() public member function returns a non-zero value if the Key is found in the dictionary.
WCValSkipListDict<Key,Value>::find(), WCValSkipListDict<Key,Value>::findKeyAndValue()
count the elements in the dictionary
#include <wcskip.h> public: unsigned entries() const;
The entries() public member function is used to return the current number of elements stored in the dictionary.
The entries() public member function returns the number of elements in the dictionary.
WCValSkipListDict<Key,Value>::isEmpty()
find an element in the dictionary
#include <wcskip.h> public: int find( const Key &, Value & ) const;
The find() public member function is used to find an element with an equivalent key in the dictionary.
Note that equivalence is based on the equivalence operator of the Key type.
The element equivalent to the passed key is located in the dictionary.
WCValSkipListDict<Key,Value>::findKeyAndValue()
find an element in the dictionary
#include <wcskip.h> public: int findKeyAndValue( const Key &, Key &, Value & ) const;
The findKeyAndValue() public member function is used to find an element in the dictionary with an key equivalent to the first parameter.
Note that equivalence is based on the equivalence operator of the Key type.
The element equivalent to the passed key is located in the dictionary.
WCValSkipListDict<Key,Value>::find()
invoke a function for each element in the dictionary
#include <wcskip.h> public: void forAll( void (*user_fn)( Key, Value, void * ), void * );
The forAll() public member function causes the user-supplied function to be invoked for every key-value pair in the dictionary. The user function has the prototype
void user_func( Key key, Value value, void * data );
As the elements are visited, the user function is invoked with the Key and Value components of the element passed as the first two parameters. The second parameter of the forAll() function is passed as the third parameter to the user function. This value can be used to pass any appropriate data from the main program to the user function.
The elements in the dictionary are all visited, and the user function is invoked for each one.
WCValSkipListDict<Key,Value>::find(), WCValSkipListDict<Key,Value>::findKeyAndValue()
insert an element into the dictionary
#include <wcskip.h> public: int insert( const Key &, const Value & );
The insert() public member function inserts a key and value into the dictionary.
If allocation of the node to store the key-value pair fails, then the out_of_memory exception is thrown if it's enabled. If the exception isn't enabled, the insertion isn't completed.
The insert() public member function inserts a key and value into the dictionary. If the insertion is successful, a non-zero value is returned. A zero is returned if the insertion fails.
WCExcept::out_of_memory, WCValSkipListDict<Key,Value>::operator =()
determine whether or not the dictionary is empty
#include <wcskip.h> public: int isEmpty() const;
The isEmpty() public member function is used to determine if the dictionary is empty.
The isEmpty() public member function returns zero if the dictionary contains at least one entry, non-zero if it's empty.
WCValSkipListDict<Key,Value>::entries()
index into the dictionary to find the element for the given Key
#include <wcskip.h> public: Value & operator[ ]( const Key & ); const Value & operator[ ]( const Key & ) const;
operator [ ]() is the dictionary index operator; there are two forms of it:
If no equivalent element is found, then a new key-value pair is created with the specified Key value, and initialized with the default constructor. The returned reference can then be assigned to, so that insertions can be made with the operator.
If an allocation error occurs while inserting a new key-value pair, then the out_of_memory exception is thrown if it's enabled. If the exception isn't enabled, then a reference to address zero is returned. This results in a run-time error on systems that trap references to address zero.
If no equivalent element is found, then the index_range exception is thrown if it's enabled. If the exception isn't enabled, then a reference to address zero is returned. This results in a run-time error on systems that trap references to address zero.
WCExcept::index_range, WCExcept::out_of_memory
assign one dictionary to another
#include <wcskip.h> public: WCValSkipListDict & operator =( const WCValSkipListDict & );
The operator =() public member function is the assignment operator for the WCValSkipListDict<Key,Value> class. The left hand side dictionary is first cleared using the clear() member function, and then the right hand side dictionary is copied. The new skip list is created with the same probability and maximum pointers, all values or pointers stored in the list, and the exception trap states.
If there isn't enough memory to copy all of the values or pointers in the dictionary, then only some are copied, and the out_of_memory exception is thrown if it's enabled. The number of entries correctly reflects the number copied.
The operator =() public member function sets the left hand side dictionary to be a copy of the right hand side.
WCExcept::out_of_memory, WCValSkipListDict<Key,Value>::clear()
determine whether or not two dictionaries are equivalent
#include <wcskip.h> public: int operator ==( const WCValSkipListDict & ) const;
The operator ==() public member function is the equivalence operator for the WCValSkipListDict<Key,Value> class. Two dictionary objects are equivalent if they're the same object and share the same address.
A TRUE (non-zero) value is returned if the left hand side and right hand side dictionary are the same object. A FALSE (zero) value is returned otherwise.
remove an element from the dictionary
#include <wcskip.h> public: int remove( const Key & );
The remove() public member function is used to remove the specified element from the dictionary. If an equivalent element is found, a non-zero value is returned. Zero is returned if the element isn't found. Note that equivalence is based on the equivalence operator of the Key type.
The element is removed from the dictionary if it's found.
wcskip.h
The WCValSkipListSet<Type> and WCValSkipList<Type> classes are templated classes used to store objects in a skip list. A skip list is a probabilistic alternative to balanced trees, and provides a reasonable performance balance to insertion, search, and deletion. A skip list allows more than one copy of an element that's equivalent, while the skip list set allows only one copy. The equality operator of the element's type is used to locate the value.
In the description of each member function, the text Type is used to indicate the template parameter defining the type of the data to be stored in the list.
Values are copied into the list, which could be undesirable if the stored objects are complicated and copying is expensive. Value skip lists shouldn't be used to store objects of a base class if any derived types of different sizes would be stored in the list, or if the destructor for a derived class must be called.
The iterator classes for skip lists have the same function and operator interface as the hash iterator classes. See the chapter on Hash Iterators for more information.
The WCExcept class is a base class of the WCValSkipListSet<Type> and WCValSkipList<Type> classes, and provides the exceptions() member function. This member function controls the exceptions that can be thrown by the WCValSkipListSet<Type> and WCValSkipList<Type> objects. No exceptions are enabled unless they're set by the exceptions() member function.
The WCValSkipListSet<Type> and WCValSkipList<Type> classes require Type to have the following:
Type::Type()
Type::Type( const Type & )
int operator ==( const Type & ) const
int operator <( const Type & ) const
The following member functions are declared in the public interface:
WCValSkipList( unsigned = WCSKIPLIST_PROB_QUARTER, unsigned = WCDEFAULT_SKIPLIST_MAX_PTRS ); WCValSkipList( unsigned = WCSKIPLIST_PROB_QUARTER, unsigned = WCDEFAULT_SKIPLIST_MAX_PTRS, void * (*user_alloc)( size_t size ), void (*user_dealloc)( void *old, size_t size ) ); WCValSkipList( const WCValSkipList & ); virtual ~WCValSkipList(); WCValSkipListSet( unsigned = WCSKIPLIST_PROB_QUARTER, unsigned = WCDEFAULT_SKIPLIST_MAX_PTRS ); WCValSkipListSet( unsigned = WCSKIPLIST_PROB_QUARTER, unsigned = WCDEFAULT_SKIPLIST_MAX_PTRS, void * (*user_alloc)( size_t size ), void (*user_dealloc)( void *old, size_t size ) ); WCValSkipListSet( const WCValSkipListSet & ); virtual ~WCValSkipListSet(); void clear(); int contains( const Type & ) const; unsigned entries() const; int find( const Type &, Type & ) const; void forAll( void (*user_fn)( Type, void * ), void * ); int insert( const Type & ); int isEmpty() const; int remove( const Type & );
The following public member functions are available for the WCValSkipList class only:
unsigned occurrencesOf( const Type & ) const; unsigned removeAll( const Type & );
The following member operators are declared in the public interface:
WCValSkipList & operator =( const WCValSkipList & ); int operator ==( const WCValSkipList & ) const; WCValSkipListSet & operator =( const WCValSkipListSet & ); int operator ==( const WCValSkipListSet & ) const;
create a WCValSkipListSet<Type> object
#include <wcskip.h> public: WCValSkipListSet( unsigned = WCSKIPLIST_PROB_QUARTER, unsigned = WCDEFAULT_SKIPLIST_MAX_PTRS ); WCValSkipListSet( unsigned = WCSKIPLIST_PROB_QUARTER, unsigned = WCDEFAULT_SKIPLIST_MAX_PTRS, void * (*user_alloc)( size_t ), void (*user_dealloc)( void *, size_t ) ); WCValSkipListSet( const WCValSkipListSet & );
There are three forms of the WCValSkipListSet<Type> constructor:
The first optional parameter, which defaults to the constant WCSKIPLIST_PROB_QUARTER, determines the probability of having a certain number of pointers in each skip list node. The second optional parameter, which defaults to the constant WCDEFAULT_SKIPLIST_MAX_PTRS, determines the maximum number of pointers that are allowed in any skip list node. WCDEFAULT_SKIPLIST_MAX_PTRS is the maximum effective value of the second parameter.
If an allocation failure occurs while creating the skip list, the out_of_memory exception is thrown if it's enabled.
The allocation function must return a zero if it can't perform the allocation. The deallocation function is passed the size as well as the pointer to the data. Your allocation system may take advantage of the characteristic that the allocation function is always called with the same size value for any particular instantiation of a skip list. To determine the size of the objects that the memory management functions are required to allocate and free, the following macro may be used:
WCValSkipListSetItemSize( Type, num_of_pointers )
If there isn't enough memory to copy all of the values, then only some are copied, and the number of entries correctly reflects the number copied. If all of the elements can't be copied, then the out_of_memory exception is thrown if it's enabled.
The WCValSkipListSet<Type> constructor creates an initialized WCValSkipListSet object.
WCExcept::out_of_memory, WCValSkipListSet<Type>::~WCValSkipListSet(), WCValSkipListSet<Type>::operator =()
destroy a WCValSkipListSet<Type> object
#include <wcskip.h> public: virtual ~WCValSkipListSet();
The WCValSkipListSet<Type> destructor is the destructor for the WCValSkipListSet class.
If the number of elements isn't zero and the not_empty exception is enabled, the exception is thrown. Otherwise, the list elements are cleared using the clear() member function.
The call to this destructor is inserted implicitly by the compiler at the point where the WCValSkipListSet object goes out of scope.
The WCValSkipListSet object is destroyed.
WCExcept::not_empty, WCValSkipListSet<Type>::clear()
create a WCValSkipList<Type> object
#include <wcskip.h> public: WCValSkipList( unsigned = WCSKIPLIST_PROB_QUARTER, unsigned = WCDEFAULT_SKIPLIST_MAX_PTRS ); WCValSkipList( unsigned = WCSKIPLIST_PROB_QUARTER, unsigned = WCDEFAULT_SKIPLIST_MAX_PTRS, void * (*user_alloc)( size_t ), void (*user_dealloc)( void *, size_t ) ); WCValSkipList( const WCValSkipList & );
There are three forms of the WCValSkipList<Type> constructor:
The first optional parameter, which defaults to the constant WCSKIPLIST_PROB_QUARTER, determines the probability of having a certain number of pointers in each skip list node. The second optional parameter, which defaults to the constant WCDEFAULT_SKIPLIST_MAX_PTRS, determines the maximum number of pointers that are allowed in any skip list node. WCDEFAULT_SKIPLIST_MAX_PTRS is the maximum effective value of the second parameter.
If an allocation failure occurs while creating the skip list, the out_of_memory exception is thrown if it's enabled.
The allocation function must return a zero if it can't perform the allocation. The deallocation function is passed the size as well as the pointer to the data. Your allocation system may take advantage of the characteristic that the allocation function is always called with the same size value for any particular instantiation of a skip list. To determine the size of the objects that the memory management functions are required to allocate and free, the following macro may be used:
WCValSkipListItemSize( Type, num_of_pointers )
If there isn't enough memory to copy all of the values, then only some are copied, and the number of entries correctly reflects the number copied. If all of the elements can't be copied, then the out_of_memory exception is thrown if it's enabled.
The WCValSkipList<Type> constructor creates an initialized WCValSkipList object.
WCExcept::out_of_memory, WCValSkipList<Type>::~WCValSkipList() WCValSkipList<Type>::operator =()
destroy a WCValSkipList<Type> object
#include <wcskip.h> public: virtual ~WCValSkipList();
The WCValSkipList<Type> destructor is the destructor for the WCValSkipList class.
If the number of elements isn't zero and the not_empty exception is enabled, the exception is thrown. Otherwise, the list elements are cleared using the clear() member function.
The call to this destructor is inserted implicitly by the compiler at the point where the WCValSkipList object goes out of scope.
The WCValSkipList object is destroyed.
WCExcept::not_empty, WCValSkipList<Type>::clear()
clear all the entries from the list
#include <wcskip.h> public: void clear();
The clear() public member function is used to clear the list so that it has no entries. Elements stored in the list are destroyed using the destructors of Type. The list object isn't destroyed and re-created by this function, so the object destructor isn't invoked.
The clear() public member function clears the list to have no elements.
WCValSkipListSet<Type>::~WCValSkipListSet(), WCValSkipList<Type>::~WCValSkipList(), WCValSkipListSet<Type>::operator =(), WCValSkipList<Type>::operator =()
determine whether or not an element is in the list
#include <wcskip.h> public: int contains( const Type & ) const;
The contains() public member function returns non-zero if the element is stored in the list, or zero if there is no equivalent element. Note that equivalence is based on the equivalence operator of the element type.
The contains() public member function returns a non-zero value if the element is found in the list.
WCValSkipListSet<Type>::find(), WCValSkipList<Type>::find()
count the elements in the list
#include <wcskip.h> public: unsigned entries() const;
The entries() public member function is used to return the current number of elements stored in the list.
The entries() public member function returns the number of elements in the list.
WCValSkipListSet<Type>::isEmpty(), WCValSkipList<Type>::isEmpty()
find an element in the list
#include <wcskip.h> public: int find( const Type &, Type & ) const;
The find() public member function is used to find an element with an equivalent value in the list.
Note that equivalence is based on the equivalence operator of the element type.
The element equivalent to the passed value is located in the list.
invoke a function for each element in the list
#include <wcskip.h> public: void forAll( void (*user_fn)( Type, void * ), void * );
The forAll() public member function causes the user-supplied function to be invoked for every value in the list. The user function has the prototype
void user_func( Type & value, void * data );
As the elements are visited, the user function is invoked with the element passed as the first. The second parameter of the forAll() function is passed as the second parameter to the user function. This value can be used to pass any appropriate data from the main program to the user function.
The elements in the list are all visited, and the user function is invoked for each one.
WCValSkipListSet<Type>::find(), WCValSkipList<Type>::find()
insert an element into the list
#include <wcskip.h> public: int insert( const Type & );
The insert() public member function inserts a value into the list. If allocation of the node to store the value fails, then the out_of_memory exception is thrown if it's enabled. If the exception isn't enabled, the insertion isn't completed.
With a WCValSkipListSet, there must be only one equivalent element in the set. If an element equivalent to the inserted element is already in the list set, the list set remains unchanged, and the not_unique exception is thrown if it's enabled. If the exception isn't enabled, the insertion isn't completed.
The insert() public member function inserts a value into the list. If the insertion is successful, a non-zero value is returned; zero is returned if it fails.
WCExcept::out_of_memory, WCExcept::not_unique, WCValSkipListSet<Type>::operator =(), WCValSkipList<Type>::operator =()
determine whether or not the list is empty
#include <wcskip.h> public: int isEmpty() const;
The isEmpty() public member function is used to determine if the list is empty.
The isEmpty() public member function returns zero if the list contains at least one entry, non-zero if it's empty.
WCValSkipListSet<Type>::entries(), WCValSkipList<Type>::entries()
count the elements that are equvalent to the passed value
#include <wcskip.h> public: unsigned occurrencesOf( const Type & ) const;
The occurrencesOf() public member function is used to return the current number of elements stored in the list that are equivalent to the passed value. Note that equivalence is based on the equivalence operator of the element type.
The occurrencesOf() public member function returns the number of elements in the list that are equivalent to the passed value.
WCValSkipList<Type>::entries(), WCValSkipList<Type>::find(), WCValSkipList<Type>::isEmpty()
assign one list to another
#include <wcskip.h> public: WCValSkipList & operator =( const WCValSkipList & ); WCValSkipListSet & operator =( const WCValSkipListSet & );
The operator =() public member function is the assignment operator for the WCValSkipListSet<Type> and WCValSkipList<Type> classes. The left hand side list is first cleared using the clear() member function, and then the right hand side list is copied. The list function, exception trap states, and all of the list elements are copied.
If there isn't enough memory to copy all of the values or pointers in the list, then only some are copied, and the out_of_memory exception is thrown if it's enabled. The number of entries correctly reflects the number copied.
The operator =() public member function sets the left hand side list to be a copy of the right hand side.
WCExcept::out_of_memory, WCValSkipListSet<Type>::clear(), WCValSkipList<Type>::clear()
determine whether or not two lists are equivalent
#include <wcskip.h> public: int operator ==( const WCValSkipList & ) const; int operator ==( const WCValSkipListSet & ) const;
The operator ==() public member function is the equivalence operator for the WCValSkipListSet<Type> and WCValSkipList<Type> classes. Two list objects are equivalent if they're the same object and share the same address.
A TRUE (non-zero) value is returned if the left hand side and right hand side list are the same object. A FALSE (zero) value is returned otherwise.
remove an element from the list
#include <wcskip.h> public: int remove( const Type & );
The remove() public member function is used to remove the specified element from the list.
If the list is a WCValSkipList and there's more than one element equivalent to the specified element, then the last equivalent element added to the list is removed. Note that equivalence is based on the equivalence operator of the element type.
The element is removed from the list.
remove all occurrences of an element from the list
#include <wcskip.h> public: unsigned removeAll( const Type & );
The removeAll() public member function is used to remove all elements equivalent to the specified element from the list. Zero is returned if no equivalent elements are found. Note that equivalence is based on the equivalence operator of the element type.
All equivalent elements are removed from the list.