Skip to content

Commit

Permalink
Merge branch 'docs' into backlog
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Heuser committed Feb 16, 2019
2 parents 0236ecc + 2e6b972 commit 7920f0a
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 84 deletions.
28 changes: 17 additions & 11 deletions docs/bcc-iterator.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,22 @@ This space-efficient variant

## Example
```cpp
UndirectedGraph g=GraphCreator::windmill(3,4);
#include <cstdio>
#include "sealib/iterator/bcciterator.h"
#include "sealib/graph/graphcreator.h"

BCCIterator b(g);
b.init();
b.start(1,2);
b.forEach([](std::pair<uint64_t,uint64_t> p) {
if(p.second==INVALID) {
std::cout << "found node: " << p.first << "\n";
} else {
std::cout << "found edge: " << p.first << "," << p.second << "\n";
}
});
int main() {
UndirectedGraph g=GraphCreator::windmill(3,4);

BCCIterator b(g);
b.init();
b.start(1,2);
b.forEach([](std::pair<uint64_t,uint64_t> p) {
if(p.second==INVALID) {
std::cout << "found node: " << p.first << "\n";
} else {
std::cout << "found edge: " << p.first << "," << p.second << "\n";
}
});
}
```
45 changes: 24 additions & 21 deletions docs/choice-dictionary.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@ A choice dictionary is a bitset containing n elements that supports reading and
## Example

```cpp
ChoiceDictionary* cd = new ChoiceDictionary(12);
cd.insert(0); // Indexing beginns with 0
cd.insert(4);
cd.insert(7);
cd.insert(11);
#include "sealib/dictionary/choicedictionary.h"

cd.get(0); // Returns 1
cd.get(2); // Returns 0
int main() {
ChoiceDictionary cd(12);
cd.insert(0); // Indexing begins with 0
cd.insert(4);
cd.insert(7);
cd.insert(11);

cd.choice(); // May return 0, 4, 7 or 11.
cd.get(0); // Returns 1
cd.get(2); // Returns 0

delete cd;
cd.choice(); // May return 0, 4, 7 or 11.
}
```
<br>

Expand All @@ -47,19 +49,20 @@ It supports the so-called *more* operation that returns true if the choice dicti
## Example

```cpp
ChoiceDictionary* cd = new ChoiceDictionary(12);
ChoiceDictionaryIterator* it = new ChoiceDictionaryIterator(cd);
cd->insert(0); // Indexing beginns with 0
cd->insert(4);
cd->insert(7);
cd->insert(11);
#include "sealib/iterator/choicedictionaryiterator.h"

it->init();
int main() {
ChoiceDictionary cd(12);
ChoiceDictionaryIterator it(&cd);
cd.insert(0); // Indexing beginns with 0
cd.insert(4);
cd.insert(7);
cd.insert(11);

while (it->more()) { // Returns true if more bits are set to 1
it->next(); // May return the next arbitrary bit 0, 4, 7 or 11.
}
it.init();

delete it;
delete cd;
while (it.more()) { // Returns true if more bits are set to 1
it.next(); // May return the next arbitrary bit 0, 4, 7 or 11.
}
}
```
20 changes: 13 additions & 7 deletions docs/cut-vertex-iterator.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,19 @@ This space-efficient variant

## Example
```cpp
UndirectedGraph g=GraphCreator::windmill(3,4);
#include <cstdio>
#include "sealib/iterator/cutvertexiterator.h"
#include "sealib/graph/graphcreator.h"

CutVertexIterator c(g);
c.init();
while(c.more()) {
std::cout << "found: " << c.next() << "\n";
}
int main() {
UndirectedGraph g=GraphCreator::windmill(3,4);

CutVertexIterator c(g);
c.init();
while(c.more()) {
std::cout << "found: " << c.next() << "\n";
}

std::cout << "center should be cut vertex: " << c.isCutVertex(g->getOrder()-1) << "\n";
printf("center should be cut vertex: %d\n",c.isCutVertex(g.getOrder()-1));
}
```
25 changes: 15 additions & 10 deletions docs/n-bit-bfs.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,22 @@ This space-efficient variant

## Example
```cpp
DirectedGraph g=GraphCreator::createRandomFixed(500,2);
#include <cstdio>
#include "sealib/iterator/bfs.h"
#include "sealib/graph/graphcreator.h"

BFS bfs(g, p0, e0);
bfs.init(); // don't forget initialization of the iterator
bfs.forEach([&](std::pair<uint64_t, uint64_t>) {
uint64_t u=s.first, dist=s.second;
std::cout << "found vertex " << u << " with distance " << dist << "\n";
});
// example procedures:
void preproc(uint64_t u) { printf("preprocess %u\n", u); }
void preexp(uint64_t u, uint64_t v) { printf("preexplore %u,%u\n", u, v); }

int main() {
DirectedGraph g=GraphCreator::kOutdegree(500,2);

// example procedures:
void p0(uint64_t u) { printf("preprocess %u\n", u); }
void e0(uint64_t u, uint64_t v) { printf("preexplore %u,%u\n", u, v); }
BFS bfs(g, preproc, preexp);
bfs.init(); // don't forget initialization of the iterator
bfs.forEach([&](std::pair<uint64_t, uint64_t>) {
uint64_t u=s.first, dist=s.second;
std::cout << "found vertex " << u << " with distance " << dist << "\n";
});
}
```
22 changes: 13 additions & 9 deletions docs/n-bit-dfs.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,20 @@ This space-efficient variant

