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

◆ 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.

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

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 }
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

◆ ~Trie()

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

Definition at line 499 of file Trie.h.

499  {
500  delete _factory;
501 }
TrieFactory< T > * _factory
factory
Definition: Trie.h:212

◆ 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.

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

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 }
assert(be >=bs)
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

◆ 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 }
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

◆ 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 }
TrieNode< T > * _initialNode
first node of trie
Definition: Trie.h:214

◆ find() [1/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.

References spr::find(), and str.

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)

◆ find() [2/2]

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

Definition at line 565 of file Trie.h.

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

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

◆ 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 }
TrieNode< T > * _initialNode
first node of trie
Definition: Trie.h:214

◆ insert() [1/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.

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

Referenced by SequenceTypes.Schedule::_replaceIfHeldDirectly().

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)

◆ insert() [2/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.

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

Referenced by SequenceTypes.Schedule::_replaceIfHeldDirectly().

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)
TrieNode< T > * _addEntry(const char *str, unsigned strLen)
Definition: Trie.h:514
const TrieNode< T > * node(std::string const &str) const
get node matching a string
Definition: Trie.h:584

◆ node() [1/2]

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.

References str.

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

◆ node() [2/2]

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 newFWLiteAna::found, str, 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

◆ 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 ( 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 str, and 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)

◆ setEntry() [2/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.

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

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

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