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 (const char *str, unsigned strLen) const
 
const Tfind (std::string const &str) const
 get an entry in the Trie More...
 
const TrieNode< T > * initialNode () const
 get initial TrieNode More...
 
void insert (const char *str, unsigned strLen, const T &value)
 
void insert (std::string const &str, const T &value)
 
const TrieNode< T > * node (const char *str, unsigned strLen) const
 
const TrieNode< T > * node (std::string const &str) const
 get node matching a string More...
 
void setEntry (const char *str, unsigned strLen, const T &value)
 
void setEntry (std::string const &str, 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

◆ Trie() [1/3]

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.

492  : _empty(empty), _factory(nullptr), _initialNode(nullptr) {
493  // initialize nodes by paquets of 10000
494  _factory = new TrieFactory<T>(10000);
495  _initialNode = _factory->newNode(_empty);
496 }

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

◆ ~Trie()

template<typename T >
edm::Trie< T >::~Trie ( )

Definition at line 499 of file Trie.h.

499  {
500  delete _factory;
501 }

◆ Trie() [2/3]

template<typename T >
edm::Trie< T >::Trie ( )
privatedelete

avoid default constructor

◆ Trie() [3/3]

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

avoid copy constructor

Member Function Documentation

◆ _addEntry()

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

Definition at line 514 of file Trie.h.

514  {
515  unsigned pos = 0;
516  bool found = true;
517  TrieNode<T> *node = _initialNode, *previous = nullptr;
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 != nullptr);
541  return node;
542 }

References edm::TrieNode< T >::addSubNode(), cms::cuda::assert(), newFWLiteAna::found, mps_fire::i, str, and edm::TrieNode< T >::subNodeByLabel().

◆ clear()

template<typename T >
void edm::Trie< T >::clear ( void  )

clear the content of trie

Definition at line 611 of file Trie.h.

611  {
612  _factory->clear();
613  _initialNode = _factory->newNode(_empty);
614 }

Referenced by BeautifulSoup.Tag::setString().

◆ display()

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.

617  {
618  if (_initialNode)
619  _initialNode->display(os, 0, 0);
620 }

◆ find() [1/2]

template<typename T >
const T & edm::Trie< T >::find ( const char *  str,
unsigned  strLen 
) const

Definition at line 565 of file Trie.h.

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 }

References newFWLiteAna::found, str, edm::TrieNode< T >::subNodeByLabel(), and edm::TrieNode< T >::value().

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

◆ find() [2/2]

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.

560  {
561  return find(str.c_str(), str.size());
562 }

References spr::find(), and str.

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

◆ initialNode()

template<typename T >
const edm::TrieNode< T > * edm::Trie< T >::initialNode ( ) const

get initial TrieNode

Definition at line 606 of file Trie.h.

606  {
607  return _initialNode;
608 }

◆ insert() [1/2]

template<typename T >
void edm::Trie< T >::insert ( const char *  str,
unsigned  strLen,
const T value 
)

Definition at line 550 of file Trie.h.

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 }

References edm::detailsTrie::errorInsert(), edm::TrieNode< T >::setValue(), str, AlCaHLTBitMon_QueryRunRegistry::string, and edm::TrieNode< T >::value().

Referenced by BeautifulSoup.PageElement::append().

◆ insert() [2/2]

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.

545  {
546  insert(str.c_str(), str.size(), value);
547 }

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

Referenced by BeautifulSoup.PageElement::append().

◆ node() [1/2]

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

Definition at line 589 of file Trie.h.

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 }

References newFWLiteAna::found, str, and edm::TrieNode< T >::subNodeByLabel().

◆ node() [2/2]

template<typename T >
const edm::TrieNode< T > * edm::Trie< T >::node ( std::string const &  str) const

get node matching a string

Definition at line 584 of file Trie.h.

584  {
585  return node(str.c_str(), str.size());
586 }

References str.

◆ operator=()

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

avoid affectation operator

◆ setEntry() [1/2]

template<typename T >
void edm::Trie< T >::setEntry ( const char *  str,
unsigned  strLen,
const T value 
)

Definition at line 508 of file Trie.h.

508  {
509  TrieNode<T> *node = _addEntry(str, strLen);
510  node->setValue(value);
511 }

References edm::TrieNode< T >::setValue(), and str.

◆ setEntry() [2/2]

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.

504  {
505  setEntry(str.c_str(), str.size(), value);
506 }

References str, and relativeConstraints::value.

Member Data Documentation

◆ _empty

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

◆ _factory

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

factory

Definition at line 212 of file Trie.h.

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

◆ _initialNode

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

first node of trie

Definition at line 214 of file Trie.h.

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

mps_fire.i
i
Definition: mps_fire.py:355
edm::Trie::_addEntry
TrieNode< T > * _addEntry(const char *str, unsigned strLen)
Definition: Trie.h:514
edm::Trie::find
const T & find(std::string const &str) const
get an entry in the Trie
Definition: Trie.h:560
pos
Definition: PixelAliasList.h:18
cms::cuda::assert
assert(be >=bs)
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
edm::Trie::setEntry
void setEntry(std::string const &str, const T &value)
Definition: Trie.h:504
str
#define str(s)
Definition: TestProcessor.cc:48
edm::Trie::insert
void insert(std::string const &str, const T &value)
Definition: Trie.h:545
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::Trie::_empty
T _empty
value returned when no match is found in trie
Definition: Trie.h:210
edm::detailsTrie::errorInsert
void errorInsert(std::string const &key)
Definition: Trie.h:482
value
Definition: value.py:1
edm::Trie::_factory
TrieFactory< T > * _factory
factory
Definition: Trie.h:212
relativeConstraints.value
value
Definition: relativeConstraints.py:53
relativeConstraints.empty
bool empty
Definition: relativeConstraints.py:46
edm::Trie::node
const TrieNode< T > * node(std::string const &str) const
get node matching a string
Definition: Trie.h:584
edm::Trie::_initialNode
TrieNode< T > * _initialNode
first node of trie
Definition: Trie.h:214