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

SExpressionHashTable Class Reference

#include <shashtbl.hpp>

Inheritance diagram for SExpressionHashTable:

Inheritance graph
[legend]
Collaboration diagram for SExpressionHashTable:

Collaboration graph
[legend]
List of all members.

Detailed Description

Hash table.

The class implements hash tables similar to those from Common Lisp

Definition at line 56 of file shashtbl.hpp.

Public Member Functions

 SExpressionHashTable (SEqualityPredicate eqp=0)
 The constructor.
virtual class SString TextRepresentation () const
 Text representation of the S-expression.
virtual SExpressionClone () const
 Clone a changeable object.
void AddItem (SReference key, SReference val)
 Add a new item.
bool SafeAddItem (SReference key, SReference val)
 Add a new item safely.
SReference FindItem (SReference key, const SReference &defval=EmptySlotMark) const
 Find item.
SReferenceGetItemPosition (SReference key)
 Get the position where to store an item.
bool RemoveItem (SReference key)
 Remove item.
long Count () const
 Items count.
void Clear ()
 Clear the table.
const IntelibTypeIdTermType () const
 Actual S-expression type.
bool IsChangeable () const
 Can it be changed during the lifetime of the object?
virtual bool SpecificEql (const SExpression *) const
 Are the two objects EQL (while not EQ).

Static Public Attributes

static IntelibTypeId TypeId
 The type identifier.
static SLabel EmptySlotMark
 Empty slot mark.

Protected Member Functions

 SExpressionHashTable (const IntelibTypeId &id, SEqualityPredicate eqp=0)
 ~SExpressionHashTable ()
bool CanDie ()
 Is it OK to delete the object now?

Friends

class Iterator::Iterator

Classes

class  Iterator
 Iterator to walk through the hash table. More...


Constructor & Destructor Documentation

SExpressionHashTable::SExpressionHashTable SEqualityPredicate  eqp = 0  ) 
 

The constructor.

Parameters:
eqp is the equality predicate; by default, EQUAL is used

Definition at line 116 of file shashtbl.cpp.

References SExprsAreEqual().

Referenced by Clone().

SExpressionHashTable::SExpressionHashTable const IntelibTypeId id,
SEqualityPredicate  eqp = 0
[protected]
 

Definition at line 126 of file shashtbl.cpp.

References SExprsAreEqual().

SExpressionHashTable::~SExpressionHashTable  )  [protected]
 

Definition at line 137 of file shashtbl.cpp.


Member Function Documentation

SString SExpressionHashTable::TextRepresentation  )  const [virtual]
 

Text representation of the S-expression.

Returns the text string which represents the given S-expression as for real Lisp (for example, (25 36 49))

Implements SExpression.

Definition at line 240 of file shashtbl.cpp.

References SReference::GetPtr(), SExprsAreEq(), SExprsAreEql(), and SExprsAreEqual().

SExpression * SExpressionHashTable::Clone  )  const [virtual]
 

Clone a changeable object.

The method should return the pointer created with new

Note:
It can (and should) return null pointer for non-changeables
Warning:
This method will hang your program being called for a looped data structure, including looped lists, a hash table which references a list in which it is a member, etc.

If you create a changeable S-expression, you MUST make sure this method duplicates your object in such a way that nothing is shared between the old and new objects, that is, changing the new object can not in any way change the old object.

Reimplemented from SExpression.

Definition at line 142 of file shashtbl.cpp.

References SReference::Clone(), dim, itemcount, lastfoundpos, SExpressionHashTable(), and table.

void SExpressionHashTable::AddItem SReference  key,
SReference  val
 

Add a new item.

If there's already an item with the given key, it is replaced

Definition at line 155 of file shashtbl.cpp.

References GetItemPosition().

Referenced by SExpressionHashPackage::Import(), and SExpressionHashPackage::Intern().

bool SExpressionHashTable::SafeAddItem SReference  key,
SReference  val
 

Add a new item safely.

If there was no such item, add one and returns true. If an item with the same key already exists, do nothing and return false.

