1 #ifndef DataFormats_Common_Trie_h 2 #define DataFormats_Common_Trie_h 97 unsigned char brotherLabel()
const;
107 unsigned char subNodeLabel()
const;
110 const TrieNode<T> *subNodeByLabel(
unsigned char chr)
const;
114 void addSubNode(
unsigned char chr,
TrieNode<T> *node);
117 void display(std::ostream &os,
unsigned offset,
unsigned char label)
const;
123 template <
typename Node>
126 void _setBrother(
TrieNode<T> *brother,
unsigned char brotherLabel);
128 void _addBrother(
unsigned char chr,
TrieNode<T> *brother);
133 const TrieNode<T> *_getBrother(
unsigned char chr)
const;
158 template <
typename T>
160 template <
typename T>
167 template <
typename T>
187 void insert(
const char *str,
unsigned strLen,
const T &value);
191 void setEntry(
const char *str,
unsigned strLen,
const T &value);
194 const T &
find(
const char *str,
unsigned strLen)
const;
197 const TrieNode<T> *node(
const char *str,
unsigned strLen)
const;
201 void display(std::ostream &os);
206 TrieNode<T> *_addEntry(
const char *str,
unsigned strLen);
218 #include <boost/iterator/iterator_facade.hpp> 227 template <
typename T>
228 class TrieNodeIter :
public boost::iterator_facade<TrieNodeIter<T>, TrieNode<T> const, boost::forward_traversal_tag> {
234 explicit TrieNodeIter(node_base *
p) : m_node(p ? p->subNode() : 0), m_label(p ? p->subNodeLabel() : 0) {}
236 unsigned char label()
const {
return m_label; }
239 friend class boost::iterator_core_access;
242 m_label = m_node->brotherLabel();
243 m_node = m_node->brother();
255 template <
typename V,
typename T>
259 for (node_iterator
p(&n);
p !=
e; ++
p) {
260 v((*p).value(),
label + (char)
p.label());
266 template <
typename V,
typename T>
273 for (; p !=
e; ++
p) {
275 v((*p).value(),
label + (char)p.label());
287 template <
typename T>
293 template <
typename T>
295 typename std::list<TrieNode<T> *>::const_iterator it;
303 template <
typename T>
317 template <
typename T>
319 typename std::list<TrieNode<T> *>::const_iterator it;
326 template <
typename T>
331 _firstSubNodeLabel(0),
337 template <
typename T>
343 template <
typename T>
347 template <
typename T>
352 template <
typename T>
357 template <
typename T>
362 template <
typename T>
367 template <
typename T>
372 template <
typename T>
378 template <
typename T>
383 template <
typename T>
390 _brother->_addBrother(chr, brother);
393 template <
typename T>
398 template <
typename T>
403 template <
typename T>
408 template <
typename T>
413 template <
typename T>
419 template <
typename T>
424 template <
typename T>
434 template <
typename T>
435 template <
typename Node>
437 if (first && label <= val) {
440 return first->_getBrother(val);
445 template <
typename T>
451 template <
typename T>
457 os <<
"label[" << label <<
"] ";
458 os <<
"value[" <<
_value <<
"]" << std::endl;
465 template <
typename T>
481 namespace detailsTrie {
484 "Trie::insert called with a key already in collection;\n" 491 template <
typename T>
498 template <
typename T>
503 template <
typename T>
507 template <
typename T>
513 template <
typename T>
520 while (found && pos < strLen) {
531 if (!node || pos != strLen) {
533 for (
unsigned i = pos;
i < strLen; ++
i) {
544 template <
typename T>
549 template <
typename T>
559 template <
typename T>
561 return find(str.c_str(), str.size());
564 template <
typename T>
570 while (found && pos < strLen) {
578 if (node && pos == strLen)
579 return node->
value();
583 template <
typename T>
585 return node(str.c_str(), str.size());
588 template <
typename T>
594 while (found && pos < strLen) {
605 template <
typename T>
610 template <
typename T>
616 template <
typename T>
622 #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
std::list< TrieNode< T > * > _allocatedNodes
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
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)