-
Notifications
You must be signed in to change notification settings - Fork 2
/
GraphSequence.h
79 lines (65 loc) · 2.36 KB
/
GraphSequence.h
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
/* 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
*
*/
#ifndef GRAPH_SEQUENCE_H
#define GRAPH_SEQUENCE_H
#include <libcdsBasics.h>
#include <Mapper.h>
#include <SequenceBuilder.h>
#include <BitSequenceBuilder.h>
#include "RePairWaveletTree.h"
namespace cds_static
{
class GraphSequence
{
public:
/**
* Builds a graph from a adjacency list represented by
* <it>nodes</it> sequences. Each sequence has to start with the number
* of adjacent nodes and then the corresponding neighbors.
* If a node has zero neighbors his respective sequence must be
* one containing only a zero
* @param adjacencyList Adjacency list of the graph.
* @param nodes Number of nodes
* @param sb Builder for sequence that represent the adjacency sequence
* @param debug True if you want to print debug messages
* */
GraphSequence(uint **adjacencyList, size_t nodes, SequenceBuilder *sb, bool debug = false);
virtual ~GraphSequence();
vector<uint> *getNeighbors(uint n) const;
vector<uint> *getReverseNeighbors(uint n) const;
size_t neighborsCount(uint n) const;
size_t reverseNeighborsCount(uint n) const;
size_t nodesCount() const{return nodes;}
size_t edgesCount() const{return edges;}
virtual void save(ofstream & fp) const;
static GraphSequence * load(ifstream & fp);
virtual size_t getSize() const;
protected:
Sequence *adjacencyList;
BitSequence *bitseq;
size_t nodes;
long long edges;
long long falseEdges;
GraphSequence();
};
};
#endif