CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
edm::Trie< T > Class Template Reference

#include <Trie.h>

Public Member Functions

void clear ()
 clear the content of trie More...
 
void display (std::ostream &os)
 display content of trie in output stream More...
 
const Tfind (std::string const &str) const
 get an entry in the Trie More...
 
const Tfind (const char *str, unsigned strLen) const
 
const TrieNode< T > * initialNode () const
 get initial TrieNode More...
 
void insert (std::string const &str, const T &value)
 
void insert (const char *str, unsigned strLen, const T &value)
 
const TrieNode< T > * node (std::string const &str) const
 get node matching a string More...
 
const TrieNode< T > * node (const char *str, unsigned strLen) const
 
void setEntry (std::string const &str, const T &value)
 
void setEntry (const char *str, unsigned strLen, const T &value)
 
 Trie (const T &empty)
 
 ~Trie ()
 

Private Member Functions

TrieNode< T > * _addEntry (const char *str, unsigned strLen)
 
Trieoperator= (const Trie &e)=delete
 avoid affectation operator More...
 
 Trie ()=delete
 avoid default constructor More...
 
 Trie (const Trie &e)=delete
 avoid copy constructor More...
 

Private Attributes

T _empty
 value returned when no match is found in trie More...
 
TrieFactory< T > * _factory
 factory More...
 
TrieNode< T > * _initialNode
 first node of trie More...
 

Detailed Description

template<typename T>
class edm::Trie< T >

Implement a trie in memory with the smallest structure as possible (use few RAM as possible)

Definition at line 168 of file Trie.h.

Constructor & Destructor Documentation

template<typename T >
edm::Trie< T >::Trie ( const T empty)

constuctor, empty is the value returned when no match in found in trie

Definition at line 492 of file Trie.h.

References edm::Trie< T >::_empty, edm::Trie< T >::_factory, and edm::Trie< T >::_initialNode.

492  : _empty(empty), _factory(0x0), _initialNode(0x0) {
493  // initialize nodes by paquets of 10000
494  _factory = new TrieFactory<T>(10000);
495  _initialNode = _factory->newNode(_empty);
496 }
T _empty
value returned when no match is found in trie
Definition: Trie.h:210
TrieFactory< T > * _factory
factory
Definition: Trie.h:212
TrieNode< T > * _initialNode
first node of trie
Definition: Trie.h:214
template<typename T >
edm::Trie< T >::~Trie ( )

Definition at line 499 of file Trie.h.

References edm::Trie< T >::_factory.

499  {
500  delete _factory;
501 }
TrieFactory< T > * _factory
factory
Definition: Trie.h:212
template<typename T >
edm::Trie< T >::Trie ( )
privatedelete

avoid default constructor

template<typename T >
edm::Trie< T >::Trie ( const Trie< T > &  e)
privatedelete

avoid copy constructor

Member Function Documentation

template<typename T >
edm::TrieNode< T > * edm::Trie< T >::_addEntry ( const char *  str,
unsigned  strLen 
)
private

Definition at line 514 of file Trie.h.

References edm::Trie< T >::_empty, edm::Trie< T >::_factory, edm::Trie< T >::_initialNode, edm::TrieNode< T >::addSubNode(), newFWLiteAna::found, mps_fire::i, edm::Trie< T >::node(), and edm::TrieNode< T >::subNodeByLabel().

Referenced by edm::Trie< T >::insert(), and edm::Trie< T >::setEntry().

