cgma
Hasher< Y, B > Class Template Reference

#include <IdHasher.hpp>

List of all members.

Classes

struct  BaseIter
class  iterator
struct  IterTag

Public Types

enum  { NumberOfBits = Y::NumberOfBits + B }
enum  { SubSize = Y::NumberOfBits }
enum  { MySize = 1 << B }
enum  { MyMask = ( 1 << SubSize ) - 1 }
typedef iterator const_iterator
typedef unsigned int Key
typedef Y::value_type value_type

Public Member Functions

 Hasher ()
 ~Hasher ()
bool add (Key idx, value_type ptr)
bool remove (Key idx)
const value_typeoperator[] (Key idx) const
value_typeoperator[] (Key idx)
Key count () const
iterator begin ()
iterator end ()
Key my_index (Key idx) const
Key sub_index (Key idx) const

Public Attributes

value_type Null

Private Attributes

Key mCount
YmChildren [MySize]

Detailed Description

template<class Y, unsigned int B>
class Hasher< Y, B >

Definition at line 17 of file IdHasher.hpp.


Member Typedef Documentation

template<class Y, unsigned int B>
typedef iterator Hasher< Y, B >::const_iterator

Definition at line 31 of file IdHasher.hpp.

template<class Y, unsigned int B>
typedef unsigned int Hasher< Y, B >::Key

Definition at line 34 of file IdHasher.hpp.

template<class Y, unsigned int B>
typedef Y::value_type Hasher< Y, B >::value_type

Definition at line 35 of file IdHasher.hpp.


Member Enumeration Documentation

template<class Y, unsigned int B>
anonymous enum
Enumerator:
NumberOfBits 

Definition at line 38 of file IdHasher.hpp.

{ NumberOfBits = Y::NumberOfBits + B };
template<class Y, unsigned int B>
anonymous enum
Enumerator:
SubSize 

Definition at line 41 of file IdHasher.hpp.

{ SubSize = Y::NumberOfBits };
template<class Y, unsigned int B>
anonymous enum
Enumerator:
MySize 

Definition at line 44 of file IdHasher.hpp.

{ MySize = 1 << B };
template<class Y, unsigned int B>
anonymous enum
Enumerator:
MyMask 

Definition at line 47 of file IdHasher.hpp.

{ MyMask = ( 1 << SubSize ) - 1 };

Constructor & Destructor Documentation

template<class Y, unsigned int B>
Hasher< Y, B >::Hasher ( ) [inline]

Definition at line 52 of file IdHasher.hpp.

           : Null(0)
  {
    for(Key i=0; i<MySize; i++)
      mChildren[i] = 0;
    mCount=0;
  }
template<class Y, unsigned int B>
Hasher< Y, B >::~Hasher ( ) [inline]

Definition at line 60 of file IdHasher.hpp.

  {
    for(Key i=0; i<MySize; i++)
      if(mChildren[i])
        delete mChildren[i];
  }

Member Function Documentation

template<class Y, unsigned int B>
bool Hasher< Y, B >::add ( Key  idx,
value_type  ptr 
) [inline]

Definition at line 69 of file IdHasher.hpp.

  {
    assert(ptr != 0);
    Key myidx = my_index(idx);
    Y* y = mChildren[myidx];
    if(!y)
    {
      y = mChildren[myidx] = new Y();
    }
    bool inserted = y->add(sub_index(idx), ptr);
    if(inserted)
    {
      this->mCount++;
    }
    return inserted;
  }
template<class Y, unsigned int B>
iterator Hasher< Y, B >::begin ( ) [inline]

Definition at line 126 of file IdHasher.hpp.

  {
    return iterator(this->mChildren, true);
  }
template<class Y, unsigned int B>
Key Hasher< Y, B >::count ( ) const [inline]

Definition at line 121 of file IdHasher.hpp.

  {
    return mCount;
  }
template<class Y, unsigned int B>
iterator Hasher< Y, B >::end ( ) [inline]

Definition at line 131 of file IdHasher.hpp.

  {
    return iterator(this->mChildren, false);
  }
template<class Y, unsigned int B>
Key Hasher< Y, B >::my_index ( Key  idx) const [inline]

Definition at line 229 of file IdHasher.hpp.

  {
    return idx >> SubSize;
  }
template<class Y, unsigned int B>
const value_type& Hasher< Y, B >::operator[] ( Key  idx) const [inline]

Definition at line 105 of file IdHasher.hpp.

  {
    Key myidx = my_index(idx);
    if(mChildren[myidx])
      return (*mChildren[myidx])[sub_index(idx)];
    return this->Null;
  }
template<class Y, unsigned int B>
value_type& Hasher< Y, B >::operator[] ( Key  idx) [inline]

Definition at line 113 of file IdHasher.hpp.

  {
    Key myidx = my_index(idx);
    if(mChildren[myidx])
      return (*mChildren[myidx])[sub_index(idx)];
    return this->Null;
  }
template<class Y, unsigned int B>
bool Hasher< Y, B >::remove ( Key  idx) [inline]

Definition at line 87 of file IdHasher.hpp.

  {
    Key myidx = my_index(idx);
    Y* y = mChildren[myidx];
    bool removed = y ? y->remove(sub_index(idx)) : false;
    if(removed)
    {
      this->mCount--;
      if(y->count() == 0)
      {
        delete mChildren[myidx];
        mChildren[myidx] = 0;
      }
    }
    return removed;
  }
template<class Y, unsigned int B>
Key Hasher< Y, B >::sub_index ( Key  idx) const [inline]

Definition at line 235 of file IdHasher.hpp.

  {
    return idx & MyMask;
  }

Member Data Documentation

template<class Y, unsigned int B>
Y* Hasher< Y, B >::mChildren[MySize] [private]

Definition at line 243 of file IdHasher.hpp.

template<class Y, unsigned int B>
Key Hasher< Y, B >::mCount [private]

Definition at line 242 of file IdHasher.hpp.

template<class Y, unsigned int B>
value_type Hasher< Y, B >::Null

Definition at line 49 of file IdHasher.hpp.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines