Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
FragTable< T, E, A > Class Template Reference

#include <elm/data/FragTable.h>

+ Inheritance diagram for FragTable< T, E, A >:

Classes

class  BaseIter
 
class  Iter
 
class  MutIter
 

Public Types

typedef T t
 
typedef FragTable< T, E, A > self_t
 
- Public Types inherited from Equiv< T >
typedef T t
 

Public Member Functions

 FragTable (int size_pow=8)
 
 FragTable (const FragTable &t)
 
 ~FragTable (void)
 
int pageSize () const
 
int pagePower () const
 
bool pageFull () const
 
Iter begin () const
 
Iter end () const
 
int count (void) const
 
bool contains (const T &v) const
 
template<class C >
bool containsAll (const C &c) const
 
bool isEmpty () const
 
 operator bool (void) const
 
Iter items (void) const
 
Iter operator* (void) const
 
 operator Iter (void) const
 
bool equals (const self_t &t) const
 
bool operator== (const self_t &t) const
 
bool operator!= (const self_t &t) const
 
MutIter begin ()
 
MutIter end ()
 
void clear (void)
 
void add (const T &value)
 
template<template< class _ > class C>
void addAll (const C< T > &items)
 
void remove (const T &item)
 
template<template< class _ > class C>
void removeAll (const C< T > &items)
 
void remove (const Iter &iter)
 
self_toperator+= (const T &v)
 
self_toperator-= (const T &v)
 
int length (void) const
 
const T & get (int index) const
 
int indexOf (const T &value, int start=0) const
 
int lastIndexOf (const T &value, int start=-1) const
 
const T & operator[] (int index) const
 
void shrink (int length)
 
void set (int index, const T &value)
 
void set (const Iter &iter, const T &item)
 
T & get (int index)
 
T & operator[] (int index)
 
void insert (int index, const T &item)
 
void insert (const Iter &iter, const T &item)
 
void removeAt (int index)
 
void removeAt (const Iter &iter)
 
int alloc (int count)
 
- Public Member Functions inherited from Equiv< T >
bool isEqual (const T &v1, const T &v2) const
 
- Public Member Functions inherited from DefaultAllocatorDelegate
t::ptr allocate (t::size size) const
 
void free (t::ptr p) const
 
template<class T >
T * alloc () const
 

Additional Inherited Members

- Static Public Member Functions inherited from Equiv< T >
static bool equals (const T &v1, const T &v2)
 
- Static Public Attributes inherited from Equiv< T >
static Equiv< T > def
 

Detailed Description

template<class T, class E = Equiv<T>, class A = DefaultAlloc>
class elm::FragTable< T, E, A >

This container class allows indexed access to its data. It is implemented as expandable fragmented table using a two-level table traversal. The first level table selects a sub-table that contains the actual stored items.

Consequently, the access time is a bit longer than a classic table but small and constant. Yet, the table may be expanded without inducing a copy of already stored content. According the granularity / size of the sub-tables, the place / item count ratio overhead is pretty small : this class is a good candidate for big tables requiring dynamic expansion.

Complexity information (N items, chunks of size S):

  • access time: O(0)
  • addition time: O(0)
  • insertion time: O(N/2) average, O(N) worst case
  • removal time: O(N/2) average, O(N) worst case
  • object memory footprint: 6 ints + 8 pointers
  • per-item memory foot print: |N / S| pointers

Implemented concepts:

Parameters
TType of stored items.
MType of the data structure manager (default to EquivManager).

Member Typedef Documentation

◆ self_t

typedef FragTable<T, E, A> self_t

◆ t

typedef T t

Constructor & Destructor Documentation

◆ FragTable() [1/2]

FragTable ( int  chunk_size = 8)
inline

The constructor of a fragmented table.

Parameters
chunk_size2^chunk_size is the size of sub-tables (default to 256).

◆ FragTable() [2/2]

FragTable ( const FragTable< T, E, A > &  tab)
inline

Build a fragmented table by copy.

Parameters
tabTable to copy.

References FragTable< T, E, A >::addAll().

◆ ~FragTable()

~FragTable ( void  )
inline

Member Function Documentation

◆ add()

void add ( const T &  value)
inline

Add an item to the table.

Parameters
valueValue of the item to add.

Referenced by FragTable< T, E, A >::addAll(), and FragTable< T, E, A >::operator+=().

◆ addAll()

void addAll ( const C< T > &  items)
inline

Add a collection of item to the table.

Parameters
itemsItems to add.

References FragTable< T, E, A >::add(), and FragTable< T, E, A >::items().

Referenced by FragTable< T, E, A >::FragTable().

◆ alloc()

int alloc ( int  count)
inline

Allocate the given count of items in sequence in the table and return the index of the first item.

Parameters
countCount of items to allocate.
Returns
Index of the first item.

References FragTable< T, E, A >::count(), and FragTable< T, E, A >::length().

◆ begin() [1/2]

MutIter begin ( )
inline

◆ begin() [2/2]

Iter begin ( ) const
inline

◆ clear()

void clear ( void  )
inline

Remove all items from the fragmeted table and release as many memory as possible.

Referenced by FragTable< T, E, A >::~FragTable().

◆ contains()

bool contains ( const T &  item) const
inline

Test if the table contains the given item.

Parameters
itemItem to look for.
Returns
True if the item is contained in the table, false else.