514  {
515  unsigned pos = 0;
516  bool found = true;
517  TrieNode<T> *node = _initialNode, *previous = 0x0;
518 
519  // Look for the part of the word which is in Trie
520  while (found && pos < strLen) {
521  found = false;
522  previous = node;
523  node = node->subNodeByLabel(str[pos]);
524  if (node) {
525  found = true;
526  ++pos;
527  }
528  }
529 
530  // Add part of the word which is not in Trie
531  if (!node || pos != strLen) {
532  node = previous;
533  for (unsigned i = pos; i < strLen; ++i) {
534  TrieNode<T> *newNode = _factory->newNode(_empty);
535  node->addSubNode(str[pos], newNode);
536  node = newNode;
537  ++pos;
538  }
539  }
540  assert(node != 0x0);
541  return node;
542 }
T _empty
value returned when no match is found in trie
Definition: Trie.h:210
TrieFactory< T > * _factory
factory
Definition: Trie.h:212
TrieNode< T > * _initialNode
first node of trie
Definition: Trie.h:214
#define str(s)
const TrieNode< T > * node(std::string const &str) const
get node matching a string
Definition: Trie.h:584
template<typename T >
void edm::Trie< T >::clear ( void  )
template<typename T >
void edm::Trie< T >::display ( std::ostream &  os)

display content of trie in output stream

Definition at line 617 of file Trie.h.

References edm::Trie< T >::_initialNode.

617  {
618  if (_initialNode)
619  _initialNode->display(os, 0, 0);
620 }
TrieNode< T > * _initialNode
first node of trie
Definition: Trie.h:214
template<typename T >
const T & edm::Trie< T >::find ( std::string const &  str) const

get an entry in the Trie

Definition at line 560 of file Trie.h.

Referenced by BeautifulSoup.Tag::__getattr__(), and BeautifulSoup.Tag::firstText().

560  {
561  return find(str.c_str(), str.size());
562 }
const T & find(std::string const &str) const
get an entry in the Trie
Definition: Trie.h:560
#define str(s)
template<typename T >
const T & edm::Trie< T >::find ( const char *  str,
unsigned  strLen 
) const

Definition at line 565 of file Trie.h.

References edm::Trie< T >::_empty, edm::Trie< T >::_initialNode, newFWLiteAna::found, edm::Trie< T >::node(), edm::TrieNode< T >::subNodeByLabel(), and edm::TrieNode< T >::value().

Referenced by BeautifulSoup.Tag::__getattr__(), and BeautifulSoup.Tag::firstText().

565  {
566  unsigned pos = 0;
567  bool found = true;
568  const TrieNode<T> *node = _initialNode;
569 
570  while (found && pos < strLen) {
571  found = false;
572  node = node->subNodeByLabel(str[pos]);
573  if (node) {
574  found = true;
575  ++pos;
576  }
577  }
578  if (node && pos == strLen) // The word is complet in the automaton
579  return node->value();
580  return _empty;
581 }
T _empty
value returned when no match is found in trie
Definition: Trie.h:210
TrieNode< T > * _initialNode
first node of trie
Definition: Trie.h:214
#define str(s)
const TrieNode< T > * node(std::string const &str) const
get node matching a string
Definition: Trie.h:584
template<typename T >
const edm::TrieNode< T > * edm::Trie< T >::initialNode ( ) const

get initial TrieNode

Definition at line 606 of file Trie.h.

References edm::Trie< T >::_initialNode.

606  {
607  return _initialNode;
608 }
TrieNode< T > * _initialNode
first node of trie
Definition: Trie.h:214
template<typename T >
void edm::Trie< T >::insert ( std::string const &  str,
const T value 
)

add an entry in the Trie, if entry already exist an exception is throw

Definition at line 545 of file Trie.h.

References relativeConstraints::value.

Referenced by BeautifulSoup.PageElement::append().

545  {
546  insert(str.c_str(), str.size(), value);
547 }
void insert(std::string const &str, const T &value)
Definition: Trie.h:545
#define str(s)
template<typename T >
void edm::Trie< T >::insert ( const char *  str,
unsigned  strLen,
const T value 
)

Definition at line 550 of file Trie.h.

References edm::Trie< T >::_addEntry(), edm::Trie< T >::_empty, edm::detailsTrie::errorInsert(), edm::Trie< T >::node(), edm::TrieNode< T >::setValue(), AlCaHLTBitMon_QueryRunRegistry::string, and edm::TrieNode< T >::value().

