CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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)
 avoid affectation operator More...
 
 Trie ()
 avoid default constructor More...
 
 Trie (const Trie &e)
 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 557 of file Trie.h.

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

557  :
558  _empty(empty), _factory(0x0), _initialNode(0x0)
559 {
560  // initialize nodes by paquets of 10000
561  _factory = new TrieFactory<T>(10000);
562  _initialNode = _factory->newNode(_empty);
563 }
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 566 of file Trie.h.

567 {
568  delete _factory;
569 }
TrieFactory< T > * _factory
factory
Definition: Trie.h:224
template<typename T >
edm::Trie< T >::Trie ( )
private

avoid default constructor

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

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

References edm::TrieNode< T >::addSubNode(), newFWLiteAna::found, i, python.Node::node, pos, and edm::TrieNode< T >::subNodeByLabel().

585 {
586  unsigned pos = 0;
587  bool found = true;
588  TrieNode<T> *node = _initialNode, *previous = 0x0;
589 
590  // Look for the part of the word which is in Trie
591  while (found && pos < strLen)
592  {
593  found = false;
594  previous = node;
595  node = node->subNodeByLabel(str[pos]);
596  if (node)
597  {
598  found = true;
599  ++pos;
600  }
601  }
602 
603  // Add part of the word which is not in Trie
604  if (!node || pos != strLen)
605  {
606  node = previous;
607  for (unsigned i = pos; i < strLen; ++i)
608  {
609  TrieNode<T> *newNode = _factory->newNode(_empty);
610  node->addSubNode(str[pos], newNode);
611  node = newNode;
612  ++pos;
613  }
614  }
615  assert(node != 0x0);
616  return node;
617 }
int i
Definition: DBlmapReader.cc:9
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:666
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 705 of file Trie.h.

706 {
707  if (_initialNode)
708  _initialNode->display(os, 0, 0);
709 }
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 638 of file Trie.h.

References spr::find().

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

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

Definition at line 643 of file Trie.h.

References newFWLiteAna::found, python.Node::node, pos, edm::TrieNode< T >::subNodeByLabel(), and edm::TrieNode< T >::value().

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

644 {
645  unsigned pos = 0;
646  bool found = true;
647  const TrieNode<T> *node = _initialNode;
648 
649  while (found && pos < strLen)
650  {
651  found = false;
652  node = node->subNodeByLabel(str[pos]);
653  if (node)
654  {
655  found = true;
656  ++pos;
657  }
658  }
659  if (node && pos == strLen) // The word is complet in the automaton
660  return node->value();
661  return _empty;
662 }
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:666
template<typename T >
const edm::TrieNode< T > * edm::Trie< T >::initialNode ( ) const

get initial TrieNode

Definition at line 692 of file Trie.h.

693 {
694  return _initialNode;
695 }
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 621 of file Trie.h.

References edm::eventsetup::heterocontainer::insert(), and relativeConstraints::value.

Referenced by BeautifulSoup.PageElement::_invert(), and GeometricSearchTrackerBuilder::build().

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

Definition at line 627 of file Trie.h.

References edm::detailsTrie::errorInsert(), python.Node::node, edm::TrieNode< T >::setValue(), and edm::TrieNode< T >::value().

Referenced by BeautifulSoup.PageElement::_invert().

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

get node matching a string

Definition at line 666 of file Trie.h.

References python.Node::node.

Referenced by GeometricSearchTrackerBuilder::build().

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

Definition at line 672 of file Trie.h.

References newFWLiteAna::found, python.Node::node, pos, and edm::TrieNode< T >::subNodeByLabel().

672  {
673  unsigned pos = 0;
674  bool found = true;
675  const TrieNode<T> *node = _initialNode;
676 
677  while (found && pos < strLen)
678  {
679  found = false;
680  node = node->subNodeByLabel(str[pos]);
681  if (node)
682  {
683  found = true;
684  ++pos;
685  }
686  }
687  return node;
688 }
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:666
template<typename T >
Trie& edm::Trie< T >::operator= ( const Trie< T > &  e)
private

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

References relativeConstraints::value.

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

Definition at line 577 of file Trie.h.

References python.Node::node, and edm::TrieNode< T >::setValue().

578 {
579  TrieNode<T> *node = _addEntry(str, strLen);
580  node->setValue(value);
581 }
const TrieNode< T > * node(std::string const &str) const
get node matching a string
Definition: Trie.h:666
TrieNode< T > * _addEntry(const char *str, unsigned strLen)
Definition: Trie.h:584

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 >::Trie().

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

factory

Definition at line 224 of file Trie.h.

Referenced by edm::Trie< T >::Trie().

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

first node of trie

Definition at line 226 of file Trie.h.

Referenced by edm::Trie< T >::Trie().