4
Copyright (C) 2006 Elliot Paquette <Elliot.Paquette05@kzoo.edu>
5
Kalamazoo College, 1200 Academy st, Kalamazoo, MI
7
This program 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.
12
This program 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.
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
31
double igraph_i_log2(double f) {
32
return log(f) / log(2.0);
35
int igraph_psumtree_init(igraph_psumtree_t *t, long int size) {
37
t->offset=pow(2, ceil(igraph_i_log2(size)))-1;
38
IGRAPH_CHECK(igraph_vector_init((igraph_vector_t *)t, t->offset+t->size));
42
void igraph_psumtree_destroy(igraph_psumtree_t *t) {
43
igraph_vector_destroy((igraph_vector_t *)t);
46
igraph_real_t igraph_psumtree_get(const igraph_psumtree_t *t, long int idx) {
47
const igraph_vector_t *tree=&t->v;
48
return VECTOR(*tree)[t->offset+idx];
51
int igraph_psumtree_search(const igraph_psumtree_t *t, long int *idx,
52
igraph_real_t search) {
53
const igraph_vector_t *tree=&t->v;
55
long int size = igraph_vector_size(tree);
57
while( 2*i+1 <= size) {
58
if( search <= VECTOR(*tree)[i*2-1] ) {
61
search -= VECTOR(*tree)[i*2-1];
71
return IGRAPH_SUCCESS;
74
int igraph_psumtree_update(igraph_psumtree_t *t, long int idx,
75
igraph_real_t new_value) {
76
const igraph_vector_t *tree=&t->v;
77
igraph_real_t difference;
79
idx = idx + t->offset+1;
80
difference = new_value - VECTOR(*tree)[idx-1];
83
VECTOR(*tree)[idx-1] += difference;
86
return IGRAPH_SUCCESS;
89
long int igraph_psumtree_size(const igraph_psumtree_t *t) {
93
igraph_real_t igraph_psumtree_sum(const igraph_psumtree_t *t) {
94
return VECTOR(t->v)[0];