Referenced by BeautifulSoup.PageElement::append().

550  {
551  TrieNode<T> *node = _addEntry(str, strLen);
552 
553  // Set the value on the last node
554  if (node && node->value() != _empty)
556  node->setValue(value);
557 }
T _empty
value returned when no match is found in trie
Definition: Trie.h:210
Definition: value.py:1
void errorInsert(std::string const &key)
Definition: Trie.h:482
#define str(s)
const TrieNode< T > * node(std::string const &str) const
get node matching a string
Definition: Trie.h:584
TrieNode< T > * _addEntry(const char *str, unsigned strLen)
Definition: Trie.h:514
template<typename T >
edm::TrieNode< T > const * edm::Trie< T >::node ( std::string const &  str) const

get node matching a string

Definition at line 584 of file Trie.h.

Referenced by edm::Trie< T >::_addEntry(), edm::Trie< T >::find(), edm::Trie< T >::insert(), edm::Trie< T >::node(), and edm::Trie< T >::setEntry().

584  {
585  return node(str.c_str(), str.size());
586 }
#define str(s)
const TrieNode< T > * node(std::string const &str) const
get node matching a string
Definition: Trie.h:584
template<typename T >
edm::TrieNode< T > const * edm::Trie< T >::node ( const char *  str,
unsigned  strLen 
) const

Definition at line 589 of file Trie.h.

References edm::Trie< T >::_initialNode, newFWLiteAna::found, edm::Trie< T >::node(), and edm::TrieNode< T >::subNodeByLabel().

589  {
590  unsigned pos = 0;
591  bool found = true;
592  const TrieNode<T> *node = _initialNode;
593 
594  while (found && pos < strLen) {
595  found = false;
596  node = node->subNodeByLabel(str[pos]);
597  if (node) {
598  found = true;
599  ++pos;
600  }
601  }
602  return node;
603 }
TrieNode< T > * _initialNode
first node of trie
Definition: Trie.h:214
#define str(s)
const TrieNode< T > * node(std::string const &str) const
get node matching a string
Definition: Trie.h:584
template<typename T >
Trie& edm::Trie< T >::operator= ( const Trie< T > &  e)
privatedelete

avoid affectation operator

template<typename T >
void edm::Trie< T >::setEntry ( std::string const &  str,
const T value 
)

associates a value to a string, if string is already in Trie, value is overwriten

Definition at line 504 of file Trie.h.

References relativeConstraints::value.

504  {
505  setEntry(str.c_str(), str.size(), value);
506 }
void setEntry(std::string const &str, const T &value)
Definition: Trie.h:504
#define str(s)
template<typename T >
void edm::Trie< T >::setEntry ( const char *  str,
unsigned  strLen,
const T value 
)

Definition at line 508 of file Trie.h.

References edm::Trie< T >::_addEntry(), edm::Trie< T >::node(), and edm::TrieNode< T >::setValue().

508  {
509  TrieNode<T> *node = _addEntry(str, strLen);
510  node->setValue(value);
511 }
Definition: value.py:1
#define str(s)
const TrieNode< T > * node(std::string const &str) const
get node matching a string
Definition: Trie.h:584
TrieNode< T > * _addEntry(const char *str, unsigned strLen)
Definition: Trie.h:514

Member Data Documentation

template<typename T >
T edm::Trie< T >::_empty
private

value returned when no match is found in trie

Definition at line 210 of file Trie.h.

Referenced by edm::Trie< T >::_addEntry(), edm::Trie< T >::clear(), edm::Trie< T >::find(), edm::Trie< T >::insert(), and edm::Trie< T >::Trie().

template<typename T >
TrieFactory<T>* edm::Trie< T >::_factory
private
template<typename T >
TrieNode<T>* edm::Trie< T >::_initialNode
private