home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cset21v1.zip
/
IBMCPP
/
IBMCLASS
/
IIAVLKSS.H
< prev
next >
Wrap
Text File
|
1993-09-22
|
9KB
|
194 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 _IIAVLKSS_H
#define _IIAVLKSS_H
#include <iglobals.h>
class IAvlKeySortedSetImpl {
public:
class Node {
friend class IAvlKeySortedSetImpl;
Node* ivLeft;
Node* ivRight;
Node* ivParent;
short ivDeeperSubtree;
Node*& link (short dir);
void parent (Node*& P, short& dir);
void connectChild (short dir, Node*);
void connectChild0 (short dir, Node*);
public:
Node ();
};
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* elementAt (void* node) const = 0;
virtual void const*
constElementAt (void const* node) const = 0;
virtual void const*
keyAt (void const* node) const = 0;
virtual long compareKeyToElement (void const* node,
void const* element) const = 0;
virtual long compareKeyToKey (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;
virtual long functionComparison (void *compareFunction,
void const* node1,
void const* node2) = 0;
friend class IAvlKeySortedSetImpl;
};
private :
Operations* ivOps;
Node* ivRoot;
INumber ivNumberOfElements;
void replace (Node* oldNode, Node* newNode);
void deleteTree (Node*);
void balance (Node*, short dir, IBoolean&);
void disconnectAndRemove (Node*, IBoolean&);
Node* copySubtree (Node const*);
IBoolean locateElementWithKeyOfElement
(void const* element,
Node*&) const;
IBoolean containsAllKeysFromSubtree
(Node const*) const;
void unionWithSubtree (Node const*);
IBoolean allElementsDoSubtree(void* function,
void* environment,
Node const*) const;
IBoolean allElementsDoSubtree(void* function,
void* environment,
Node*);
IBoolean allElementsDoSubtree(void* iterator,
Node const*) const;
IBoolean allElementsDoSubtree(void* iterator,
Node*);
public:
IAvlKeySortedSetImpl (Operations*);
IAvlKeySortedSetImpl (IAvlKeySortedSetImpl const&,
Operations*);
void operator= (IAvlKeySortedSetImpl const&);
virtual ~IAvlKeySortedSetImpl ();
IBoolean add (void const* element);
IBoolean add (void const* element,
Node*&);
void addAllFrom (IAvlKeySortedSetImpl const&);
void const* elementAt (Node const*) const;
void* elementAt (Node*);
void removeAt (Node*);
INumber removeAll (void* predicate,
void* environment);
void replaceAt (Node*,
void const* element);
void removeAll ();
IBoolean isBounded () const;
IPosition numberOfElements () const
{ return ivNumberOfElements; }
IBoolean isEmpty () const
{ return ivRoot == 0; }
IBoolean isFull () const;
IBoolean setToFirst (Node*&) const;
IBoolean setToNext (Node*&) const;
IBoolean allElementsDo (void* function,
void* environment) const;
IBoolean allElementsDo (void* function,
void* environment);
IBoolean allElementsDo (void* iterator) const;
IBoolean allElementsDo (void* iterator);
INumber removeAllOccurences (void const* element);
IBoolean containsAllKeysFrom (IAvlKeySortedSetImpl const&) const;
IBoolean containsElementWithKey
(void const* key) const;
IBoolean locateElementWithKey(void const* key,
Node*&) const;
IBoolean replaceElementWithKey
(void const* element,
Node*&);
IBoolean replaceElementWithKey
(void const* element);
IBoolean addOrReplaceElementWithKey
(void const* element,
Node*&);
IBoolean addOrReplaceElementWithKey
(void const* element);
IBoolean locateOrAddElementWithKey
(void const* element,
Node*&);
IBoolean locateOrAddElementWithKey
(void const* element);
IBoolean removeElementWithKey(void const* key);
void const* elementWithKey (void const* key) const;
void* elementWithKey (void const* key);
void removeFirst ();
void removeLast ();
void removeAtPosition (IPosition);
void const* firstElement () const;
void const* lastElement () const;
void const* elementAtPosition (IPosition) const;
IBoolean setToLast (Node*&) const;
IBoolean setToPrevious (Node*&) const;
void setToPosition (IPosition,
Node*&) const;
IBoolean isFirst (Node const*) const;
IBoolean isLast (Node const*) const;
long compare (IAvlKeySortedSetImpl const&,
void *function) const;
IBoolean checkNode (Node const*, Node*) const;
IBoolean checkNode (Node const*) const;
IBoolean isConsistent () const;
protected:
IBoolean isConsistent (Node const* n,
int& depth, int& nrOfElm) const;
};
#endif