Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
Builder.h
1 /*
2  * stree::Builder class interface
3  *
4  * This file is part of OTAWA
5  * Copyright (c) 2013, IRIT UPS.
6  *
7  * OTAWA is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * OTAWA is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with OTAWA; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 #ifndef ELM_STREE_BUILDER_H_
22 #define ELM_STREE_BUILDER_H_
23 
24 #include <elm/stree/Tree.h>
25 
26 namespace elm { namespace stree {
27 
28 template <class K, class T, class C = Comparator<K> >
29 class Builder {
30 protected:
31  typedef typename Tree<K, T, C>::node_t node_t;
32 
34  int s = n + leastUpperPowerOf2(n) - 1;
35  return new node_t[s];
36  }
37 
38  int make(node_t *nodes, int& s, int start, int end) {
39  if(start == end)
40  return start;
41  else {
42  int m = (start + end) / 2,
43  l = make(nodes, s, start, m),
44  u = make(nodes, s, m + 1, end);
45  int p = s;
46  nodes[s++] = node_t(nodes, l, u);
47  return p;
48  }
49  }
50 };
51 
52 } } // elm::stree
53 
54 #endif /* ELM_STREE_BUILDER_H_ */
elm::io::p
Printable< T, M > p(const T &data, const M &man)
Definition: Output.h:302
elm::stree::Builder
Definition: Builder.h:29
elm::leastUpperPowerOf2
t::uint32 leastUpperPowerOf2(t::uint32 v)
Definition: int.cpp:226
elm::stree::Builder::allocate
node_t * allocate(t::uint32 n)
Definition: Builder.h:33
elm
Definition: adapter.h:26
elm::stree::Builder::node_t
Tree< K, T, C >::node_t node_t
Definition: Builder.h:31
elm::t::uint32
unsigned int uint32
Definition: arch.h:31
elm::stree::Tree::node_t
Definition: Tree.h:35
elm::stree::Builder::make
int make(node_t *nodes, int &s, int start, int end)
Definition: Builder.h:38