-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGraphSequenceTest.cpp
More file actions
112 lines (81 loc) · 3.08 KB
/
GraphSequenceTest.cpp
File metadata and controls
112 lines (81 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/* WaveletTreeNoptrs.h
* Copyright (C) 2013, Nicolás Lehmann.
*
* Graph implementation using a sequence representation
* for the concatenation of the adjacency lists
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include <ctime>
#include "GraphSequenceTest.h"
namespace cds_static
{
GraphSequenceTest::GraphSequenceTest(){
}
GraphSequenceTest::~GraphSequenceTest(){
}
double GraphSequenceTest::testDirectNeighbors(uint n, ofstream &fp) const{
clock_t begin = clock();
size_t pos = bitseq->select1(n+1);
size_t next = bitseq->select1(n+2);
size_t len = (next == -1?bitseq->getLength() : next) - pos;
int repetitions = 1024/len > 1 ? 1024/len : 1;
for(int r = 0; r < repetitions; ++r){
for(int i = 0; i < len; ++i)
adjacencyList->access(pos + i);
}
clock_t end = clock();
double elapsed_secs = ((double)(end - begin))/ CLOCKS_PER_SEC/repetitions;
if(elapsed_secs < 0.00001)
fprintf(stderr,"To fast repetitions: %d, len: %d, secs: %.10f\n", repetitions, len,elapsed_secs);
return elapsed_secs/len;
}
double GraphSequenceTest::testReverseNeighbors(uint n, ofstream &fp) const{
clock_t begin = clock();
size_t len = adjacencyList->rank(n, adjacencyList->getLength());
int repetitions = 1024/len > 1 ? 1024/len : 1;
for(int r = 0; r < repetitions; ++r){
for(int i = 0; i < len; ++i)
bitseq->rank1(adjacencyList->select(n, i+1)) - 1;
}
clock_t end = clock();
double elapsed_secs = ((double)(end - begin))/ CLOCKS_PER_SEC/repetitions;
if(elapsed_secs < 0.00001)
fprintf(stderr,"To fast repetitions: %d, len: %d, secs: %.10f\n", repetitions, len,elapsed_secs);
return elapsed_secs/len;
}
GraphSequenceTest * GraphSequenceTest::load(ifstream & fp) {
GraphSequenceTest *ret = new GraphSequenceTest();
ret->nodes = loadValue<size_t>(fp);
ret->edges = loadValue<long long>(fp);
ret->falseEdges = loadValue<long long>(fp);
ret->adjacencyList = RePairWaveletTree::load(fp);
ret->bitseq = BitSequence::load(fp);
return ret;
}
void GraphSequenceTest::rpwvt_conf(uint repair_sample, uint max_len, uint occ_sample, double alpha){
RePairWaveletTree *wvt = (RePairWaveletTree *) this->adjacencyList;
wvt->re_sample_repair(repair_sample);
wvt->re_set_max_rule_len(max_len);
if(occ_sample == 0)
wvt->turn_occ_array();
else{
wvt->turn_occ_bitmap();
wvt->re_set_occ_sample(occ_sample);
}
wvt->re_set_alpha_factor(alpha);
}
};