Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

Core::SearchTreeNode Class Reference

#include <SearchTreeNode.h>

Inheritance diagram for Core::SearchTreeNode:

Inheritance graph
[legend]
Collaboration diagram for Core::SearchTreeNode:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 SearchTreeNode (void)
virtual StringclassName (void) const
 Answer receiver class name.
virtual SearchTreeNodecreateNewNode (void)
virtual Objectat (SequenceableCollection *key)
virtual Objectat (SequenceableCollection *key, Object *ifAbsentValue)
virtual void put (SequenceableCollection *key, Object *value)
virtual ObjectatLongestPrefixOf (SequenceableCollection *key)
virtual bool includesKey (SequenceableCollection *key)
virtual ObjectvalueAt (SequenceableCollection *key, int depth, bool prefix)
virtual void putValueAt (SequenceableCollection *key, Object *value, int depth)
virtual ObjectprivDeeperValueAt (SequenceableCollection *key, int depth, bool prefix)

Protected Attributes

Dictionarybranches
Object_value

Constructor & Destructor Documentation

SearchTreeNode::SearchTreeNode void   ) 
 

Definition at line 34 of file SearchTreeNode.cc.

References _value, branches, and nil.

00035 {
00036     branches = new Dictionary(2);
00037     _value = nil;
00038 }


Member Function Documentation

Object * SearchTreeNode::at SequenceableCollection key,
Object ifAbsentValue
[virtual]
 

Definition at line 57 of file SearchTreeNode.cc.

References at().

00058 {
00059     Object *obj;
00060 
00061     try {
00062         obj = at(key);
00063     }
00064     catch (KeyNotFoundError *ex) {
00065         obj = ifAbsentValue;
00066     }
00067     return obj;
00068 }

Object * SearchTreeNode::at SequenceableCollection key  )  [virtual]
 

Definition at line 52 of file SearchTreeNode.cc.

References valueAt().

Referenced by at(), and includesKey().

00053 {
00054     return valueAt(key, 0, false);
00055 }

Object * SearchTreeNode::atLongestPrefixOf SequenceableCollection key  )  [virtual]
 

Definition at line 75 of file SearchTreeNode.cc.

References valueAt().

00076 {
00077     return valueAt(key, 0, true);
00078 }

String * SearchTreeNode::className void   )  const [virtual]
 

Answer receiver class name.

Because there isn't any standard way to obtain class name this method comes to place.

Every class should rewrite this method but many didn't (yet).

Reimplemented from Core::Object.

Definition at line 41 of file SearchTreeNode.cc.

00042 {
00043     return new String("SearchTreeNode");
00044 }

SearchTreeNode * SearchTreeNode::createNewNode void   )  [virtual]
 

Definition at line 46 of file SearchTreeNode.cc.

Referenced by putValueAt().

00047 {
00048     return new SearchTreeNode;
00049 }

bool SearchTreeNode::includesKey SequenceableCollection key  )  [virtual]
 

Definition at line 81 of file SearchTreeNode.cc.

References at(), and nil.

00082 {
00083     return at(key, nil) != nil;
00084 }

Object * SearchTreeNode::privDeeperValueAt SequenceableCollection key,
int  depth,
bool  prefix
[virtual]
 

Definition at line 113 of file SearchTreeNode.cc.

References Core::Dictionary::at(), branches, and valueAt().

Referenced by valueAt().

00115 {
00116     SearchTreeNode *next;
00117     next = dynamic_cast<SearchTreeNode *>(branches->at(key->at(depth)));
00118     return next->valueAt(key, depth+1, prefix);
00119 }

void SearchTreeNode::put SequenceableCollection key,
Object value
[virtual]
 

Definition at line 70 of file SearchTreeNode.cc.

References putValueAt().

00071 {
00072     putValueAt(key, value, 0);
00073 }

void SearchTreeNode::putValueAt SequenceableCollection key,
Object value,
int  depth
[virtual]
 

Definition at line 121 of file SearchTreeNode.cc.

References _value, Core::Dictionary::at(), branches, createNewNode(), Core::Dictionary::includesKey(), Core::Dictionary::put(), and putValueAt().

Referenced by put(), and putValueAt().

00123 {
00124     if (key->size() > depth) {
00125         SearchTreeNode *next;
00126         if (branches->includesKey(key->at(depth)))
00127             next = dynamic_cast<SearchTreeNode *>(branches->at(key->at(depth)));
00128         else {
00129             next = createNewNode();
00130             branches->put(key->at(depth), next);
00131         }
00132         next->putValueAt(key, value, depth+1);
00133     } else {
00134         _value = value;
00135     }
00136 }

Object * SearchTreeNode::valueAt SequenceableCollection key,
int  depth,
bool  prefix
[virtual]
 

Definition at line 87 of file SearchTreeNode.cc.

References _value, branches, Core::Collection::isEmpty(), nil, privDeeperValueAt(), and Core::SequenceableCollection::size().

Referenced by at(), atLongestPrefixOf(), and privDeeperValueAt().

00089 {
00090     if (key->size() > depth) {
00091         if (branches->isEmpty() && prefix)
00092             return _value;
00093         else {
00094             if (_value == nil || !prefix) {
00095                 return privDeeperValueAt(key, depth, prefix);
00096             } else {
00097                 /* I know the value. If there is no better answer, I got one. */
00098                 try {
00099                     return privDeeperValueAt(key, depth, prefix);
00100                 }
00101                 catch (KeyNotFoundError *ex) {
00102                     return _value;
00103                 }
00104             }
00105         }
00106     } else {
00107         if (_value == nil)
00108             (new KeyNotFoundError(__PRETTY_FUNCTION__, key))->raiseFrom(this);
00109         return _value;
00110     }
00111 }


Member Data Documentation

Object* Core::SearchTreeNode::_value [protected]
 

Definition at line 39 of file SearchTreeNode.h.

Referenced by putValueAt(), SearchTreeNode(), and valueAt().

Dictionary* Core::SearchTreeNode::branches [protected]
 

Definition at line 38 of file SearchTreeNode.h.

Referenced by privDeeperValueAt(), putValueAt(), SearchTreeNode(), and valueAt().


The documentation for this class was generated from the following files:
Generated on Mon Nov 27 09:51:54 2006 for Smalltalk like C++ Class Library by  doxygen 1.4.2