|
|
Go to the documentation of this file. 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>
517 TrieNode<T> *node = _initialNode, *previous =
nullptr;
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
cudaStream_t T uint32_t const T *__restrict__ const uint32_t *__restrict__ uint32_t int cudaStream_t V
TrieNodeIter< T > begin() const
initialize subnode iterator (std conforming)
void walkTrie(V &v, TrieNode< T > const &n, std::string const &label="")
visit each node of the trie
Node _sequentialSearch(Node first, unsigned char label, unsigned char val) const
void clear()
clear content of TrieNode
unsigned _nbUsedInLastNodes
unsigned char brotherLabel() const
get brother label
TrieNodeIter< T > const_iterator
TrieNode< T > * _addEntry(const char *str, unsigned strLen)
TrieNode< T > * _brother
pointer to brother (node with same father as this one)
unsigned char label() const
const T & find(std::string const &str) const
get an entry in the Trie
friend class boost::iterator_core_access
unsigned char _brotherLabel
character to go to brother (node with same father as this one)
node_base & dereference() const
void setValue(const T &val)
set value associed to node
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
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)
TrieFactory & operator=(const TrieFactory &e)=delete
avoid affectation operator
T first(std::pair< T, U > const &p)
unsigned char subNodeLabel() const
Trie()=delete
avoid default constructor
void setEntry(std::string const &str, const T &value)
std::list< TrieNode< T > * > _allocatedNodes
void display(std::ostream &os)
display content of trie in output stream
void insert(std::string const &str, const T &value)
const TrieNode< T > node_base
TrieNodeIter< T > end() const
mark end of iteration (std conforming)
TrieNodeIter(node_base *p)
bool equal(self const &other) const
T _empty
value returned when no match is found in trie
void display(std::ostream &os, unsigned offset, unsigned char label) const
display content of node in output stream
void errorInsert(std::string const &key)
void _addBrother(unsigned char chr, TrieNode< T > *brother)
add a new brother
unsigned char _firstSubNodeLabel
character to go to first subnode
const TrieNode< T > * brother() const
get brother (return 0x0 this node has no brother)
const TrieNode< T > * initialNode() const
get initial TrieNode
Trie & operator=(const Trie &e)=delete
avoid affectation operator
TrieNode< T > * _firstSubNode
pointer to first sub node
TrieNode< T > * _lastNodes
const TrieNode< T > * subNode() const
TrieFactory< T > * _factory
factory
const TrieNode< T > * _getBrother(unsigned char chr) const
void clear()
clear the content of trie
const T & value() const
get value associed to node
void addSubNode(unsigned char chr, TrieNode< T > *node)
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
bool insert(Storage &iStorage, ItemType *iItem, const IdTag &iIdTag)
const TrieNode< T > * node(std::string const &str) const
get node matching a string
const TrieNode< T > * subNodeByLabel(unsigned char chr) const
TrieNode< T > * _initialNode
first node of trie
TrieFactory()=delete
avoid default constructor
TrieNode & operator=(const TrieNode &e)=delete
avoid affectation operator
T _value
value associed to this node
bool iterateTrieLeaves(V &v, TrieNode< T > const &n, std::string const &label="")
visits only leaf nodes
TrieNode< T > * newNode(const T &value)