Definition at line 160 of file shashtbl.cpp.

References EmptySlotMark, GetItemPosition(), and SReference::GetPtr().

Referenced by SExpressionHashPackage::Import().

SReference SExpressionHashTable::FindItem SReference  key,
const SReference defval = EmptySlotMark
const
 

Find item.

Find an item with the given key. Return defval value if none found, or else return the found value (key is assumed to be the same)

Definition at line 172 of file shashtbl.cpp.

References SExpressionCons::Car(), SExpressionCons::Cdr(), SReference::GetPtr(), and LispHash().

Referenced by SExpressionHashPackage::FindSymbol().

SReference & SExpressionHashTable::GetItemPosition SReference  key  ) 
 

Get the position where to store an item.

Gets reference to the value position. If there's no such key, new entry is created. If the entry remains unbound, the table removes it at the next call to GetItemPosition()

Warning:
You must use the value returned by this method BEFORE another call to this method. The subsequent call may cause rehashing so that your reference become invalid.

Definition at line 188 of file shashtbl.cpp.

References SExpressionCons::Car(), SExpressionCons::Cdr(), EmptySlotMark, SReference::GetPtr(), and LispHash().

Referenced by AddItem(), and SafeAddItem().

bool SExpressionHashTable::RemoveItem SReference  key  ) 
 

Remove item.

Removes the item. Returns true if there was one, false othervise

Definition at line 217 of file shashtbl.cpp.

References SExpressionCons::Car(), SReference::GetPtr(), and LispHash().

long SExpressionHashTable::Count  )  const
 

Items count.

Return total amount of items in the table

Definition at line 129 of file shashtbl.hpp.

void SExpressionHashTable::Clear  ) 
 

Clear the table.

Remove all existing items from the table

Definition at line 232 of file shashtbl.cpp.

const IntelibTypeId& SExpression::TermType  )  const [inherited]
 

Actual S-expression type.

Definition at line 195 of file sexpress.hpp.

Referenced by SReference::DynamicCastGetPtr(), SchReference::IsEql(), LReference::IsEql(), SReference::SimpleCastGetPtr(), SchReference::TextRepresentation(), and LReference::TextRepresentation().

bool SExpression::IsChangeable  )  const [inherited]
 

Can it be changed during the lifetime of the object?

Definition at line 198 of file sexpress.hpp.

References IntelibTypeId::IsChangeable().

virtual bool SExpression::SpecificEql const SExpression  )  const [virtual, inherited]
 

Are the two objects EQL (while not EQ).

This function is overriden by those SExpressions able to be EQL while being not EQ.

Warning:
It is not demanded that this function return true if it's arguments are the same SExpression (that is, they're EQ). It is only called by the EQL predicate implementation when it has been checked that the operands are not the same object.

Reimplemented in SExpressionInt, SExpressionFloat, SExpressionChar, and SExpressionString.

Definition at line 235 of file sexpress.hpp.

Referenced by SchReference::IsEql(), and LReference::IsEql().

bool GarbageSafe::CanDie  )  [protected, inherited]
 

Is it OK to delete the object now?

Our children have no access to the private attribute RefCount and should never need it except when checking if the destruction is not an error. This solves the problem.

Definition at line 53 of file refcount.hpp.


Friends And Related Function Documentation

friend class Iterator::Iterator [friend]
 

Definition at line 153 of file shashtbl.hpp.


Member Data Documentation

IntelibTypeId SExpressionHashTable::TypeId [static]
 

The type identifier.

Reimplemented from SExpression.

Reimplemented in SExpressionHashPackage, LExpressionPackage, and SchExpressionPackage.

SLabel SExpressionHashTable::EmptySlotMark [static]
 

Empty slot mark.

This object is returned as a search result when the given key is not found in the table

Referenced by GetItemPosition(), and SafeAddItem().


The documentation for this class was generated from the following files:
Generated on Tue Dec 18 00:41:17 2007 for InteLib by  doxygen 1.4.1