Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:51:01

0001 /*
0002  *  See header file for a description of this class.
0003  *
0004  *  \author Paolo Ronchese INFN Padova
0005  *
0006  */
0007 
0008 template <class Key, class Content>
0009 DTBufferTree<Key, Content>::DTBufferTree() : bufferContent(DTBufferTreeTrait<Content>::getDefault()) {}
0010 
0011 template <class Key, class Content>
0012 DTBufferTree<Key, Content>::~DTBufferTree() {
0013   map_iter iter = bufferMap.begin();
0014   map_iter iend = bufferMap.end();
0015   while (iter != iend)
0016     delete (iter++)->second;
0017 }
0018 
0019 template <class Key, class Content>
0020 void DTBufferTree<Key, Content>::clear() {
0021   map_iter iter = bufferMap.begin();
0022   map_iter iend = bufferMap.end();
0023   while (iter != iend)
0024     delete (iter++)->second;
0025   bufferMap.clear();
0026   bufferContent = std::move(Content(DTBufferTreeTrait<Content>::getDefault()));
0027 }
0028 
0029 template <class Key, class Content>
0030 int DTBufferTree<Key, Content>::insert(ElementKey fKey, ElementKey lKey, Content cont) {
0031   if (fKey == lKey) {
0032     bufferContent = std::move(cont);
0033     return 1;
0034   }
0035   map_iter iter = bufferMap.find(*fKey);
0036   if (iter != bufferMap.end())
0037     return iter->second->insert(++fKey, lKey, std::move(cont));
0038   map_node* bMap = new map_node;
0039   bufferMap.insert(std::pair<Key, DTBufferTree<Key, Content>*>(*fKey, bMap));
0040   bMap->insert(++fKey, lKey, std::move(cont));
0041   return 0;
0042 }
0043 
0044 template <class Key, class Content>
0045 int DTBufferTree<Key, Content>::insert(const Key& k, Content cont) {
0046   map_iter iter = bufferMap.find(k);
0047   if (iter != bufferMap.end()) {
0048     iter->second->bufferContent = std::move(cont);
0049     return 1;
0050   }
0051   map_node* bMap = new map_node;
0052   bufferMap.insert(std::pair<Key, DTBufferTree<Key, Content>*>(k, bMap));
0053   bMap->bufferContent = std::move(cont);
0054   return 0;
0055 }
0056 
0057 template <class Key, class Content>
0058 int DTBufferTree<Key, Content>::find(ElementKey fKey,
0059                                      ElementKey lKey,
0060                                      typename DTBufferTreeTrait<Content>::outputTypeOfConstFind& cont) const {
0061   if (fKey == lKey) {
0062     cont = DTBufferTreeTrait<Content>::getOutputValue(bufferContent);
0063     return 0;
0064   }
0065   map_iter iter = bufferMap.find(*fKey++);
0066   if (iter != bufferMap.end())
0067     return iter->second->find(fKey, lKey, cont);
0068   cont = DTBufferTreeTrait<Content>::getDefault();
0069   return 1;
0070 }
0071 
0072 template <class Key, class Content>
0073 int DTBufferTree<Key, Content>::find(const Key& k,
0074                                      typename DTBufferTreeTrait<Content>::outputTypeOfConstFind& cont) const {
0075   map_iter iter = bufferMap.find(k);
0076   if (iter != bufferMap.end()) {
0077     cont = DTBufferTreeTrait<Content>::getOutputValue(iter->second->bufferContent);
0078     return 0;
0079   }
0080   cont = DTBufferTreeTrait<Content>::getDefault();
0081   return 1;
0082 }
0083 
0084 template <class Key, class Content>
0085 int DTBufferTree<Key, Content>::find(ElementKey fKey,
0086                                      ElementKey lKey,
0087                                      typename DTBufferTreeTrait<Content>::outputTypeOfNonConstFind& cont) {
0088   if (fKey == lKey) {
0089     cont = DTBufferTreeTrait<Content>::getOutputValue(bufferContent);
0090     return 0;
0091   }
0092   map_iter iter = bufferMap.find(*fKey++);
0093   if (iter != bufferMap.end())
0094     return iter->second->find(fKey, lKey, cont);
0095   cont = DTBufferTreeTrait<Content>::getDefault();
0096   return 1;
0097 }
0098 
0099 template <class Key, class Content>
0100 int DTBufferTree<Key, Content>::find(const Key& k,
0101                                      typename DTBufferTreeTrait<Content>::outputTypeOfNonConstFind& cont) {
0102   map_iter iter = bufferMap.find(k);
0103   if (iter != bufferMap.end()) {
0104     cont = DTBufferTreeTrait<Content>::getOutputValue(iter->second->bufferContent);
0105     return 0;
0106   }
0107   cont = DTBufferTreeTrait<Content>::getDefault();
0108   return 1;
0109 }