1 #ifndef DataFormats_Common_Trie_h 2 #define DataFormats_Common_Trie_h 123 template <
typename Node>
158 template <
typename T>
160 template <
typename T>
167 template <
typename T>
194 const T &
find(
const char *
str,
unsigned strLen)
const;
201 void display(std::ostream &os);
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> {
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>
289 : _paquetSize(paquetSize), _lastNodes(nullptr), _nbUsedInLastNodes(0) {
293 template <
typename T>
295 typename std::list<TrieNode<T> *>::const_iterator
it;
297 for (
it = _allocatedNodes.begin();
it != _allocatedNodes.end(); ++
it)
303 template <
typename T>
305 if (_nbUsedInLastNodes == _paquetSize) {
306 _allocatedNodes.push_back(_lastNodes);
307 _nbUsedInLastNodes = 0;
311 ++_nbUsedInLastNodes;
317 template <
typename T>
319 typename std::list<TrieNode<T> *>::const_iterator
it;
320 for (
it = _allocatedNodes.begin();
it != _allocatedNodes.end(); ++
it)
322 _allocatedNodes.clear();
323 _nbUsedInLastNodes = 0;
326 template <
typename T>
330 _firstSubNode(nullptr),
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>
375 return _sequentialSearch(brother, _brotherLabel, chr);
378 template <
typename T>
380 return _sequentialSearch(_brother, _brotherLabel, chr);
383 template <
typename T>
385 if (!_brother || _brotherLabel > chr) {
393 template <
typename T>
395 return _brotherLabel;
398 template <
typename T>
400 return _firstSubNode;
403 template <
typename T>
405 return _firstSubNode;
408 template <
typename T>
410 return _firstSubNodeLabel;
413 template <
typename T>
416 return _sequentialSearch(
first, _firstSubNodeLabel, chr);
419 template <
typename T>
421 return _sequentialSearch(_firstSubNode, _firstSubNodeLabel, chr);
424 template <
typename T>
426 if (!_firstSubNode || _firstSubNodeLabel > chr) {
427 node->
_setBrother(_firstSubNode, _firstSubNodeLabel);
428 _firstSubNode = node;
429 _firstSubNodeLabel = chr;
434 template <
typename T>
435 template <
typename Node>
445 template <
typename T>
448 _brotherLabel = brotherLabel;
451 template <
typename T>
457 os <<
"label[" <<
label <<
"] ";
458 os <<
"value[" << _value <<
"]" << std::endl;
460 _firstSubNode->display(os,
offset + 2, _firstSubNodeLabel);
462 _brother->display(os,
offset, _brotherLabel);
465 template <
typename T>
469 _firstSubNode =
nullptr;
470 _firstSubNodeLabel = 0;
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>
531 if (!node ||
pos != strLen) {
533 for (
unsigned i =
pos;
i < strLen; ++
i) {
544 template <
typename T>
549 template <
typename T>
554 if (node && node->
value() != _empty)
559 template <
typename T>
564 template <
typename T>
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>
605 template <
typename T>
610 template <
typename T>
613 _initialNode = _factory->newNode(_empty);
616 template <
typename T>
619 _initialNode->display(os, 0, 0);
622 #endif // DataFormats_Common_Trie_h void clear()
clear content of TrieNode
unsigned char brotherLabel() const
get brother label
void display(std::ostream &os, unsigned offset, unsigned char label) const
display content of node in output stream
const TrieNode< T > * subNode() const
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)
TrieNode< T > * _lastNodes
const T & find(std::string const &str) const
get an entry in the Trie
void setValue(const T &val)
set value associed to node
TrieNodeIter< T > end() const
mark end of iteration (std conforming)
node_base & dereference() const
Trie()=delete
avoid default constructor
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
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)
TrieNode & operator=(const TrieNode &e)=delete
avoid affectation operator
bool equal(self const &other) const
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t V
unsigned char subNodeLabel() const
void setEntry(std::string const &str, const T &value)
unsigned char label() const
TrieNode< T > const node_base
const TrieNode< T > * brother() const
get brother (return 0x0 this node has no brother)
void _addBrother(unsigned char chr, TrieNode< T > *brother)
add a new brother
T _empty
value returned when no match is found in trie
key
prepare the HTCondor submission files and eventually submit them
const TrieNode< T > * _getBrother(unsigned char chr) const
bool insert(Storage &iStorage, ItemType *iItem, const IdTag &iIdTag)
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
const TrieNode< T > * initialNode() const
get initial TrieNode
Trie & operator=(const Trie &e)=delete
avoid affectation operator
Node _sequentialSearch(Node first, unsigned char label, unsigned char val) const
const TrieNode< T > * subNodeByLabel(unsigned char chr) const
void clear()
clear the content of trie
TrieNodeIter(node_base *p)
TrieFactory< T > * _factory
factory
TrieFactory & operator=(const TrieFactory &e)=delete
avoid affectation operator
TrieNode< T > * _initialNode
first node of trie
T _value
value associed to this node
const T & value() const
get value associed to node
TrieFactory()=delete
avoid default constructor
T first(std::pair< T, U > const &p)
unsigned char _brotherLabel
character to go to brother (node with same father as this one)
TrieNode< T > * _addEntry(const char *str, unsigned strLen)
TrieNodeIter< T > begin() const
initialize subnode iterator (std conforming)
const TrieNode< T > * node(std::string const &str) const
get node matching a string
TrieNode< T > * _brother
pointer to brother (node with same father as this one)