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 179 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 555 of file Trie.h.

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

555  :
556  _empty(empty), _factory(0x0), _initialNode(0x0)
557 {
558  // initialize nodes by paquets of 10000
559  _factory = new TrieFactory<T>(10000);
560  _initialNode = _factory->newNode(_empty);
561 }
T _empty
value returned when no match is found in trie
Definition: Trie.h:222
TrieFactory< T > * _factory
factory
Definition: Trie.h:224
TrieNode< T > * _initialNode
first node of trie
Definition: Trie.h:226
template<typename T >
edm::Trie< T >::~Trie ( )

Definition at line 564 of file Trie.h.

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

565 {
566  delete _factory;
567 }
TrieFactory< T > * _factory
factory
Definition: Trie.h:224
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 582 of file Trie.h.

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

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

583 {
584  unsigned pos = 0;
585  bool found = true;
586  TrieNode<T> *node = _initialNode, *previous = 0x0;
587 
588  // Look for the part of the word which is in Trie
589  while (found && pos < strLen)
590  {
591  found = false;
592  previous = node;
593  node = node->subNodeByLabel(str[pos]);
594  if (node)
595  {
596  found = true;
597  ++pos;
598  }
599  }
600 
601  // Add part of the word which is not in Trie
602  if (!node || pos != strLen)
603  {
604  node = previous;
605  for (unsigned i = pos; i < strLen; ++i)
606  {
607  TrieNode<T> *newNode = _factory->newNode(_empty);
608  node->addSubNode(str[pos], newNode);
609  node = newNode;
610  ++pos;
611  }
612  }
613  assert(node != 0x0);
614  return node;
615 }
T _empty
value returned when no match is found in trie
Definition: Trie.h:222
TrieFactory< T > * _factory
factory
Definition: Trie.h:224
TrieNode< T > * _initialNode
first node of trie
Definition: Trie.h:226
const TrieNode< T > * node(std::string const &str) const
get node matching a string
Definition: Trie.h:664
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 703 of file Trie.h.

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

704 {
705  if (_initialNode)
706  _initialNode->display(os, 0, 0);
707 }
TrieNode< T > * _initialNode
first node of trie
Definition: Trie.h:226
template<typename T >
const T & edm::Trie< T >::find ( std::string const &  str) const

get an entry in the Trie

Definition at line 636 of file Trie.h.

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

636  {
637  return find(str.c_str(),str.size());
638 }
const T & find(std::string const &str) const
get an entry in the Trie
Definition: Trie.h:636
template<typename T >
const T & edm::Trie< T >::find ( const char *  str,
unsigned  strLen 
) const

Definition at line 641 of file Trie.h.

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

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

642 {
643  unsigned pos = 0;
644  bool found = true;
645  const TrieNode<T> *node = _initialNode;
646 
647  while (found && pos < strLen)
648  {
649  found = false;
650  node = node->subNodeByLabel(str[pos]);
651  if (node)
652  {
653  found = true;
654  ++pos;
655  }
656  }
657  if (node && pos == strLen) // The word is complet in the automaton
658  return node->value();
659  return _empty;
660 }
T _empty
value returned when no match is found in trie
Definition: Trie.h:222
TrieNode< T > * _initialNode
first node of trie
Definition: Trie.h:226
const TrieNode< T > * node(std::string const &str) const
get node matching a string
Definition: Trie.h:664
template<typename T >
const edm::TrieNode< T > * edm::Trie< T >::initialNode ( ) const

get initial TrieNode

Definition at line 690 of file Trie.h.

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

691 {
692  return _initialNode;
693 }
TrieNode< T > * _initialNode
first node of trie
Definition: Trie.h:226
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 619 of file Trie.h.

References relativeConstraints::value.

Referenced by BeautifulSoup.PageElement::append().

620 {
621  insert(str.c_str(),str.size(),value);
622 }
void insert(std::string const &str, const T &value)
Definition: Trie.h:619
template<typename T >
void edm::Trie< T >::insert ( const char *  str,
unsigned  strLen,
const T value 
)

Definition at line 625 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().

626 {
627  TrieNode<T> *node = _addEntry(str, strLen);
628 
629  // Set the value on the last node
630  if (node && node->value() != _empty)
632  node->setValue(value);
633 }
T _empty
value returned when no match is found in trie
Definition: Trie.h:222
Definition: value.py:1
void errorInsert(std::string const &key)
Definition: Trie.h:545
const TrieNode< T > * node(std::string const &str) const
get node matching a string
Definition: Trie.h:664
TrieNode< T > * _addEntry(const char *str, unsigned strLen)
Definition: Trie.h:582
template<typename T >
edm::TrieNode< T > const * edm::Trie< T >::node ( std::string const &  str) const

get node matching a string

Definition at line 664 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().

664  {
665  return node(str.c_str(),str.size());
666  }
const TrieNode< T > * node(std::string const &str) const
get node matching a string
Definition: Trie.h:664
template<typename T >
edm::TrieNode< T > const * edm::Trie< T >::node ( const char *  str,
unsigned  strLen 
) const

Definition at line 670 of file Trie.h.

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

670  {
671  unsigned pos = 0;
672  bool found = true;
673  const TrieNode<T> *node = _initialNode;
674 
675  while (found && pos < strLen)
676  {
677  found = false;
678  node = node->subNodeByLabel(str[pos]);
679  if (node)
680  {
681  found = true;
682  ++pos;
683  }
684  }
685  return node;
686 }
TrieNode< T > * _initialNode
first node of trie
Definition: Trie.h:226
const TrieNode< T > * node(std::string const &str) const
get node matching a string
Definition: Trie.h:664
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 570 of file Trie.h.

References relativeConstraints::value.

571 {
572  setEntry(str.c_str(),str.size(),value);
573 }
void setEntry(std::string const &str, const T &value)
Definition: Trie.h:570
template<typename T >
void edm::Trie< T >::setEntry ( const char *  str,
unsigned  strLen,
const T value 
)

Definition at line 575 of file Trie.h.

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

576 {
577  TrieNode<T> *node = _addEntry(str, strLen);
578  node->setValue(value);
579 }
Definition: value.py:1
const TrieNode< T > * node(std::string const &str) const
get node matching a string
Definition: Trie.h:664
TrieNode< T > * _addEntry(const char *str, unsigned strLen)
Definition: Trie.h:582

Member Data Documentation

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

value returned when no match is found in trie

Definition at line 222 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