1 #ifndef DataFormats_Common_Trie_h 2 #define DataFormats_Common_Trie_h 105 unsigned char brotherLabel()
const;
116 unsigned char subNodeLabel()
const;
119 const TrieNode<T>* subNodeByLabel(
unsigned char chr)
const;
123 void addSubNode(
unsigned char chr,
TrieNode<T> *node);
126 void display(std::ostream &os,
unsigned offset,
unsigned char label)
const;
132 template <
typename Node>
133 Node _sequentialSearch(Node
first,
unsigned char label,
134 unsigned char val)
const;
136 void _setBrother(
TrieNode<T> *brother,
unsigned char brotherLabel);
138 void _addBrother(
unsigned char chr,
TrieNode<T> *brother);
143 const TrieNode<T>* _getBrother(
unsigned char chr)
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;
209 const TrieNode<T>* node(
const char *str,
unsigned strLen)
const;
213 void display(std::ostream &os);
218 TrieNode<T>* _addEntry(
const char *str,
unsigned strLen);
232 #include <boost/iterator/iterator_facade.hpp> 244 :
public boost::iterator_facade<TrieNodeIter<T>,
246 boost::forward_traversal_tag >
253 : m_node(0), m_label(0)
257 : m_node(p ? p->subNode() : 0),
258 m_label(p ? p->subNodeLabel() : 0)
261 unsigned char label()
const {
return m_label;}
263 friend class boost::iterator_core_access;
266 m_label = m_node->brotherLabel();
267 m_node = m_node->brother();
272 return this->m_node ==
other.m_node;
283 template<
typename V,
typename T>
287 for (node_iterator
p(&n);
p!=
e; ++
p) {
288 v((*p).value(),
label+(char)
p.label());
296 template<
typename V,
typename T>
301 if (p==e)
return true;
304 v((*p).value(),
label+(char)p.label());
318 template <
typename T>
325 template <
typename T>
328 typename std::list<TrieNode<T>*>::const_iterator it;
336 template <
typename T>
352 template <
typename T>
355 typename std::list<TrieNode<T>*>::const_iterator it;
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>
421 template <
typename T>
427 template <
typename T>
437 _brother->_addBrother(chr, brother);
440 template <
typename T>
446 template <
typename T>
452 template <
typename T>
458 template <
typename T>
464 template <
typename T>
471 template <
typename T>
477 template <
typename T>
490 template <
typename T>
491 template <
typename Node>
494 if (first && label <= val)
498 return first->_getBrother(val);
503 template <
typename T>
510 template <
typename T>
517 os <<
"label[" << label <<
"] ";
518 os <<
"value[" <<
_value <<
"]" << std::endl;
525 template <
typename T>
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>
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>
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>
702 template <
typename T>
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
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
Trie()=delete
avoid default constructor
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
bool setValue(Container &, const reco::JetBaseRef &, const JetExtendedData &)
associate jet with value. Returns false and associate nothing if jet is already associated ...
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
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)
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
TrieNodeIter(node_base *p)
TrieFactory< T > * _factory
factory
TrieFactory & operator=(const TrieFactory &e)=delete
avoid affectation operator
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
TrieFactory()=delete
avoid default constructor
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)