References FragTable< T, E, A >::get(), and FragTable< T, E, A >::length().

Referenced by FragTable< T, E, A >::containsAll(), and elm::operator<=().

◆ containsAll()

bool containsAll ( const C &  c) const
inline

◆ count()

int count ( void  ) const
inline

◆ end() [1/2]

MutIter end ( )
inline

◆ end() [2/2]

Iter end ( ) const
inline

◆ equals()

bool equals ( const self_t t) const
inline

◆ get() [1/2]

T & get ( int  index)
inline

Same as FragTable::get() const but return a mutable reference.

Parameters
indexIndex of the looked item.
Returns
Reference on the matching item.

References FragTable< T, E, A >::length().

◆ get() [2/2]

const T & get ( int  index) const
inline

Get the item at the given index.

Warning
It is an error to pass an index greater or equal to the table length.
Parameters
indexIndex of the looked item.
Returns
Item matching the given index.

References FragTable< T, E, A >::length().

Referenced by FragTable< T, E, A >::contains(), FragTable< T, E, A >::insert(), FragTable< T, E, A >::BaseIter::item(), FragTable< T, E, A >::Iter::item(), FragTable< T, E, A >::MutIter::item(), FragTable< T, E, A >::lastIndexOf(), FragTable< T, E, A >::operator[](), and FragTable< T, E, A >::removeAt().

◆ indexOf()

int indexOf ( const T &  value,
int  start = 0 
) const
inline

Get the first index of a value in the array.

Parameters
valueValue to look for.
startStart index to look at (default to 0).
Returns
Index of the first value, -1 if the value is not found.

◆ insert() [1/2]

void insert ( const Iter iter,
const T &  item 
)
inline

◆ insert() [2/2]

void insert ( int  index,
const T &  item 
)
inline

Insert an item at the given position and move the following item in the next indexes.

Parameters
indexIndex to insert to.
itemItem to insert.

References DefaultAllocatorDelegate::alloc(), FragTable< T, E, A >::get(), FragTable< T, E, A >::length(), and FragTable< T, E, A >::set().

Referenced by FragTable< T, E, A >::insert().

◆ isEmpty()

bool isEmpty ( ) const
inline

Test if the fragmented table is empty.

Returns
True if it is empty, false else.

Referenced by FragTable< T, E, A >::operator bool().

◆ items()

◆ lastIndexOf()

int lastIndexOf ( const T &  value,
int  start = -1 
) const
inline

Get the last index of a value in the array.

Parameters
valueValue to look for.
startStart index to look back (default to -1 for end of array).
Returns
Index of the last value, -1 if the value is not found.

References FragTable< T, E, A >::get(), and FragTable< T, E, A >::length().

◆ length()

◆ operator bool()

operator bool ( void  ) const
inline

Same as !isEmpty().

Same as !isEmpty()/

References FragTable< T, E, A >::isEmpty().

◆ operator Iter()

operator Iter ( void  ) const
inline

◆ operator!=()

bool operator!= ( const self_t t) const
inline

◆ operator*()

Iter operator* ( void  ) const
inline

◆ operator+=()

FragTable< T > & operator+= ( const T &  v)
inline

Operator implementing FragTable::add().

Deprecated:

Operator implementing FragTable::add().

Deprecated:

References FragTable< T, E, A >::add().

◆ operator-=()

self_t& operator-= ( const T &  v)
inline

◆ operator==()

bool operator== ( const self_t t) const
inline

◆ operator[]() [1/2]

T & operator[] ( int  index)
inline

Operator implementing FragTable::get().

References FragTable< T, E, A >::get().

◆ operator[]() [2/2]

const T& operator[] ( int  index) const
inline

◆ pageFull()

bool pageFull ( ) const
inline

Test if the current page is full.

Returns
True if the page is full, false else.

◆ pagePower()

int pagePower ( ) const
inline

Get the page size as a power of 2.

Returns
Power of 2 page size.

◆ pageSize()

int pageSize ( ) const
inline

Get the page size (in elements).

Returns
Page size (in elements).

◆ remove() [1/2]

void remove ( const Iter iter)
inline

◆ remove() [2/2]

void remove ( const T &  item)
inline

Remove an item from the table.

Parameters
itemItem to remove.

Referenced by FragTable< T, E, A >::operator-=(), and FragTable< T, E, A >::removeAll().

◆ removeAll()

void removeAll ( const C< T > &  items)
inline

Remove a collection of items.

Parameters
itemsItems to remove.

References FragTable< T, E, A >::items(), and FragTable< T, E, A >::remove().

◆ removeAt() [1/2]

void removeAt ( const Iter iter)
inline

◆ removeAt() [2/2]

void removeAt ( int  index)
inline

Remove the item at the given index and shift back following items.

Parameters
indexIndex of the item to remove.

References FragTable< T, E, A >::get(), FragTable< T, E, A >::length(), and FragTable< T, E, A >::set().

Referenced by FragTable< T, E, A >::remove().

◆ set() [1/2]

void set ( const Iter iter,
const T &  item 
)
inline

◆ set() [2/2]

void set ( int  index,
const T &  value 
)
inline

◆ shrink()

void shrink ( int  length)
inline

Shrink the size of the table.

Parameters
lengthNew length of the table.

References FragTable< T, E, A >::length().


The documentation for this class was generated from the following files: