Elm  1.0
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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_ */
node_t * allocate(t::uint32 n)
Definition: Builder.h:33
Definition: Builder.h:29
int make(node_t *nodes, int &s, int start, int end)
Definition: Builder.h:38
Tree< K, T, C >::node_t node_t
Definition: Builder.h:31
t::uint32 leastUpperPowerOf2(t::uint32 v)
Definition: int.cpp:242
Definition: Tree.h:35
uint32_t uint32
Definition: int.h:35