~ubuntu-branches/ubuntu/lucid/igraph/lucid

« back to all changes in this revision

Viewing changes to src/gengraph_box_list.h

  • Committer: Bazaar Package Importer
  • Author(s): Mathieu Malaterre
  • Date: 2009-11-16 18:12:42 UTC
  • Revision ID: james.westby@ubuntu.com-20091116181242-mzv9p5fz9uj57xd1
Tags: upstream-0.5.3
ImportĀ upstreamĀ versionĀ 0.5.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// This class allows to maintain a list of vertices, 
 
2
// sorted by degree (largest degrees first)
 
3
// Operations allowed :
 
4
// - get the vertex having max degree -> Cost = O(1)
 
5
// - remove any vertex from the graph -> Cost = Sum(degrees of neighbours)
 
6
//                                       [ could be O(degree) if optimized ]
 
7
 
 
8
#ifndef _BOX_LIST_H
 
9
#define _BOX_LIST_H
 
10
 
 
11
namespace gengraph {
 
12
 
 
13
class box_list {
 
14
 
 
15
private:
 
16
  int n;     // INITIAL number of vertices
 
17
  int dmax;  // CURRENT Maximum degree
 
18
  int *deg;  // CURRENT Degrees (points directly to the deg[] of the graph
 
19
 
 
20
  // Vertices are grouped by degree: one double-chained lists for each degree
 
21
  int *list;        // list[d-1] is the head of list of vertices of degree d
 
22
  int *next;        // next[v]/prev[v] are the vertices next/previous to v
 
23
  int *prev;        //   in the list where v belongs
 
24
  void pop(int);    // pop(v) just removes v from its list
 
25
  void insert(int); // insert(v) insert v at the head of its list
 
26
 
 
27
public:
 
28
 
 
29
  // Ctor. Takes O(n) time.
 
30
  box_list(int n0, int *deg0);
 
31
 
 
32
  // Dtor
 
33
  ~box_list();
 
34
 
 
35
  // Self-explaining inline routines
 
36
  inline bool is_empty() { return dmax<1; };
 
37
  inline int get_max()   { return list[dmax-1]; };
 
38
  inline int get_one()   { return list[0]; };
 
39
  inline int get_min()   {
 
40
    int i=0;
 
41
    while(list[i]<0) i++;
 
42
    return list[i];
 
43
  };
 
44
  
 
45
  // Remove v from box_list
 
46
  // Also, semi-remove vertex v from graph: all neighbours of v will swap
 
47
  // their last neighbour wit hv, and then decrease their degree, so
 
48
  // that any arc w->v virtually disappear
 
49
  // Actually, adjacency lists are just permuted, and deg[] is changed
 
50
  void pop_vertex(int v, int **neigh);
 
51
};
 
52
 
 
53
} // namespace gengraph
 
54
 
 
55
#endif //_BOX_LIST_H