## Example
```cpp
DirectedGraph g=GraphCreator::sparseDirected(50);
#include <cstdio>
#include "sealib/iterator/dfs.h"
#include "sealib/graph/graphcreator.h"

DFS::nBitDFS(g); // quiet run

DFS::nBitDFS(g, p0, e0, e1, p1); // supply procedures to do something with the current node or edge
// example procedures:
void preproc(uint64_t u) { printf("preprocess %u\n", u); }
void postproc(uint64_t u) { printf("postprocess %u\n", u); }
void preexp(uint64_t u, uint64_t v) { printf("preexplore %u,%u\n", u, v); }
void postexp(uint64_t u, uint64_t v) { printf("postexplore %u,%u\n", u, v); }

int main() {
DirectedGraph g=GraphCreator::sparseDirected(50);
DFS::nBitDFS(g); // quiet run

// example procedures:
void p0(uint64_t u) { printf("preprocess %u\n", u); }
void p1(uint64_t u) { printf("postprocess %u\n", u); }
void e0(uint64_t u, uint64_t v) { printf("preexplore %u,%u\n", u, v); }
void e1(uint64_t u, uint64_t v) { printf("postexplore %u,%u\n", u, v); }
DFS::nBitDFS(g, preproc, preexp, postexp, postproc); // supply procedures to do something with the current node or edge
}
```
22 changes: 13 additions & 9 deletions docs/nloglogn-bit-dfs.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,20 @@ This space-efficient variant

## Example
```cpp
DirectedGraph g=GraphCreator::imbalanced(500);
#include <cstdio>
#include "sealib/iterator/dfs.h"
#include "sealib/graph/graphcreator.h"

DFS::nloglognBitDFS(g); // quiet run

DFS::nBitDFS(g, p0, e0, e1, p1); // supply procedures to do something with the current node or edge
// example procedures:
void preproc(uint64_t u) { printf("preprocess %u\n", u); }
void postproc(uint64_t u) { printf("postprocess %u\n", u); }
void preexp(uint64_t u, uint64_t v) { printf("preexplore %u,%u\n", u, v); }
void postexp(uint64_t u, uint64_t v) { printf("postexplore %u,%u\n", u, v); }

int main() {
DirectedGraph g=GraphCreator::imbalanced(500);
DFS::nloglognBitDFS(g); // quiet run

// example procedures:
void p0(uint64_t u) { printf("preprocess %u\n", u); }
void p1(uint64_t u) { printf("postprocess %u\n", u); }
void e0(uint64_t u, uint64_t v) { printf("preexplore %u,%u\n", u, v); }
void e1(uint64_t u, uint64_t v) { printf("postexplore %u,%u\n", u, v); }
DFS::nloglognBitDFS(g, preproc, preexp, postexp, postproc); // supply procedures to do something with the current node or edge
}
```
23 changes: 14 additions & 9 deletions docs/nplusm-bit-dfs.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,21 @@ This space-efficient variant *only works with undirected graphs*:

## Example
```cpp
UndirectedGraph g=GraphCreator::kRegular(100,5)
#include <cstdio>
#include "sealib/iterator/dfs.h"
#include "sealib/graph/graphcreator.h"

DFS::nplusmBitDFS(g); // quiet run

DFS::nplusmBitDFS(g, p0, e0, e1, p1); // supply procedures to do something with the current node or edge
// example procedures:
void preproc(uint64_t u) { printf("preprocess %u\n", u); }
void postproc(uint64_t u) { printf("postprocess %u\n", u); }
// ! Attention: for this DFS variant, the 'explore' calls return the edge INDEX k, not the node v
void preexp(uint64_t u, uint64_t k) { printf("preexplore %u,%u\n", u, k); }
void postexp(uint64_t u, uint64_t k) { printf("postexplore %u,%u\n", u, k); }

int main() {
UndirectedGraph g=GraphCreator::kRegular(100,5);
DFS::nBitDFS(g); // quiet run

// example procedures:
void p0(uint64_t u) { printf("preprocess %u\n", u); }
void p1(uint64_t u) { printf("postprocess %u\n", u); }
void e0(uint64_t u, uint64_t v) { printf("preexplore %u,%u\n", u, v); }
void e1(uint64_t u, uint64_t v) { printf("postexplore %u,%u\n", u, v); }
DFS::nBitDFS(g, preproc, preexp, postexp, postproc); // supply procedures to do something with the current node or edge
}
```
18 changes: 10 additions & 8 deletions docs/reverse-dfs.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ This space-efficient reverse DFS

## Example
```cpp
DirectedGraph g = Sealib::GraphCreator::createRandomFixed(1024, 16);
#include "sealib/iterator/reversedfs.h"
#include "sealib/graph/graphcreator.h"

ReverseDFS d(g);
d.init();
while (d.more()) {
UserCall c=d.next();
if(c.type==UserCall::postprocess) {
// do something
int main() {
DirectedGraph g = Sealib::GraphCreator::createRandomFixed(1024, 16);

ReverseDFS d(g);
d.init();
while (d.more()) {
UserCall c=d.next();
// do something with the user call
}
//...
}
```

0 comments on commit 7920f0a

Please sign in to comment.