home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cset21v1.zip
/
IBMCPP
/
IBMCLASS
/
IIHSHKB.H
< prev
next >
Wrap
Text File
|
1993-09-22
|
9KB
|
224 lines
/*******************************************************************************
* *
* COPYRIGHT: *
* IBM C/C++ Tools Version 2.01 - Collection Class Library *
* Licensed Materials - Property of IBM *
* (C) Copyright IBM Corporation 1992, 1993 *
* All Rights Reserved *
* US Government Users Restricted Rights - Use, duplication, or disclosure *
* restricted by GSA ADP Schedule Contract with IBM Corp. *
* *
*******************************************************************************/
#ifndef _IIHSHKB_H
#define _IIHSHKB_H
#include <stdlib.h>
#include <iglobals.h>
class IHashKeyBagImpl {
public:
class Node {
friend class IHashKeyBagImpl;
Node* ivNext;
};
class Operations {
virtual Node* newNode (void const* element) const = 0;
virtual Node* copyNode (void const* node) const = 0;
virtual void deleteNode (void* node) const = 0;
virtual void* newBlock (size_t) const = 0;
virtual void removeBlock (void*, size_t) const = 0;
virtual INumber getHashvalue (void const* key, INumber) const = 0;
virtual void* elementAt (void* node) const = 0;
virtual void const*
keyAt (void const* node) const = 0;
virtual IBoolean isKeyEqualToElement (void const* node,
void const* element) const = 0;
virtual IBoolean isKeyEqualToKey (void const* node,
void const* key) const = 0;
virtual void copyFrom (void* node,
void const* element) const = 0;
virtual IBoolean constantFunctionIteration
(void *function,
void* env,
void const* node) = 0;
virtual IBoolean functionIteration (void *function,
void* env,
void* node) = 0;
virtual IBoolean constantIteratorIteration
(void* iterator,
void const* node) = 0;
virtual IBoolean iteratorIteration (void* iterator,
void* node) = 0;
friend class IHashKeyBagImpl;
};
class Cursor {
public:
INumber ivEntryNumber;
Node* ivNode;
Cursor () : ivNode (0) {}
IBoolean operator== (Cursor const& cursor) const
{ return ivNode == cursor.ivNode &&
ivEntryNumber == cursor.ivEntryNumber; }
IBoolean operator!= (Cursor const& cursor) const
{ return ! operator== (cursor); }
};
private :
Operations* ivOps;
INumber ivNoEntries;
INumber ivNoElements;
Node** ivTable;
INumber* ivCollList;
void createHashtable (INumber);
void copyHashtable (IHashKeyBagImpl const&);
void resize (Node*, INumber&);
IHashKeyBagImpl () {};
public:
IHashKeyBagImpl (INumber, Operations*);
IHashKeyBagImpl (IHashKeyBagImpl const&, Operations*);
~IHashKeyBagImpl ();
IBoolean add (void const* element,
INumber,
Cursor&);
IBoolean add (void const* element,
INumber);
void addAllFrom (IHashKeyBagImpl const&);
IHashKeyBagImpl& operator= (IHashKeyBagImpl const&);
void const* elementAt (Cursor const&) const;
void* elementAt (Cursor const&);
void const* anyElement () const;
void removeAt (Cursor const&);
INumber removeAll (void* predicate,
void* environment);
void replaceAt (Cursor const&,
void const* element);
void removeAll ();
IBoolean isBounded () const;
INumber maxNumberOfElements () const;
INumber numberOfElements () const
{ return ivNoElements; }
IBoolean isEmpty () const
{ return ivNoElements == 0; }
IBoolean isFull () const;
IBoolean setToFirst (Cursor&) const;
IBoolean setToNext (Cursor&) const;
IBoolean allElementsDo (void* function,
void* environment) const;
IBoolean allElementsDo (void* function,
void* environment);
IBoolean allElementsDo (void* iterator) const;
IBoolean allElementsDo (void* iterator);
// Keycollection methods
public:
IBoolean containsAllKeysFrom (IHashKeyBagImpl const&) const;
IBoolean containsElementWithKey
(void const* key, INumber)const;
INumber numberOfElementsWithKey
(void const* key, INumber) const;
IBoolean locateElementWithKey(void const* key,
INumber,
Cursor&) const;
private:
IBoolean locateElementWithKeyOfElement
(void const* element,
INumber,
Cursor&) const;
public:
IBoolean replaceElementWithKey
(void const* element,
INumber,
Cursor&);
IBoolean replaceElementWithKey
(void const* element,
INumber);
IBoolean locateOrAddElementWithKey
(void const* element,
INumber,
Cursor&);
IBoolean locateOrAddElementWithKey
(void const* element,
INumber);
IBoolean addOrReplaceElementWithKey
(void const* element,
INumber,
Cursor&);
IBoolean addOrReplaceElementWithKey
(void const* element,
INumber);
IBoolean removeElementWithKey(void const* key, INumber);
void const* elementWithKey (void const* key, INumber)const;
void* elementWithKey (void const* key, INumber);
IBoolean locateNextElementWithKey
(void const* key,
INumber,
Cursor&) const;
INumber removeAllElementsWithKey
(void const* key, INumber);
INumber numberOfDifferentKeys
() const;
IBoolean setToNextWithDifferentKey
(Cursor&) const;
INumber noEntries () const;
IBoolean checkCursor (Cursor const&) const;
IBoolean isConsistent () const;
};
#endif