1 #ifndef DataFormats_Common_Trie_h
2 #define DataFormats_Common_Trie_h
132 template <
typename Node>
134 unsigned char val)
const;
169 template <
typename T>
171 template <
typename T>
178 template <
typename T>
199 void insert(
const char *str,
unsigned strLen,
const T &value);
203 void setEntry(
const char *str,
unsigned strLen,
const T &value);
206 const T&
find(
const char *str,
unsigned strLen)
const;
213 void display(std::ostream &os);
232 #include <boost/iterator/iterator_facade.hpp>
244 :
public boost::iterator_facade<TrieNodeIter<T>,
246 boost::forward_traversal_tag >
257 :
m_node(p ? p->subNode() : 0),
258 m_label(p ? p->subNodeLabel() : 0)
272 return this->
m_node == other.m_node;
283 template<
typename V,
typename T>
287 for (node_iterator
p(&n);
p!=
e; ++
p) {
296 template<
typename V,
typename T>
301 if (p==e)
return true;
318 template <
typename T>
320 _paquetSize(paquetSize), _lastNodes(0x0), _nbUsedInLastNodes(0)
325 template <
typename T>
328 typename std::list<TrieNode<T>*>::const_iterator it;
330 for (it = _allocatedNodes.begin(); it != _allocatedNodes.end(); ++it)
336 template <
typename T>
339 if (_nbUsedInLastNodes == _paquetSize)
341 _allocatedNodes.push_back(_lastNodes);
342 _nbUsedInLastNodes = 0;
345 TrieNode<T> *res = &_lastNodes[_nbUsedInLastNodes];
346 ++_nbUsedInLastNodes;
352 template <
typename T>
355 typename std::list<TrieNode<T>*>::const_iterator it;
356 for (it = _allocatedNodes.begin(); it != _allocatedNodes.end(); ++it)
358 _allocatedNodes.clear();
359 _nbUsedInLastNodes = 0;
363 template <
typename T>
365 _brother(0), _brotherLabel(0), _firstSubNode(0), _firstSubNodeLabel(0),_value()
371 template <
typename T>
379 template <
typename T>
384 template <
typename T>
390 template <
typename T>
396 template <
typename T>
402 template <
typename T>
408 template <
typename T>
414 template <
typename T>
418 return _sequentialSearch(brother, _brotherLabel, chr);
421 template <
typename T>
424 return _sequentialSearch(_brother, _brotherLabel, chr);
427 template <
typename T>
430 if (!_brother || _brotherLabel > chr)
440 template <
typename T>
443 return _brotherLabel;
446 template <
typename T>
449 return _firstSubNode;
452 template <
typename T>
455 return _firstSubNode;
458 template <
typename T>
461 return _firstSubNodeLabel;
464 template <
typename T>
468 return _sequentialSearch(first, _firstSubNodeLabel, chr);
471 template <
typename T>
474 return _sequentialSearch(_firstSubNode, _firstSubNodeLabel, chr);
477 template <
typename T>
480 if (!_firstSubNode || _firstSubNodeLabel > chr)
482 node->
_setBrother(_firstSubNode, _firstSubNodeLabel);
483 _firstSubNode = node;
484 _firstSubNodeLabel = chr;
490 template <
typename T>
491 template <
typename Node>
494 if (first && label <= val)
498 return first->_getBrother(val);
503 template <
typename T>
507 _brotherLabel = brotherLabel;
510 template <
typename T>
517 os <<
"label[" << label <<
"] ";
518 os <<
"value[" << _value <<
"]" << std::endl;
520 _firstSubNode->display(os, offset + 2, _firstSubNodeLabel);
522 _brother->display(os, offset, _brotherLabel);
525 template <
typename T>
531 _firstSubNodeLabel = 0;
544 namespace detailsTrie {
547 "Trie::insert called with a key already in collection;\n"
554 template <
typename T>
556 _empty(empty), _factory(0x0), _initialNode(0x0)
563 template <
typename T>
569 template <
typename T>
572 setEntry(str.c_str(),str.size(),
value);
574 template <
typename T>
581 template <
typename T>
589 while (found && pos < strLen)
602 if (!node || pos != strLen)
605 for (
unsigned i = pos;
i < strLen; ++
i)
618 template <
typename T>
624 template <
typename T>
630 if (node && node->
value() != _empty)
635 template <
typename T>
637 return find(str.c_str(),str.size());
640 template <
typename T>
647 while (found && pos < strLen)
657 if (node && pos == strLen)
658 return node->
value();
662 template <
typename T>
665 return node(str.c_str(),str.size());
668 template <
typename T>
675 while (found && pos < strLen)
689 template <
typename T>
695 template <
typename T>
699 _initialNode = _factory->newNode(_empty);
702 template <
typename T>
706 _initialNode->display(os, 0, 0);
709 #endif // DataFormats_Common_Trie_h
void clear()
clear content of TrieNode
void display(std::ostream &os, unsigned offset, unsigned char label) const
display content of node in output stream
TrieFactory & operator=(const TrieFactory &e)
avoid affectation operator
edm::TrieNodeIter< PDet > node_iterator
this class represent the node of a trie, it contains a link to a sub node and a link to a brother (no...
void _setBrother(TrieNode< T > *brother, unsigned char brotherLabel)
set brother (used by sort)
void addSubNode(unsigned char chr, TrieNode< T > *node)
const TrieNode< T > * _getBrother(unsigned char chr) const
TrieNode< T > * _lastNodes
void setValue(const T &val)
set value associed to node
const TrieNode< T > * brother() const
get brother (return 0x0 this node has no brother)
const TrieNode< T > * subNode() const
unsigned char _firstSubNodeLabel
character to go to first subnode
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
TrieNode< T > * _firstSubNode
pointer to first sub node
TrieNodeIter< T > end() const
mark end of iteration (std conforming)
TrieNode< T > * newNode(const T &value)
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
bool iterateTrieLeaves(V &v, TrieNode< T > const &n, std::string const &label="")
visits only leaf nodes
void display(std::ostream &os)
display content of trie in output stream
void insert(std::string const &str, const T &value)
TrieNodeIter< T > begin() const
initialize subnode iterator (std conforming)
void setEntry(std::string const &str, const T &value)
TrieNode< T > const node_base
const T & value() const
get value associed to node
Node _sequentialSearch(Node first, unsigned char label, unsigned char val) const
const T & find(std::string const &str) const
get an entry in the Trie
TrieFactory()
avoid default constructor
void _addBrother(unsigned char chr, TrieNode< T > *brother)
add a new brother
const TrieNode< T > * initialNode() const
get initial TrieNode
T _empty
value returned when no match is found in trie
std::list< TrieNode< T > * > _allocatedNodes
bool insert(Storage &iStorage, ItemType *iItem, const IdTag &iIdTag)
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
friend class boost::iterator_core_access
TrieNodeIter< T > const_iterator
void errorInsert(std::string const &key)
void walkTrie(V &v, TrieNode< T > const &n, std::string const &label="")
visit each node of the trie
unsigned _nbUsedInLastNodes
void clear()
clear the content of trie
bool equal(self const &other) const
TrieNode & operator=(const TrieNode &e)
avoid affectation operator
TrieNodeIter(node_base *p)
TrieFactory< T > * _factory
factory
Trie & operator=(const Trie &e)
avoid affectation operator
Trie()
avoid default constructor
TrieNode< T > * _initialNode
first node of trie
unsigned char label() const
const TrieNode< T > * subNodeByLabel(unsigned char chr) const
T _value
value associed to this node
unsigned char brotherLabel() const
get brother label
T first(std::pair< T, U > const &p)
unsigned char subNodeLabel() const
unsigned char _brotherLabel
character to go to brother (node with same father as this one)
const TrieNode< T > * node(std::string const &str) const
get node matching a string
TrieNode< T > * _addEntry(const char *str, unsigned strLen)
node_base & dereference() const
TrieNode< T > * _brother
pointer to brother (node with same father as this one)