├── LICENSE ├── README.md ├── data_scripts ├── BinarizeAdjacencyTSV.class ├── BinarizeAdjacencyTSV.java ├── Makefile ├── Transforma.java ├── Transforma2.java ├── dmgenerator │ ├── .gitignore │ ├── Makefile │ └── dmgen.c ├── lib │ ├── activation-1.1.jar │ ├── animal-sniffer-annotations-1.14.jar │ ├── checker-qual-2.5.2.jar │ ├── commons-collections-20040616.jar │ ├── commons-configuration-1.10.jar │ ├── commons-io-2.6.jar │ ├── commons-lang-2.6.jar │ ├── commons-lang3-3.9.jar │ ├── commons-logging-1.1.1.jar │ ├── commons-math3-3.6.1.jar │ ├── dsiutils-2.5.4.jar │ ├── error_prone_annotations-2.1.3.jar │ ├── fastutil-8.2.3.jar │ ├── guava-26.0-jre.jar │ ├── j2objc-annotations-1.1.jar │ ├── javax.mail-1.6.0.jar │ ├── jsap-2.1.jar │ ├── jsr305-3.0.2.jar │ ├── jung-algorithms-2.1.1.jar │ ├── jung-api-2.1.1.jar │ ├── jung-io-2.1.1.jar │ ├── logback-classic-1.3.0-alpha4.jar │ ├── logback-core-1.3.0-alpha4.jar │ ├── slf4j-api-1.8.0-beta4.jar │ ├── sux4j-5.0.0.jar │ └── webgraph-3.6.2.jar ├── scale_free_graph_generator.py ├── setup-dmgen-param.sh ├── setup-webgraph-param.sh ├── setup_dmgen.sh ├── setup_webgraphs.sh └── util.sh ├── datasets ├── dataset-adds-checks.tsv ├── dataset-adds-deletions.tsv ├── dataset-adds-lists.tsv ├── dataset-checks.tsv ├── dataset-deletions.tsv ├── dataset-lists.tsv ├── dataset.adj ├── dataset.kt └── dataset.tsv ├── eval_scripts ├── eval-dk2tree-dmgen.sh ├── eval-dk2tree-param.sh ├── eval-dk2tree-webgraph.sh ├── eval-k2tree-dmgen.sh ├── eval-k2tree-param.sh ├── eval-k2tree-webgraph.sh ├── eval-k2trie-dmgen.sh ├── eval-k2trie-param.sh ├── eval-k2trie-webgraph.sh ├── eval-sdk2sdsl-all-datasets-A.sh ├── eval-sdk2sdsl-all-datasets-AD.sh ├── eval-sdk2sdsl-dmgen-algo-CT-dummy.sh ├── eval-sdk2sdsl-dmgen-algo-PR.sh ├── eval-sdk2sdsl-dmgen-algo.sh ├── eval-sdk2sdsl-dmgen.sh ├── eval-sdk2sdsl-param-A.sh ├── eval-sdk2sdsl-param-AD.sh ├── eval-sdk2sdsl-param.sh ├── eval-sdk2sdsl-webgraph-algo-CT-dummy.sh ├── eval-sdk2sdsl-webgraph-algo.sh ├── eval-sdk2sdsl-webgraph.sh ├── eval-sdk2tree-all-datasets-A.sh ├── eval-sdk2tree-all-datasets-AD.sh ├── eval-sdk2tree-dmgen.sh ├── eval-sdk2tree-param-A.sh ├── eval-sdk2tree-param-AD.sh ├── eval-sdk2tree-param.sh ├── eval-sdk2tree-webgraph.sh ├── gnuplot-templates │ ├── gp-TEST_CASE.gnuplot │ └── gp-sdk2sdsl-ALGO-TEST.gnuplot ├── make_gnuplot_scripts.py ├── run-all.sh ├── run-k2sdsl-algos.sh └── streamer.sh ├── img ├── citic_logo.JPEG ├── enxenio_logo.png ├── inesc-id_logo.png └── ist_logo.png ├── implementations ├── Makefile ├── dk2tree │ ├── .gitignore │ ├── DynamicSequence.c │ ├── DynamicSequence.h │ ├── Makefile │ ├── MemoryManager.c │ ├── MemoryManager.h │ ├── README.md │ ├── basic.c │ ├── basic.h │ ├── comp.c │ ├── debug.h │ ├── encoding.c │ ├── encoding.h │ ├── hash.c │ ├── hash.h │ ├── k2tree-aux.h │ ├── k2tree-common.c │ ├── k2tree-common.h │ ├── k2tree-impl.c │ ├── k2tree-impl.h │ ├── k2tree-operations.c │ ├── lru.c │ ├── lru.h │ ├── main.c │ ├── nodeManager-common.c │ ├── nodeManager-disk-complete.c │ ├── nodeManager-disk.c │ ├── nodeManager-lru.c │ ├── nodeManager-mem-complete.c │ ├── nodeManager-mem.c │ ├── nodeManager.h │ ├── testCreateFromGraph.c │ ├── testInsert.c │ ├── testLoad.c │ ├── testLoadFromFile.c │ ├── testNeighbors.c │ ├── testOptimizeLastLevel.c │ ├── testRange.c │ ├── testRebuild.c │ ├── timing.h │ ├── translator.c │ ├── util.c │ ├── util.h │ ├── vocUtils.c │ └── vocUtils.h ├── k2tree │ ├── .gitignore │ ├── Entry.c │ ├── Entry.h │ ├── Makefile │ ├── NodeQueue.c │ ├── NodeQueue.h │ ├── Queue.c │ ├── Queue.h │ ├── README.md │ ├── adylist.c │ ├── adylist.h │ ├── adylist_setOperations.c │ ├── adylist_setOperations.h │ ├── adylist_setop_complement.c │ ├── adylist_setop_difference.c │ ├── adylist_setop_intersection.c │ ├── adylist_setop_symmdiff.c │ ├── adylist_setop_union.c │ ├── basic.c │ ├── basic.h │ ├── bitrankw32int.c │ ├── bitrankw32int.h │ ├── kTree.c │ ├── kTree.h │ ├── kt_buildTree.c │ ├── kt_decompressTree.c │ ├── kt_fromList.c │ ├── kt_getCell.c │ ├── kt_getNeightbors.c │ ├── kt_getRange.c │ ├── kt_getReverseNeightbors.c │ ├── kt_setOperations.c │ ├── kt_setOperations.h │ ├── kt_setop_complement.c │ ├── kt_setop_difference.c │ ├── kt_setop_intersection.c │ ├── kt_setop_symmdiff.c │ ├── kt_setop_union.c │ ├── kt_toList.c │ ├── main.c │ ├── misBits.c │ ├── misBits.h │ ├── pair.c │ └── pair.h ├── k2trie │ ├── .gitignore │ ├── LICENSE │ ├── Makefile │ ├── README.md │ ├── main.cpp │ ├── treeBlock.cpp │ └── treeBlock.h └── sdk2tree │ ├── .gitignore │ ├── Entry.c │ ├── Entry.h │ ├── Makefile │ ├── NodeQueue.c │ ├── NodeQueue.h │ ├── Queue.c │ ├── Queue.h │ ├── README.md │ ├── adylist.c │ ├── adylist.h │ ├── adylist_setOperations.c │ ├── adylist_setOperations.h │ ├── adylist_setop_complement.c │ ├── adylist_setop_difference.c │ ├── adylist_setop_intersection.c │ ├── adylist_setop_symmdiff.c │ ├── adylist_setop_union.c │ ├── basic.c │ ├── basic.h │ ├── bitrankw32int.c │ ├── bitrankw32int.h │ ├── kTree.c │ ├── kTree.h │ ├── kt_buildTree.c │ ├── kt_decompressTree.c │ ├── kt_fromList.c │ ├── kt_getCell.c │ ├── kt_getNeightbors.c │ ├── kt_getRange.c │ ├── kt_getReverseNeightbors.c │ ├── kt_setOperations.c │ ├── kt_setOperations.h │ ├── kt_setop_complement.c │ ├── kt_setop_difference.c │ ├── kt_setop_intersection.c │ ├── kt_setop_symmdiff.c │ ├── kt_setop_union.c │ ├── kt_toList.c │ ├── main.c │ ├── misBits.c │ ├── misBits.h │ ├── pair.c │ └── pair.h └── python ├── __pycache__ └── matplotlib_config.cpython-37.pyc ├── make_op_streams.py └── plot_figures.py /data_scripts/BinarizeAdjacencyTSV.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aplf/sdk2tree/c86a1df6b0a8ea3d40bc9799472da3db201ba53a/data_scripts/BinarizeAdjacencyTSV.class -------------------------------------------------------------------------------- /data_scripts/BinarizeAdjacencyTSV.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.ArrayList; 3 | import java.util.Arrays; 4 | import java.util.Collections; 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | import java.util.TreeMap; 8 | 9 | import it.unimi.dsi.webgraph.*; 10 | import it.unimi.dsi.fastutil.ints.*; 11 | 12 | /** 13 | * Transforms WebGraph compressed datasets into the format expected by the 14 | * k2-tree implementation of this project which is located in directory src/ 15 | * 16 | */ 17 | class BinarizeAdjacencyTSV { 18 | 19 | public static void main(String[] args) throws Exception { 20 | if (args.length != 1) { 21 | System.out.println("Uso: java BinarizeAdjacencyTSV "); 22 | return; 23 | } 24 | 25 | // TODO: 1 convert from regular 'a 5 1' commands to . 26 | final FileInputStream fstream = new FileInputStream(args[0]); 27 | final BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); 28 | 29 | String strLine; 30 | 31 | // Read File Line By Line 32 | final Map> adj = new TreeMap>(); 33 | 34 | long edgeCtr = 0; 35 | while ((strLine = br.readLine()) != null) { 36 | 37 | if (strLine.startsWith("a")) { 38 | 39 | edgeCtr = edgeCtr + 1; 40 | 41 | final String[] tokens = strLine.split("\\s+"); 42 | final int src = Integer.parseInt(tokens[1]); 43 | final int dst = Integer.parseInt(tokens[2]); 44 | 45 | if (!adj.containsKey(src)) { 46 | final ArrayList l = new ArrayList<>(); 47 | l.add(dst); 48 | adj.put(src, l); 49 | } else { 50 | adj.get(src).add(dst); 51 | } 52 | } 53 | } 54 | 55 | // Close the input stream 56 | fstream.close(); 57 | 58 | // BVGraph gr = BVGraph.load(args[0]); 59 | final int termIndex = args[0].lastIndexOf("."); 60 | final RandomAccessFile out = new RandomAccessFile(args[0].substring(0, termIndex > -1 ? termIndex : args[0].length()) + ".adj", "rw"); 61 | 62 | 63 | 64 | out.writeInt(Integer.reverseBytes(adj.size())); 65 | out.writeLong(Long.reverseBytes(edgeCtr)); 66 | 67 | // adj.keySet().s 68 | 69 | for (Integer i : adj.keySet()) { 70 | 71 | out.writeInt(Integer.reverseBytes(-(i+1))); 72 | 73 | final ArrayList neighbors = adj.get(i); 74 | Collections.sort(neighbors); 75 | for(int n : neighbors) { 76 | out.writeInt(Integer.reverseBytes(1+n)); 77 | } 78 | 79 | if(i%1000000==0) System.out.println("Nodes "+i); 80 | } 81 | 82 | //out.writeInt(Integer.reverseBytes(gr.numNodes())); 83 | //out.writeLong(Long.reverseBytes(gr.numArcs())); 84 | /* 85 | for(int i=0;i"); 17 | return; 18 | } 19 | BVGraph gr = BVGraph.load(args[0]); 20 | RandomAccessFile out = new RandomAccessFile(args[0]+".adj","rw"); 21 | out.writeInt(Integer.reverseBytes(gr.numNodes())); 22 | out.writeLong(Long.reverseBytes(gr.numArcs())); 23 | for(int i=0;i"); 16 | return; 17 | } 18 | BVGraph gr = BVGraph.load(args[0]); 19 | for(int i=0;i 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | #define rand_p() (((double) rand()) / RAND_MAX) 13 | #define rand_n(n) ((int) (((double) (n)) * (rand() / (RAND_MAX + 1.0)))) 14 | 15 | struct lst { 16 | unsigned v; 17 | struct lst *nxt; 18 | }; 19 | 20 | void usage(){ 21 | fprintf(stderr, "Usage: dmgen \n"); 22 | } 23 | 24 | int 25 | main(int argc, char *argv[]) 26 | { 27 | unsigned nv_arg, i, nv, ne, u, v, w, idstart; 28 | double p; 29 | struct timeval t; 30 | struct lst **adj, *e, *f, *g; 31 | int *adj_sz, max_dg, *dg; 32 | 33 | if (argc != 4) { 34 | usage(); 35 | exit(EXIT_FAILURE); 36 | } 37 | 38 | nv_arg = atoi(argv[1]); 39 | p = strtod(argv[2], (char **) NULL); 40 | idstart = atoi(argv[3]); 41 | 42 | fprintf(stderr, "main: args: %d %g\n", nv_arg, p); 43 | assert(nv_arg > 0 && p >= 0.0 && p <= 1.0); 44 | 45 | gettimeofday(&t, NULL); 46 | srand((unsigned) (t.tv_sec ^ t.tv_usec)); 47 | 48 | adj = (struct lst **) malloc(sizeof(struct lst *)*nv_arg); 49 | memset(adj, 0, sizeof(struct lst *)*nv_arg); 50 | adj_sz = (int *) malloc(sizeof(int)*nv_arg); 51 | memset(adj_sz, 0, sizeof(int)*nv_arg); 52 | 53 | nv = 1; 54 | ne = 0; 55 | 56 | while (nv < nv_arg) { 57 | u = rand_n(nv); 58 | v = nv; 59 | nv ++; 60 | 61 | printf("a %d %d\n", u, v); 62 | printf("a %d %d\n", v, u); 63 | 64 | e = (struct lst *) malloc(sizeof(struct lst)); 65 | e->v = v; 66 | e->nxt = adj[u]; 67 | adj[u] = e; 68 | adj_sz[u] ++; 69 | 70 | f = (struct lst *) malloc(sizeof(struct lst)); 71 | f->v = u; 72 | f->nxt = adj[v]; 73 | adj[v] = f; 74 | adj_sz[v] ++; 75 | 76 | ne++; 77 | 78 | for(g = adj[u]->nxt; g != NULL; g = g->nxt) { 79 | if (rand_p() > p) 80 | continue; 81 | 82 | w = g->v; 83 | 84 | printf("a %d %d\n", v, w); 85 | printf("a %d %d\n", w, v); 86 | 87 | e = (struct lst *) malloc(sizeof(struct lst)); 88 | e->v = w; 89 | e->nxt = adj[v]; 90 | adj[v] = e; 91 | adj_sz[v] ++; 92 | 93 | f = (struct lst *) malloc(sizeof(struct lst)); 94 | f->v = v; 95 | f->nxt = adj[w]; 96 | adj[w] = f; 97 | adj_sz[w] ++; 98 | 99 | ne++; 100 | } 101 | } 102 | 103 | //printf("x\n"); 104 | 105 | fprintf(stderr, "main: graph: %d %d\n", nv, ne); 106 | assert(nv == nv_arg); 107 | 108 | /*printf("%d %d\n", nv, ne); 109 | for (i = 0; i < nv_arg; i++) 110 | for(g = adj[i]; g != NULL; g = g->nxt) 111 | if (g->v > i) 112 | printf("%d %d\n", i + idstart, g->v + idstart);*/ 113 | 114 | for (i = 0; i < nv_arg; i++) { 115 | e = adj[i]; 116 | while (e != NULL) { 117 | g = e; 118 | e = e->nxt; 119 | free(g); 120 | } 121 | } 122 | free(adj); 123 | 124 | for (max_dg = i = 0; i < nv_arg; i++) 125 | if (max_dg < adj_sz[i]) 126 | max_dg = adj_sz[i]; 127 | 128 | dg = (int *) malloc(sizeof(int)*(max_dg + 1)); 129 | memset(dg, 0, sizeof(int)*(max_dg + 1)); 130 | 131 | for (i = 0; i < nv_arg; i++) 132 | dg[adj_sz[i]] ++; 133 | 134 | /* 135 | for (i = 1; i <= max_dg; i++) 136 | printf("%d:%d\n", i, dg[i]); 137 | */ 138 | 139 | free(adj_sz); 140 | free(dg); 141 | 142 | return EXIT_SUCCESS; 143 | } 144 | 145 | -------------------------------------------------------------------------------- /data_scripts/lib/activation-1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aplf/sdk2tree/c86a1df6b0a8ea3d40bc9799472da3db201ba53a/data_scripts/lib/activation-1.1.jar -------------------------------------------------------------------------------- /data_scripts/lib/animal-sniffer-annotations-1.14.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aplf/sdk2tree/c86a1df6b0a8ea3d40bc9799472da3db201ba53a/data_scripts/lib/animal-sniffer-annotations-1.14.jar -------------------------------------------------------------------------------- /data_scripts/lib/checker-qual-2.5.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aplf/sdk2tree/c86a1df6b0a8ea3d40bc9799472da3db201ba53a/data_scripts/lib/checker-qual-2.5.2.jar -------------------------------------------------------------------------------- /data_scripts/lib/commons-collections-20040616.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aplf/sdk2tree/c86a1df6b0a8ea3d40bc9799472da3db201ba53a/data_scripts/lib/commons-collections-20040616.jar -------------------------------------------------------------------------------- /data_scripts/lib/commons-configuration-1.10.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aplf/sdk2tree/c86a1df6b0a8ea3d40bc9799472da3db201ba53a/data_scripts/lib/commons-configuration-1.10.jar -------------------------------------------------------------------------------- /data_scripts/lib/commons-io-2.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aplf/sdk2tree/c86a1df6b0a8ea3d40bc9799472da3db201ba53a/data_scripts/lib/commons-io-2.6.jar -------------------------------------------------------------------------------- /data_scripts/lib/commons-lang-2.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aplf/sdk2tree/c86a1df6b0a8ea3d40bc9799472da3db201ba53a/data_scripts/lib/commons-lang-2.6.jar -------------------------------------------------------------------------------- /data_scripts/lib/commons-lang3-3.9.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aplf/sdk2tree/c86a1df6b0a8ea3d40bc9799472da3db201ba53a/data_scripts/lib/commons-lang3-3.9.jar -------------------------------------------------------------------------------- /data_scripts/lib/commons-logging-1.1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aplf/sdk2tree/c86a1df6b0a8ea3d40bc9799472da3db201ba53a/data_scripts/lib/commons-logging-1.1.1.jar -------------------------------------------------------------------------------- /data_scripts/lib/commons-math3-3.6.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aplf/sdk2tree/c86a1df6b0a8ea3d40bc9799472da3db201ba53a/data_scripts/lib/commons-math3-3.6.1.jar -------------------------------------------------------------------------------- /data_scripts/lib/dsiutils-2.5.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aplf/sdk2tree/c86a1df6b0a8ea3d40bc9799472da3db201ba53a/data_scripts/lib/dsiutils-2.5.4.jar -------------------------------------------------------------------------------- /data_scripts/lib/error_prone_annotations-2.1.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aplf/sdk2tree/c86a1df6b0a8ea3d40bc9799472da3db201ba53a/data_scripts/lib/error_prone_annotations-2.1.3.jar -------------------------------------------------------------------------------- /data_scripts/lib/fastutil-8.2.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aplf/sdk2tree/c86a1df6b0a8ea3d40bc9799472da3db201ba53a/data_scripts/lib/fastutil-8.2.3.jar -------------------------------------------------------------------------------- /data_scripts/lib/guava-26.0-jre.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aplf/sdk2tree/c86a1df6b0a8ea3d40bc9799472da3db201ba53a/data_scripts/lib/guava-26.0-jre.jar -------------------------------------------------------------------------------- /data_scripts/lib/j2objc-annotations-1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aplf/sdk2tree/c86a1df6b0a8ea3d40bc9799472da3db201ba53a/data_scripts/lib/j2objc-annotations-1.1.jar -------------------------------------------------------------------------------- /data_scripts/lib/javax.mail-1.6.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aplf/sdk2tree/c86a1df6b0a8ea3d40bc9799472da3db201ba53a/data_scripts/lib/javax.mail-1.6.0.jar -------------------------------------------------------------------------------- /data_scripts/lib/jsap-2.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aplf/sdk2tree/c86a1df6b0a8ea3d40bc9799472da3db201ba53a/data_scripts/lib/jsap-2.1.jar -------------------------------------------------------------------------------- /data_scripts/lib/jsr305-3.0.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aplf/sdk2tree/c86a1df6b0a8ea3d40bc9799472da3db201ba53a/data_scripts/lib/jsr305-3.0.2.jar -------------------------------------------------------------------------------- /data_scripts/lib/jung-algorithms-2.1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aplf/sdk2tree/c86a1df6b0a8ea3d40bc9799472da3db201ba53a/data_scripts/lib/jung-algorithms-2.1.1.jar -------------------------------------------------------------------------------- /data_scripts/lib/jung-api-2.1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aplf/sdk2tree/c86a1df6b0a8ea3d40bc9799472da3db201ba53a/data_scripts/lib/jung-api-2.1.1.jar -------------------------------------------------------------------------------- /data_scripts/lib/jung-io-2.1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aplf/sdk2tree/c86a1df6b0a8ea3d40bc9799472da3db201ba53a/data_scripts/lib/jung-io-2.1.1.jar -------------------------------------------------------------------------------- /data_scripts/lib/logback-classic-1.3.0-alpha4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aplf/sdk2tree/c86a1df6b0a8ea3d40bc9799472da3db201ba53a/data_scripts/lib/logback-classic-1.3.0-alpha4.jar -------------------------------------------------------------------------------- /data_scripts/lib/logback-core-1.3.0-alpha4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aplf/sdk2tree/c86a1df6b0a8ea3d40bc9799472da3db201ba53a/data_scripts/lib/logback-core-1.3.0-alpha4.jar -------------------------------------------------------------------------------- /data_scripts/lib/slf4j-api-1.8.0-beta4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aplf/sdk2tree/c86a1df6b0a8ea3d40bc9799472da3db201ba53a/data_scripts/lib/slf4j-api-1.8.0-beta4.jar -------------------------------------------------------------------------------- /data_scripts/lib/sux4j-5.0.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aplf/sdk2tree/c86a1df6b0a8ea3d40bc9799472da3db201ba53a/data_scripts/lib/sux4j-5.0.0.jar -------------------------------------------------------------------------------- /data_scripts/lib/webgraph-3.6.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aplf/sdk2tree/c86a1df6b0a8ea3d40bc9799472da3db201ba53a/data_scripts/lib/webgraph-3.6.2.jar -------------------------------------------------------------------------------- /data_scripts/setup_dmgen.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ####################################################### 4 | ##################### Synthetic dmgenerator files. #### 5 | ####################################################### 6 | 7 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 8 | PROJ_ROOT=$DIR/.. 9 | 10 | cd $DIR 11 | 12 | 13 | ./setup-dmgen-param.sh 50000 14 | ./setup-dmgen-param.sh 100000 15 | ./setup-dmgen-param.sh 500000 16 | ./setup-dmgen-param.sh 1000000 17 | #./setup-dmgen-param.sh 10000000 18 | 19 | cd $PROJ_ROOT -------------------------------------------------------------------------------- /data_scripts/setup_webgraphs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ####################################################### 4 | ####################### Real-world WebGraph files. #### 5 | ####################################################### 6 | 7 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 8 | PROJ_ROOT=$DIR/.. 9 | 10 | cd $DIR 11 | 12 | 13 | ./setup-webgraph-param.sh uk-2007-05@100000 14 | ./setup-webgraph-param.sh in-2004 15 | ./setup-webgraph-param.sh eu-2015-host 16 | ./setup-webgraph-param.sh indochina-2004 17 | ./setup-webgraph-param.sh uk-2014-host 18 | 19 | cd $PROJ_ROOT -------------------------------------------------------------------------------- /data_scripts/util.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | unameOut="$(uname -s)" 4 | case "${unameOut}" in 5 | Linux*) machine=Linux;; 6 | Darwin*) machine=Mac;; 7 | CYGWIN*) machine=Cygwin;; 8 | MINGW*) machine=MinGw;; 9 | *) machine="UNKNOWN:${unameOut}" 10 | esac 11 | 12 | # https://stackoverflow.com/questions/3601515/how-to-check-if-a-variable-is-set-in-bash 13 | if [ "$machine" == "Cygwin" ]; then 14 | export CLASSPATH="$(cygpath -w "${PROJ_ROOT}")"";$(cygpath -w "${PROJ_ROOT}")data_scripts\lib\*" 15 | #TODO: neet to test if this compiles in Cygwin (probably not) 16 | else 17 | if [ -z ${PROJ_ROOT+x} ]; then 18 | CLASSPATH_PREFIX="lib/*" 19 | else 20 | CLASSPATH_PREFIX="$PROJ_ROOT:$PROJ_ROOT/data_scripts/*:$PROJ_ROOT/data_scripts/lib/*" 21 | fi 22 | export CLASSPATH="$CLASSPATH:$CLASSPATH_PREFIX" 23 | #export CLASSPATH="$PROJ_ROOT:$PROJ_ROOT/data_scripts/lib/*" 24 | fi 25 | 26 | echo "$CLASSPATH" -------------------------------------------------------------------------------- /datasets/dataset-adds-checks.tsv: -------------------------------------------------------------------------------- 1 | a 0 1 2 | a 0 2 3 | a 1 3 4 | a 1 2 5 | a 2 4 6 | a 3 5 7 | a 4 5 8 | a 5 6 9 | a 5 7 10 | a 6 8 11 | a 7 8 12 | l 0 1 13 | l 0 2 14 | l 1 3 15 | l 1 2 16 | l 2 4 17 | l 3 5 18 | l 4 5 19 | l 5 6 20 | l 5 7 21 | l 6 8 22 | l 7 8 23 | l 8 15 24 | z -------------------------------------------------------------------------------- /datasets/dataset-adds-deletions.tsv: -------------------------------------------------------------------------------- 1 | a 0 1 2 | a 0 2 3 | a 1 3 4 | a 1 2 5 | a 2 4 6 | a 3 5 7 | a 4 5 8 | a 5 6 9 | a 5 7 10 | a 6 8 11 | a 7 8 12 | d 0 1 13 | d 0 2 14 | d 1 3 15 | d 1 2 16 | d 2 4 17 | s 18 | x -------------------------------------------------------------------------------- /datasets/dataset-adds-lists.tsv: -------------------------------------------------------------------------------- 1 | a 0 1 2 | a 0 2 3 | a 1 3 4 | a 1 2 5 | a 2 4 6 | a 3 5 7 | a 4 5 8 | a 5 6 9 | a 5 7 10 | a 6 8 11 | a 7 8 12 | n 0 13 | n 1 14 | n 2 15 | n 3 16 | n 4 17 | n 5 18 | n 6 19 | n 7 20 | n 8 21 | x 22 | -------------------------------------------------------------------------------- /datasets/dataset-checks.tsv: -------------------------------------------------------------------------------- 1 | l 0 1 2 | l 0 2 3 | l 1 3 4 | l 1 2 5 | l 2 4 6 | l 3 5 7 | l 4 5 8 | l 5 6 9 | l 5 7 10 | l 6 8 11 | l 7 8 12 | l 8 15 13 | x -------------------------------------------------------------------------------- /datasets/dataset-deletions.tsv: -------------------------------------------------------------------------------- 1 | d 0 1 2 | d 0 2 3 | d 1 3 4 | d 1 2 5 | d 2 4 6 | s 7 | x -------------------------------------------------------------------------------- /datasets/dataset-lists.tsv: -------------------------------------------------------------------------------- 1 | n 0 2 | n 1 3 | n 2 4 | n 3 5 | n 4 6 | n 5 7 | n 6 8 | n 7 9 | n 8 10 | x -------------------------------------------------------------------------------- /datasets/dataset.adj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aplf/sdk2tree/c86a1df6b0a8ea3d40bc9799472da3db201ba53a/datasets/dataset.adj -------------------------------------------------------------------------------- /datasets/dataset.kt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aplf/sdk2tree/c86a1df6b0a8ea3d40bc9799472da3db201ba53a/datasets/dataset.kt -------------------------------------------------------------------------------- /datasets/dataset.tsv: -------------------------------------------------------------------------------- 1 | a 0 1 2 | a 0 2 3 | a 1 3 4 | a 1 2 5 | a 2 4 6 | a 3 5 7 | a 4 5 8 | a 5 6 9 | a 5 7 10 | a 6 8 11 | a 7 8 12 | s 13 | x -------------------------------------------------------------------------------- /eval_scripts/eval-dk2tree-dmgen.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 4 | PROJ_ROOT="$DIR/.." 5 | 6 | cd "$PROJ_ROOT" 7 | 8 | # Create evaluation results directory if it does not exist. 9 | #mkdir -p "$PROJ_ROOT/evaluated_dataset" 10 | 11 | mkdir -p "$1" 12 | 13 | "$DIR"/eval-dk2tree-param.sh prepared_datasets/dmgen/50000 50000 50000 $1 14 | "$DIR"/eval-dk2tree-param.sh prepared_datasets/dmgen/100000 100000 100000 $1 15 | "$DIR"/eval-dk2tree-param.sh prepared_datasets/dmgen/500000 500000 500000 $1 16 | "$DIR"/eval-dk2tree-param.sh prepared_datasets/dmgen/1000000 1000000 1000000 $1 17 | -------------------------------------------------------------------------------- /eval_scripts/eval-dk2tree-webgraph.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 4 | PROJ_ROOT="$DIR/.." 5 | 6 | cd "$PROJ_ROOT" 7 | 8 | # Create evaluation results directory if it does not exist. 9 | #mkdir -p "$PROJ_ROOT/evaluated_dataset" 10 | 11 | mkdir -p "$1" 12 | 13 | "$DIR"/eval-dk2tree-param.sh prepared_datasets/webgraph/uk-2007-05@100000 uk-2007-05@100000 100000 $1 14 | "$DIR"/eval-dk2tree-param.sh prepared_datasets/webgraph/in-2004 in-2004 1382908 $1 15 | "$DIR"/eval-dk2tree-param.sh prepared_datasets/webgraph/uk-2014-host uk-2014-host 4769354 $1 16 | "$DIR"/eval-dk2tree-param.sh prepared_datasets/webgraph/indochina-2004 indochina-2004 7414866 $1 17 | "$DIR"/eval-dk2tree-param.sh prepared_datasets/webgraph/eu-2015-host eu-2015-host 11264052 $1 18 | -------------------------------------------------------------------------------- /eval_scripts/eval-k2tree-dmgen.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 4 | PROJ_ROOT="$DIR/.." 5 | 6 | cd "$PROJ_ROOT" 7 | 8 | # Create evaluation results directory if it does not exist. 9 | #mkdir -p "$PROJ_ROOT/evaluated_dataset" 10 | mkdir -p "$1" 11 | 12 | "$DIR"/eval-k2tree-param.sh prepared_datasets/dmgen/50000 50000 $1 13 | "$DIR"/eval-k2tree-param.sh prepared_datasets/dmgen/100000 100000 $1 14 | "$DIR"/eval-k2tree-param.sh prepared_datasets/dmgen/500000 500000 $1 15 | "$DIR"/eval-k2tree-param.sh prepared_datasets/dmgen/1000000 1000000 $1 16 | 17 | -------------------------------------------------------------------------------- /eval_scripts/eval-k2tree-param.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 4 | PROJ_ROOT="$DIR/.." 5 | 6 | cd "$PROJ_ROOT" 7 | 8 | IMPLEMENTATION="k2tree" 9 | 10 | # Create evaluation results directory if it does not exist. 11 | #OUT_DIR="$PROJ_ROOT/evaluated_dataset/$2/$IMPLEMENTATION" 12 | OUT_DIR="$3/$2/$IMPLEMENTATION" 13 | mkdir -p $OUT_DIR 14 | 15 | cd $OUT_DIR 16 | 17 | K2TREE_BIN="$PROJ_ROOT/implementations/$IMPLEMENTATION/project" 18 | 19 | STREAMER_BIN="$DIR/streamer.sh" 20 | 21 | printf "####################\n" 22 | printf "#################### $IMPLEMENTATION: static k2-tree evaluation: $1/$2\n" 23 | printf "####################\n\n" 24 | 25 | 26 | printf "#########\n" 27 | printf "##### Scenario: additions + lists (AL).\n" 28 | printf "#########\n\n" 29 | 30 | 31 | if test -f "$OUT_DIR/$2-$IMPLEMENTATION-AL-time.tsv"; then 32 | printf "> $OUT_DIR/$2-$IMPLEMENTATION-AL-time.tsv file exists.\n" 33 | else 34 | printf "> Generating $OUT_DIR/$2-$IMPLEMENTATION-AL-time.tsv:\n" 35 | 36 | printf "/usr/bin/time -v -o $OUT_DIR/$2-$IMPLEMENTATION-AL-memory.txt $K2TREE_BIN $PROJ_ROOT/$1/$2 "$2_lists_eval" < <( $STREAMER_BIN $PROJ_ROOT/$1/$2-lists.tsv ) > /dev/null 2> $OUT_DIR/$2-$IMPLEMENTATION-AL.err\n" 37 | 38 | /usr/bin/time -v -o $OUT_DIR/$2-$IMPLEMENTATION-AL-memory.txt $K2TREE_BIN $PROJ_ROOT/$1/$2 "$2_lists_eval" < <( $STREAMER_BIN $PROJ_ROOT/$1/$2-lists.tsv ) > /dev/null 2> $OUT_DIR/$2-$IMPLEMENTATION-AL.err ; 39 | 40 | mv ${IMPLEMENTATION}_times.tsv $2-$IMPLEMENTATION-AL-time.tsv 41 | 42 | fi 43 | 44 | 45 | printf "\n#########\n" 46 | printf "##### Scenario: additions + checks (AC).\n" 47 | printf "#########\n\n" 48 | 49 | 50 | if test -f "$OUT_DIR/$2-$IMPLEMENTATION-AC-time.tsv"; then 51 | printf "> $OUT_DIR/$2-$IMPLEMENTATION-AC-time.tsv file exists.\n" 52 | else 53 | printf "> Generating $OUT_DIR/$2-$IMPLEMENTATION-AC-time.tsv:\n" 54 | 55 | printf "/usr/bin/time -v -o $OUT_DIR/$2-$IMPLEMENTATION-AC-memory.txt $K2TREE_BIN $PROJ_ROOT/$1/$2 "$2_lists_eval" < <( $STREAMER_BIN $PROJ_ROOT/$1/$2-checks.tsv ) > /dev/null 2> $OUT_DIR/$2-$IMPLEMENTATION-AC.err\n" 56 | 57 | /usr/bin/time -v -o $OUT_DIR/$2-$IMPLEMENTATION-AC-memory.txt $K2TREE_BIN $PROJ_ROOT/$1/$2 "$2_lists_eval" < <( $STREAMER_BIN $PROJ_ROOT/$1/$2-checks.tsv ) > /dev/null 2> $OUT_DIR/$2-$IMPLEMENTATION-AC.err ; 58 | 59 | mv ${IMPLEMENTATION}_times.tsv $2-$IMPLEMENTATION-AC-time.tsv 60 | 61 | fi -------------------------------------------------------------------------------- /eval_scripts/eval-k2tree-webgraph.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 4 | PROJ_ROOT="$DIR/.." 5 | 6 | cd "$PROJ_ROOT" 7 | 8 | # Create evaluation results directory if it does not exist. 9 | #mkdir -p "$PROJ_ROOT/evaluated_dataset" 10 | mkdir -p "$1" 11 | 12 | "$DIR"/eval-k2tree-param.sh prepared_datasets/webgraph/uk-2007-05@100000 uk-2007-05@100000 $1 13 | "$DIR"/eval-k2tree-param.sh prepared_datasets/webgraph/in-2004 in-2004 $1 14 | "$DIR"/eval-k2tree-param.sh prepared_datasets/webgraph/uk-2014-host uk-2014-host $1 15 | "$DIR"/eval-k2tree-param.sh prepared_datasets/webgraph/indochina-2004 indochina-2004 $1 16 | "$DIR"/eval-k2tree-param.sh prepared_datasets/webgraph/eu-2015-host eu-2015-host $1 17 | -------------------------------------------------------------------------------- /eval_scripts/eval-k2trie-dmgen.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 4 | PROJ_ROOT="$DIR/.." 5 | 6 | cd "$PROJ_ROOT" 7 | 8 | # Create evaluation results directory if it does not exist. 9 | #mkdir -p "$PROJ_ROOT/evaluated_dataset" 10 | mkdir -p "$1" 11 | 12 | "$DIR"/eval-k2trie-param.sh prepared_datasets/dmgen/50000 50000 50000 $1 13 | "$DIR"/eval-k2trie-param.sh prepared_datasets/dmgen/100000 100000 100000 $1 14 | "$DIR"/eval-k2trie-param.sh prepared_datasets/dmgen/500000 500000 500000 $1 15 | "$DIR"/eval-k2trie-param.sh prepared_datasets/dmgen/1000000 1000000 1000000 $1 16 | -------------------------------------------------------------------------------- /eval_scripts/eval-k2trie-webgraph.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 4 | PROJ_ROOT="$DIR/.." 5 | 6 | cd "$PROJ_ROOT" 7 | 8 | # Create evaluation results directory if it does not exist. 9 | #mkdir -p "$PROJ_ROOT/evaluated_dataset" 10 | mkdir -p "$1" 11 | 12 | "$DIR"/eval-k2trie-param.sh prepared_datasets/webgraph/uk-2007-05@100000 uk-2007-05@100000 100000 $1 13 | "$DIR"/eval-k2trie-param.sh prepared_datasets/webgraph/in-2004 in-2004 1382908 $1 14 | "$DIR"/eval-k2trie-param.sh prepared_datasets/webgraph/uk-2014-host uk-2014-host 4769354 $1 15 | "$DIR"/eval-k2trie-param.sh prepared_datasets/webgraph/indochina-2004 indochina-2004 7414866 $1 16 | "$DIR"/eval-k2trie-param.sh prepared_datasets/webgraph/eu-2015-host eu-2015-host 11264052 $1 17 | -------------------------------------------------------------------------------- /eval_scripts/eval-sdk2sdsl-all-datasets-A.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 4 | PROJ_ROOT="$DIR/.." 5 | 6 | cd "$PROJ_ROOT" 7 | 8 | # Create evaluation results directory if it does not exist. 9 | #mkdir -p "$PROJ_ROOT/evaluated_dataset" 10 | 11 | mkdir -p "$1" 12 | 13 | #echo "$1" 14 | 15 | 16 | 17 | "$DIR"/eval-sdk2sdsl-param-A.sh prepared_datasets/dmgen/50000 50000 50000 $1 18 | "$DIR"/eval-sdk2sdsl-param-A.sh prepared_datasets/dmgen/100000 100000 100000 $1 19 | "$DIR"/eval-sdk2sdsl-param-A.sh prepared_datasets/dmgen/500000 500000 500000 $1 20 | "$DIR"/eval-sdk2sdsl-param-A.sh prepared_datasets/dmgen/1000000 1000000 1000000 $1 21 | 22 | "$DIR"/eval-sdk2sdsl-param-A.sh prepared_datasets/webgraph/uk-2007-05@100000 uk-2007-05@100000 100000 $1 23 | "$DIR"/eval-sdk2sdsl-param-A.sh prepared_datasets/webgraph/in-2004 in-2004 1382908 $1 24 | "$DIR"/eval-sdk2sdsl-param-A.sh prepared_datasets/webgraph/uk-2014-host uk-2014-host 4769354 $1 25 | "$DIR"/eval-sdk2sdsl-param-A.sh prepared_datasets/webgraph/indochina-2004 indochina-2004 7414866 $1 26 | "$DIR"/eval-sdk2sdsl-param-A.sh prepared_datasets/webgraph/eu-2015-host eu-2015-host 11264052 $1 -------------------------------------------------------------------------------- /eval_scripts/eval-sdk2sdsl-all-datasets-AD.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 4 | PROJ_ROOT="$DIR/.." 5 | 6 | cd "$PROJ_ROOT" 7 | 8 | # Create evaluation results directory if it does not exist. 9 | #mkdir -p "$PROJ_ROOT/evaluated_dataset" 10 | 11 | mkdir -p "$1" 12 | 13 | #echo "$1" 14 | 15 | 16 | 17 | "$DIR"/eval-sdk2sdsl-param-AD.sh prepared_datasets/dmgen/50000 50000 50000 $1 18 | "$DIR"/eval-sdk2sdsl-param-AD.sh prepared_datasets/dmgen/100000 100000 100000 $1 19 | "$DIR"/eval-sdk2sdsl-param-AD.sh prepared_datasets/dmgen/500000 500000 500000 $1 20 | "$DIR"/eval-sdk2sdsl-param-AD.sh prepared_datasets/dmgen/1000000 1000000 1000000 $1 21 | 22 | "$DIR"/eval-sdk2sdsl-param-AD.sh prepared_datasets/webgraph/uk-2007-05@100000 uk-2007-05@100000 100000 $1 23 | "$DIR"/eval-sdk2sdsl-param-AD.sh prepared_datasets/webgraph/in-2004 in-2004 1382908 $1 24 | "$DIR"/eval-sdk2sdsl-param-AD.sh prepared_datasets/webgraph/uk-2014-host uk-2014-host 4769354 $1 25 | "$DIR"/eval-sdk2sdsl-param-AD.sh prepared_datasets/webgraph/indochina-2004 indochina-2004 7414866 $1 26 | "$DIR"/eval-sdk2sdsl-param-AD.sh prepared_datasets/webgraph/eu-2015-host eu-2015-host 11264052 $1 -------------------------------------------------------------------------------- /eval_scripts/eval-sdk2sdsl-dmgen-algo-CT-dummy.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 4 | PROJ_ROOT="$DIR/.." 5 | 6 | cd "$PROJ_ROOT" 7 | 8 | # Create evaluation results directory if it does not exist. 9 | #mkdir -p "$PROJ_ROOT/evaluated_dataset" 10 | mkdir -p "$1" 11 | 12 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/dmgen/50000 50000 50000 $1 CT_dummy 13 | 14 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/dmgen/100000 100000 100000 $1 CT_dummy 15 | 16 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/dmgen/500000 500000 500000 $1 CT_dummy 17 | 18 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/dmgen/1000000 1000000 1000000 $1 CT_dummy 19 | -------------------------------------------------------------------------------- /eval_scripts/eval-sdk2sdsl-dmgen-algo-PR.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 4 | PROJ_ROOT="$DIR/.." 5 | 6 | cd "$PROJ_ROOT" 7 | 8 | # Create evaluation results directory if it does not exist. 9 | #mkdir -p "$PROJ_ROOT/evaluated_dataset" 10 | mkdir -p "$1" 11 | 12 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/dmgen/50000 50000 50000 $1 PR 13 | 14 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/dmgen/100000 100000 100000 $1 PR 15 | 16 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/dmgen/500000 500000 500000 $1 PR 17 | 18 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/dmgen/1000000 1000000 1000000 $1 PR 19 | -------------------------------------------------------------------------------- /eval_scripts/eval-sdk2sdsl-dmgen-algo.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 4 | PROJ_ROOT="$DIR/.." 5 | 6 | cd "$PROJ_ROOT" 7 | 8 | # Create evaluation results directory if it does not exist. 9 | #mkdir -p "$PROJ_ROOT/evaluated_dataset" 10 | mkdir -p "$1" 11 | 12 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/dmgen/50000 50000 50000 $1 PR 13 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/dmgen/50000 50000 50000 $1 BFS 14 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/dmgen/50000 50000 50000 $1 DFS 15 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/dmgen/50000 50000 50000 $1 CC 16 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/dmgen/50000 50000 50000 $1 CT_dummy_hash 17 | 18 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/dmgen/100000 100000 100000 $1 PR 19 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/dmgen/100000 100000 100000 $1 BFS 20 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/dmgen/100000 100000 100000 $1 DFS 21 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/dmgen/100000 100000 100000 $1 CC 22 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/dmgen/100000 100000 100000 $1 CT_dummy_hash 23 | 24 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/dmgen/500000 500000 500000 $1 PR 25 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/dmgen/500000 500000 500000 $1 BFS 26 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/dmgen/500000 500000 500000 $1 DFS 27 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/dmgen/500000 500000 500000 $1 CC 28 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/dmgen/500000 500000 500000 $1 CT_dummy_hash 29 | 30 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/dmgen/1000000 1000000 1000000 $1 PR 31 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/dmgen/1000000 1000000 1000000 $1 BFS 32 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/dmgen/1000000 1000000 1000000 $1 DFS 33 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/dmgen/1000000 1000000 1000000 $1 CC 34 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/dmgen/1000000 1000000 1000000 $1 CT_dummy_hash 35 | -------------------------------------------------------------------------------- /eval_scripts/eval-sdk2sdsl-dmgen.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 4 | PROJ_ROOT="$DIR/.." 5 | 6 | cd "$PROJ_ROOT" 7 | 8 | # Create evaluation results directory if it does not exist. 9 | #mkdir -p "$PROJ_ROOT/evaluated_dataset" 10 | 11 | mkdir -p "$1" 12 | 13 | #echo "$1" 14 | 15 | 16 | 17 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/dmgen/50000 50000 50000 $1 18 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/dmgen/100000 100000 100000 $1 19 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/dmgen/500000 500000 500000 $1 20 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/dmgen/1000000 1000000 1000000 $1 21 | 22 | -------------------------------------------------------------------------------- /eval_scripts/eval-sdk2sdsl-param-A.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 4 | PROJ_ROOT="$DIR/.." 5 | 6 | cd "$PROJ_ROOT" 7 | 8 | IMPLEMENTATION="sdk2sdsl" 9 | 10 | # Create evaluation results directory if it does not exist. 11 | #OUT_DIR="$PROJ_ROOT/evaluated_dataset/$2/$IMPLEMENTATION" 12 | OUT_DIR="$4/$2/$IMPLEMENTATION" 13 | 14 | #echo $OUT_DIR 15 | #exit 0 16 | 17 | mkdir -p $OUT_DIR 18 | 19 | cd $OUT_DIR 20 | 21 | K2TREE_BIN="$PROJ_ROOT/implementations/$IMPLEMENTATION/project" 22 | 23 | STREAMER_BIN="$DIR/streamer.sh" 24 | 25 | printf "\n####################\n" 26 | printf "#################### $IMPLEMENTATION: dynamic (sdsl-lite) k2-tree evaluation: $1/$2\n" 27 | printf "####################\n\n" 28 | 29 | printf "> Results will be written to:\t$OUT_DIR\n\n" 30 | 31 | printf "#########\n" 32 | printf "##### Scenario: additions only (A).\n" 33 | printf "#########\n\n" 34 | 35 | if test -f "$OUT_DIR/$2-$IMPLEMENTATION-A-time.tsv"; then 36 | printf "> $OUT_DIR/$2-$IMPLEMENTATION-A-time.tsv file exists.\n" 37 | else 38 | printf "> Generating $OUT_DIR/$2-$IMPLEMENTATION-A-time.tsv:\n" 39 | printf "/usr/bin/time -v -o $OUT_DIR/$2-$IMPLEMENTATION-A-memory.txt $K2TREE_BIN $3 < <( $STREAMER_BIN $PROJ_ROOT/$1/$2.tsv ) > /dev/null 2> $OUT_DIR/$2-$IMPLEMENTATION-A.err\n" 40 | /usr/bin/time -v -o $OUT_DIR/$2-$IMPLEMENTATION-A-memory.txt $K2TREE_BIN $3 < <( $STREAMER_BIN $PROJ_ROOT/$1/$2.tsv ) > /dev/null 2> $OUT_DIR/$2-$IMPLEMENTATION-A.err ; 41 | 42 | mv ${IMPLEMENTATION}_times.tsv $2-$IMPLEMENTATION-A-time.tsv 43 | #mkdir -p kt-A 44 | mv dktree_serialize/ kt-A/ 45 | fi 46 | -------------------------------------------------------------------------------- /eval_scripts/eval-sdk2sdsl-param-AD.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 4 | PROJ_ROOT="$DIR/.." 5 | 6 | cd "$PROJ_ROOT" 7 | 8 | IMPLEMENTATION="sdk2sdsl" 9 | 10 | # Create evaluation results directory if it does not exist. 11 | #OUT_DIR="$PROJ_ROOT/evaluated_dataset/$2/$IMPLEMENTATION" 12 | OUT_DIR="$4/$2/$IMPLEMENTATION" 13 | 14 | #echo $OUT_DIR 15 | #exit 0 16 | 17 | mkdir -p $OUT_DIR 18 | 19 | cd $OUT_DIR 20 | 21 | K2TREE_BIN="$PROJ_ROOT/implementations/$IMPLEMENTATION/project" 22 | 23 | STREAMER_BIN="$DIR/streamer.sh" 24 | 25 | printf "\n####################\n" 26 | printf "#################### $IMPLEMENTATION: dynamic (sdsl-lite) k2-tree evaluation: $1/$2\n" 27 | printf "####################\n\n" 28 | 29 | printf "> Results will be written to:\t$OUT_DIR\n\n" 30 | 31 | printf "\n#########\n" 32 | printf "##### Scenario: additions + deletions (AD).\n" 33 | printf "#########\n\n" 34 | 35 | if test -f "$OUT_DIR/$2-$IMPLEMENTATION-AD-time.tsv"; then 36 | printf "> $OUT_DIR/$2-$IMPLEMENTATION-AD-time.tsv file exists.\n" 37 | else 38 | printf "> Generating $OUT_DIR/$2-$IMPLEMENTATION-AD-time.tsv:\n" 39 | printf "/usr/bin/time -v -o $OUT_DIR/$2-$IMPLEMENTATION-AD-memory.txt $K2TREE_BIN $3 < <( $STREAMER_BIN $PROJ_ROOT/$1/$2.tsv $PROJ_ROOT/$1/$2-deletions.tsv ) > /dev/null 2> $OUT_DIR/$2-$IMPLEMENTATION-AD.err\n" 40 | /usr/bin/time -v -o $OUT_DIR/$2-$IMPLEMENTATION-AD-memory.txt $K2TREE_BIN $3 < <( $STREAMER_BIN $PROJ_ROOT/$1/$2.tsv $PROJ_ROOT/$1/$2-deletions.tsv ) > /dev/null 2> $OUT_DIR/$2-$IMPLEMENTATION-AD.err ; 41 | 42 | mv ${IMPLEMENTATION}_times.tsv $2-$IMPLEMENTATION-AD-time.tsv 43 | #mkdir -p kt-AD 44 | mv dktree_serialize/ kt-AD/ 45 | fi 46 | -------------------------------------------------------------------------------- /eval_scripts/eval-sdk2sdsl-webgraph-algo-CT-dummy.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 4 | PROJ_ROOT="$DIR/.." 5 | 6 | cd "$PROJ_ROOT" 7 | 8 | # Create evaluation results directory if it does not exist. 9 | #mkdir -p "$PROJ_ROOT/evaluated_dataset" 10 | mkdir -p "$1" 11 | 12 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/webgraph/uk-2007-05@100000 uk-2007-05@100000 100000 $1 CT_dummy 13 | 14 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/webgraph/in-2004 in-2004 1382908 $1 CT_dummy 15 | 16 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/webgraph/uk-2014-host uk-2014-host 4769354 $1 CT_dummy 17 | 18 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/webgraph/indochina-2004 indochina-2004 7414866 $1 CT_dummy 19 | 20 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/webgraph/eu-2015-host eu-2015-host 11264052 $1 CT_dummy -------------------------------------------------------------------------------- /eval_scripts/eval-sdk2sdsl-webgraph-algo.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 4 | PROJ_ROOT="$DIR/.." 5 | 6 | cd "$PROJ_ROOT" 7 | 8 | # Create evaluation results directory if it does not exist. 9 | #mkdir -p "$PROJ_ROOT/evaluated_dataset" 10 | mkdir -p "$1" 11 | 12 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/webgraph/uk-2007-05@100000 uk-2007-05@100000 100000 $1 PR 13 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/webgraph/uk-2007-05@100000 uk-2007-05@100000 100000 $1 BFS 14 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/webgraph/uk-2007-05@100000 uk-2007-05@100000 100000 $1 DFS 15 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/webgraph/uk-2007-05@100000 uk-2007-05@100000 100000 $1 CC 16 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/webgraph/uk-2007-05@100000 uk-2007-05@100000 100000 $1 CT_dummy_hash 17 | 18 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/webgraph/in-2004 in-2004 1382908 $1 PR 19 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/webgraph/in-2004 in-2004 1382908 $1 BFS 20 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/webgraph/in-2004 in-2004 1382908 $1 DFS 21 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/webgraph/in-2004 in-2004 1382908 $1 CC 22 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/webgraph/in-2004 in-2004 1382908 $1 CT_dummy_hash 23 | 24 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/webgraph/uk-2014-host uk-2014-host 4769354 $1 PR 25 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/webgraph/uk-2014-host uk-2014-host 4769354 $1 BFS 26 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/webgraph/uk-2014-host uk-2014-host 4769354 $1 DFS 27 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/webgraph/uk-2014-host uk-2014-host 4769354 $1 CC 28 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/webgraph/uk-2014-host uk-2014-host 4769354 $1 CT_dummy_hash 29 | 30 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/webgraph/indochina-2004 indochina-2004 7414866 $1 PR 31 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/webgraph/indochina-2004 indochina-2004 7414866 $1 BFS 32 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/webgraph/indochina-2004 indochina-2004 7414866 $1 DFS 33 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/webgraph/indochina-2004 indochina-2004 7414866 $1 CC 34 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/webgraph/indochina-2004 indochina-2004 7414866 $1 CT_dummy_hash 35 | 36 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/webgraph/eu-2015-host eu-2015-host 11264052 $1 PR 37 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/webgraph/eu-2015-host eu-2015-host 11264052 $1 BFS 38 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/webgraph/eu-2015-host eu-2015-host 11264052 $1 DFS 39 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/webgraph/eu-2015-host eu-2015-host 11264052 $1 CC 40 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/webgraph/eu-2015-host eu-2015-host 11264052 $1 CT_dummy_hash 41 | -------------------------------------------------------------------------------- /eval_scripts/eval-sdk2sdsl-webgraph.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 4 | PROJ_ROOT="$DIR/.." 5 | 6 | cd "$PROJ_ROOT" 7 | 8 | # Create evaluation results directory if it does not exist. 9 | #mkdir -p "$PROJ_ROOT/evaluated_dataset" 10 | mkdir -p "$1" 11 | 12 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/webgraph/uk-2007-05@100000 uk-2007-05@100000 100000 $1 13 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/webgraph/in-2004 in-2004 1382908 $1 14 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/webgraph/uk-2014-host uk-2014-host 4769354 $1 15 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/webgraph/indochina-2004 indochina-2004 7414866 $1 16 | "$DIR"/eval-sdk2sdsl-param.sh prepared_datasets/webgraph/eu-2015-host eu-2015-host 11264052 $1 17 | -------------------------------------------------------------------------------- /eval_scripts/eval-sdk2tree-all-datasets-A.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 4 | PROJ_ROOT="$DIR/.." 5 | 6 | cd "$PROJ_ROOT" 7 | 8 | # Create evaluation results directory if it does not exist. 9 | #mkdir -p "$PROJ_ROOT/evaluated_dataset" 10 | 11 | mkdir -p "$1" 12 | 13 | #echo "$1" 14 | 15 | 16 | 17 | "$DIR"/eval-sdk2tree-param-A.sh prepared_datasets/dmgen/50000 50000 50000 $1 18 | "$DIR"/eval-sdk2tree-param-A.sh prepared_datasets/dmgen/100000 100000 100000 $1 19 | "$DIR"/eval-sdk2tree-param-A.sh prepared_datasets/dmgen/500000 500000 500000 $1 20 | "$DIR"/eval-sdk2tree-param-A.sh prepared_datasets/dmgen/1000000 1000000 1000000 $1 21 | 22 | "$DIR"/eval-sdk2tree-param-A.sh prepared_datasets/webgraph/uk-2007-05@100000 uk-2007-05@100000 100000 $1 23 | "$DIR"/eval-sdk2tree-param-A.sh prepared_datasets/webgraph/in-2004 in-2004 1382908 $1 24 | "$DIR"/eval-sdk2tree-param-A.sh prepared_datasets/webgraph/uk-2014-host uk-2014-host 4769354 $1 25 | "$DIR"/eval-sdk2tree-param-A.sh prepared_datasets/webgraph/indochina-2004 indochina-2004 7414866 $1 26 | "$DIR"/eval-sdk2tree-param-A.sh prepared_datasets/webgraph/eu-2015-host eu-2015-host 11264052 $1 -------------------------------------------------------------------------------- /eval_scripts/eval-sdk2tree-all-datasets-AD.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 4 | PROJ_ROOT="$DIR/.." 5 | 6 | cd "$PROJ_ROOT" 7 | 8 | # Create evaluation results directory if it does not exist. 9 | #mkdir -p "$PROJ_ROOT/evaluated_dataset" 10 | 11 | mkdir -p "$1" 12 | 13 | #echo "$1" 14 | 15 | 16 | 17 | "$DIR"/eval-sdk2tree-param-AD.sh prepared_datasets/dmgen/50000 50000 50000 $1 18 | "$DIR"/eval-sdk2tree-param-AD.sh prepared_datasets/dmgen/100000 100000 100000 $1 19 | "$DIR"/eval-sdk2tree-param-AD.sh prepared_datasets/dmgen/500000 500000 500000 $1 20 | "$DIR"/eval-sdk2tree-param-AD.sh prepared_datasets/dmgen/1000000 1000000 1000000 $1 21 | 22 | "$DIR"/eval-sdk2tree-param-AD.sh prepared_datasets/webgraph/uk-2007-05@100000 uk-2007-05@100000 100000 $1 23 | "$DIR"/eval-sdk2tree-param-AD.sh prepared_datasets/webgraph/in-2004 in-2004 1382908 $1 24 | "$DIR"/eval-sdk2tree-param-AD.sh prepared_datasets/webgraph/uk-2014-host uk-2014-host 4769354 $1 25 | "$DIR"/eval-sdk2tree-param-AD.sh prepared_datasets/webgraph/indochina-2004 indochina-2004 7414866 $1 26 | "$DIR"/eval-sdk2tree-param-AD.sh prepared_datasets/webgraph/eu-2015-host eu-2015-host 11264052 $1 -------------------------------------------------------------------------------- /eval_scripts/eval-sdk2tree-dmgen.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 4 | PROJ_ROOT="$DIR/.." 5 | 6 | cd "$PROJ_ROOT" 7 | 8 | # Create evaluation results directory if it does not exist. 9 | #mkdir -p "$PROJ_ROOT/evaluated_dataset" 10 | mkdir -p "$1" 11 | 12 | "$DIR"/eval-sdk2tree-param.sh prepared_datasets/dmgen/50000 50000 50000 $1 13 | "$DIR"/eval-sdk2tree-param.sh prepared_datasets/dmgen/100000 100000 100000 $1 14 | "$DIR"/eval-sdk2tree-param.sh prepared_datasets/dmgen/500000 500000 500000 $1 15 | "$DIR"/eval-sdk2tree-param.sh prepared_datasets/dmgen/1000000 1000000 1000000 $1 16 | 17 | -------------------------------------------------------------------------------- /eval_scripts/eval-sdk2tree-param-A.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 4 | PROJ_ROOT="$DIR/.." 5 | 6 | cd "$PROJ_ROOT" 7 | 8 | IMPLEMENTATION="sdk2tree" 9 | 10 | # Create evaluation results directory if it does not exist. 11 | #OUT_DIR="$PROJ_ROOT/evaluated_dataset/$2/$IMPLEMENTATION" 12 | OUT_DIR="$4/$2/$IMPLEMENTATION" 13 | mkdir -p $OUT_DIR 14 | 15 | cd $OUT_DIR 16 | 17 | K2TREE_BIN="$PROJ_ROOT/implementations/$IMPLEMENTATION/project" 18 | 19 | STREAMER_BIN="$DIR/streamer.sh" 20 | 21 | printf "####################\n" 22 | printf "#################### $IMPLEMENTATION: dynamic (INESC-ID) collection dynamization k2-tree evaluation: $1/$2\n" 23 | printf "####################\n\n" 24 | 25 | printf "> Results will be written to:\t$OUT_DIR\n\n" 26 | 27 | printf "\n#########\n" 28 | printf "##### Scenario: additions only (A).\n" 29 | printf "#########\n\n" 30 | 31 | # if test -f "$OUT_DIR/$2-$IMPLEMENTATION-A-time.tsv"; then 32 | # printf "> $OUT_DIR/$2-$IMPLEMENTATION-A-time.tsv file exists.\n" 33 | # else 34 | # printf "> Generating $OUT_DIR/$2-$IMPLEMENTATION-A-time.tsv:\n" 35 | # printf "/usr/bin/time -v -o $OUT_DIR/$2-$IMPLEMENTATION-A-memory.txt $K2TREE_BIN $3 < <( $STREAMER_BIN $PROJ_ROOT/$1/$2.tsv ) > /dev/null 2> $OUT_DIR/$2-$IMPLEMENTATION-A.err\n" 36 | # /usr/bin/time -v -o $OUT_DIR/$2-$IMPLEMENTATION-A-memory.txt $K2TREE_BIN $3 < <( $STREAMER_BIN $PROJ_ROOT/$1/$2.tsv ) > /dev/null 2> $OUT_DIR/$2-$IMPLEMENTATION-A.err ; 37 | 38 | # mv ${IMPLEMENTATION}_times.tsv $2-$IMPLEMENTATION-A-time.tsv 39 | # mkdir -p kt-A 40 | # mv *.kt kt-A/ 41 | # fi 42 | 43 | 44 | if test -f "$2-$IMPLEMENTATION-A-time.tsv"; then 45 | printf "> $2-$IMPLEMENTATION-A-time.tsv file exists.\n" 46 | else 47 | printf "> Generating $OUT_DIR/$2-$IMPLEMENTATION-A-time.tsv:\n" 48 | printf "/usr/bin/time -v -o $2-$IMPLEMENTATION-A-memory.txt $K2TREE_BIN $3 < <( $STREAMER_BIN $PROJ_ROOT/$1/$2.tsv ) > /dev/null 2> $2-$IMPLEMENTATION-A.err\n" 49 | /usr/bin/time -v -o $2-$IMPLEMENTATION-A-memory.txt $K2TREE_BIN $3 < <( $STREAMER_BIN $PROJ_ROOT/$1/$2.tsv ) > /dev/null 2> $2-$IMPLEMENTATION-A.err ; 50 | 51 | mv ${IMPLEMENTATION}_times.tsv $2-$IMPLEMENTATION-A-time.tsv 52 | mkdir -p kt-A 53 | mv *.kt kt-A/ 54 | fi -------------------------------------------------------------------------------- /eval_scripts/eval-sdk2tree-param-AD.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 4 | PROJ_ROOT="$DIR/.." 5 | 6 | cd "$PROJ_ROOT" 7 | 8 | IMPLEMENTATION="sdk2tree" 9 | 10 | # Create evaluation results directory if it does not exist. 11 | #OUT_DIR="$PROJ_ROOT/evaluated_dataset/$2/$IMPLEMENTATION" 12 | OUT_DIR="$4/$2/$IMPLEMENTATION" 13 | mkdir -p $OUT_DIR 14 | 15 | cd $OUT_DIR 16 | 17 | K2TREE_BIN="$PROJ_ROOT/implementations/$IMPLEMENTATION/project" 18 | 19 | STREAMER_BIN="$DIR/streamer.sh" 20 | 21 | printf "####################\n" 22 | printf "#################### $IMPLEMENTATION: dynamic (INESC-ID) collection dynamization k2-tree evaluation: $1/$2\n" 23 | printf "####################\n\n" 24 | 25 | printf "> Results will be written to:\t$OUT_DIR\n\n" 26 | 27 | printf "\n#########\n" 28 | printf "##### Scenario: additions + deletions (AD).\n" 29 | printf "#########\n\n" 30 | 31 | if test -f "$OUT_DIR/$2-$IMPLEMENTATION-AD-time.tsv"; then 32 | printf "> $OUT_DIR/$2-$IMPLEMENTATION-AD-time.tsv file exists.\n" 33 | else 34 | printf "> Generating $OUT_DIR/$2-$IMPLEMENTATION-AD-time.tsv:\n" 35 | printf "/usr/bin/time -v -o $OUT_DIR/$2-$IMPLEMENTATION-AD-memory.txt $K2TREE_BIN $3 < <( $STREAMER_BIN $PROJ_ROOT/$1/$2.tsv $PROJ_ROOT/$1/$2-deletions.tsv ) > /dev/null 2> $OUT_DIR/$2-$IMPLEMENTATION-AD.err\n" 36 | /usr/bin/time -v -o $OUT_DIR/$2-$IMPLEMENTATION-AD-memory.txt $K2TREE_BIN $3 < <( $STREAMER_BIN $PROJ_ROOT/$1/$2.tsv $PROJ_ROOT/$1/$2-deletions.tsv ) > /dev/null 2> $OUT_DIR/$2-$IMPLEMENTATION-AD.err ; 37 | 38 | mv ${IMPLEMENTATION}_times.tsv $2-$IMPLEMENTATION-AD-time.tsv 39 | mkdir -p kt-AD 40 | mv *.kt kt-AD/ 41 | fi 42 | -------------------------------------------------------------------------------- /eval_scripts/eval-sdk2tree-webgraph.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 4 | PROJ_ROOT="$DIR/.." 5 | 6 | cd "$PROJ_ROOT" 7 | 8 | # Create evaluation results directory if it does not exist. 9 | #mkdir -p "$PROJ_ROOT/evaluated_dataset" 10 | mkdir -p "$1" 11 | 12 | "$DIR"/eval-sdk2tree-param.sh prepared_datasets/webgraph/uk-2007-05@100000 uk-2007-05@100000 100000 $1 13 | "$DIR"/eval-sdk2tree-param.sh prepared_datasets/webgraph/in-2004 in-2004 1382908 $1 14 | "$DIR"/eval-sdk2tree-param.sh prepared_datasets/webgraph/uk-2014-host uk-2014-host 4769354 $1 15 | "$DIR"/eval-sdk2tree-param.sh prepared_datasets/webgraph/indochina-2004 indochina-2004 7414866 $1 16 | "$DIR"/eval-sdk2tree-param.sh prepared_datasets/webgraph/eu-2015-host eu-2015-host 11264052 $1 17 | -------------------------------------------------------------------------------- /eval_scripts/gnuplot-templates/gp-sdk2sdsl-ALGO-TEST.gnuplot: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env gnuplot 2 | 3 | ################################# 4 | ################################# Dataset: DMGEN 5 | ################################# 6 | set terminal pdfcairo mono font "sans, 16" 7 | set output 'sdk2sdsl-TEST_CASE-STAT-dmgen.pdf' 8 | set title 'TEST_NAME (DM)' 9 | 10 | set key left top 11 | set grid 12 | set xlabel 'X_UNIT' 13 | set ylabel 'Y_UNIT' 14 | set format '%g' 15 | set style data linespoints 16 | set xrange [150:] 17 | #set xtics 0,INCR,MAX 18 | 19 | #set DMGEN-xtics 0,INCR,MAX 20 | ##### Black and white version. 21 | 22 | 23 | plot 'sdk2sdsl-TEST_CASE-STAT-dmgen.tsv' using (X_FORMULA):($4*MULTIPLIER) pt 4 title 'sdk2sdsl' 24 | 25 | ##### Colored version. 26 | 27 | set style increment user 28 | # Color pallete parula: http://www.gnuplotting.org/data/parula.pal 29 | set style line 1 lt 1 lc rgb '#0072bd' # blue 30 | set style line 2 lt 1 lc rgb '#d95319' # orange 31 | set style line 3 lt 1 lc rgb '#edb120' # yellow 32 | set style line 4 lt 1 lc rgb '#7e2f8e' # purple 33 | set style line 5 lt 1 lc rgb '#77ac30' # green 34 | set style line 6 lt 1 lc rgb '#4dbeee' # light-blue 35 | set style line 7 lt 1 lc rgb '#a2142f' # red 36 | set terminal pdfcairo color font "sans, 16" 37 | set output 'sdk2sdsl-TEST_CASE-STAT-dmgen_colorized.pdf' 38 | replot 39 | 40 | ################################# 41 | ################################# Dataset: WEBGRAPH 42 | ################################# 43 | 44 | set key left top 45 | set grid 46 | set xlabel 'X_UNIT' 47 | set ylabel 'Y_UNIT' 48 | set format '%g' 49 | set style data linespoints 50 | set xrange [150:] 51 | #set xtics 0,INCR,MAX 52 | 53 | set terminal pdfcairo mono font "sans, 16" 54 | set output 'sdk2sdsl-TEST_CASE-STAT-webgraph.pdf' 55 | set title 'TEST_NAME (REAL)' 56 | 57 | #set WEBGRAPH-xtics 0,INCR,MAX 58 | 59 | ##### Black and white version. 60 | 61 | plot 'sdk2sdsl-TEST_CASE-STAT-webgraph.tsv' using (X_FORMULA):($4*MULTIPLIER) pt 4 title 'sdk2sdsl' 62 | 63 | ##### Colored version. 64 | 65 | set style increment user 66 | # Color pallete parula: http://www.gnuplotting.org/data/parula.pal 67 | set style line 1 lt 1 lc rgb '#0072bd' # blue 68 | set style line 2 lt 1 lc rgb '#d95319' # orange 69 | set style line 3 lt 1 lc rgb '#edb120' # yellow 70 | set style line 4 lt 1 lc rgb '#7e2f8e' # purple 71 | set style line 5 lt 1 lc rgb '#77ac30' # green 72 | set style line 6 lt 1 lc rgb '#4dbeee' # light-blue 73 | set style line 7 lt 1 lc rgb '#a2142f' # red 74 | set terminal pdfcairo color font "sans, 16" 75 | set output 'sdk2sdsl-TEST_CASE-STAT-webgraph_colorized.pdf' 76 | replot 77 | 78 | quit 79 | 80 | -------------------------------------------------------------------------------- /eval_scripts/run-all.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 4 | PROJ_ROOT="$DIR/.." 5 | 6 | cd "$PROJ_ROOT" 7 | 8 | "$DIR"/eval-dk2tree-dmgen.sh $1 9 | "$DIR"/eval-dk2tree-webgraph.sh $1 10 | 11 | "$DIR"/eval-k2sdsl-dmgen.sh $1 12 | "$DIR"/eval-k2sdsl-webgraph.sh $1 13 | 14 | "$DIR"/eval-k2tree-dmgen.sh $1 15 | "$DIR"/eval-k2tree-webgraph.sh $1 16 | 17 | "$DIR"/eval-k2trie-dmgen.sh $1 18 | "$DIR"/eval-k2trie-webgraph.sh $1 19 | 20 | "$DIR"/eval-sdk2tree-dmgen.sh $1 21 | "$DIR"/eval-sdk2tree-webgraph.sh $1 22 | -------------------------------------------------------------------------------- /eval_scripts/run-k2sdsl-algos.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 4 | PROJ_ROOT="$DIR/.." 5 | 6 | cd "$PROJ_ROOT" 7 | 8 | "$DIR"/eval-k2sdsl-dmgen-algo.sh $1 9 | "$DIR"/eval-k2sdsl-webgraph-algo.sh $1 -------------------------------------------------------------------------------- /eval_scripts/streamer.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | 4 | run_algo="false" 5 | 6 | algo="none" 7 | 8 | ctr=0 9 | for algo in "$@"; do 10 | let "ctr+=1" 11 | done 12 | 13 | case $algo in 14 | PR|BFS|DFS|CC|CT_dummy|CT_dummy_hash) 15 | run_algo="true" ;; 16 | *) 17 | true ;; 18 | esac 19 | 20 | #echo "$ctr" 21 | 22 | #exit 0 23 | 24 | for var in "$@"; do 25 | case $var in 26 | PR|BFS|DFS|CC|CT_dummy|CT_dummy_hash) 27 | echo "e $var" ;; 28 | *) 29 | cat "$var" ;; 30 | esac 31 | #if [[ "$var" == "$algo" ]]; then 32 | # echo "e $algo" 33 | #else 34 | # cat "$var" 35 | #fi 36 | echo "s" 37 | echo "saving_file_$ctr" 38 | ctr=$((ctr+1)) 39 | done 40 | 41 | echo "x" 42 | 43 | -------------------------------------------------------------------------------- /img/citic_logo.JPEG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aplf/sdk2tree/c86a1df6b0a8ea3d40bc9799472da3db201ba53a/img/citic_logo.JPEG -------------------------------------------------------------------------------- /img/enxenio_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aplf/sdk2tree/c86a1df6b0a8ea3d40bc9799472da3db201ba53a/img/enxenio_logo.png -------------------------------------------------------------------------------- /img/inesc-id_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aplf/sdk2tree/c86a1df6b0a8ea3d40bc9799472da3db201ba53a/img/inesc-id_logo.png -------------------------------------------------------------------------------- /img/ist_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aplf/sdk2tree/c86a1df6b0a8ea3d40bc9799472da3db201ba53a/img/ist_logo.png -------------------------------------------------------------------------------- /implementations/Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: 3 | cd k2tree && make all 4 | cd dk2tree && make all 5 | cd k2trie && make all 6 | cd sdk2tree && make all 7 | cd k2sdsl && make all 8 | 9 | debug: 10 | cd k2tree && make debug 11 | cd dk2tree && make debug 12 | cd k2trie && make debug 13 | cd sdk2tree && make debug 14 | cd k2sdsl && make debug 15 | 16 | clean: 17 | cd k2tree && make clean 18 | cd dk2tree && make clean 19 | cd k2trie && make clean 20 | cd sdk2tree && make clean 21 | cd k2sdsl && make clean -------------------------------------------------------------------------------- /implementations/dk2tree/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | 3 | *.exe 4 | 5 | testRange 6 | testRebuild 7 | testGraph 8 | testLoad 9 | testLoadFile 10 | testInsert 11 | testNeighbors 12 | testRebuild 13 | optimize 14 | project 15 | 16 | 17 | k2tree.a 18 | -------------------------------------------------------------------------------- /implementations/dk2tree/DynamicSequence.c: -------------------------------------------------------------------------------- 1 | #include "DynamicSequence.h" 2 | 3 | 4 | uint nIntsInternalEntry[] = {2, 3}; 5 | uint nBitsInternalEntry[] = {64, 96}; 6 | 7 | DynamicSequenceRank DSRCreateEmpty(NodeManager *manager, byte rank) { 8 | DynamicSequenceRank bs = (DynamicSequenceRank) malloc(sizeof(sDynamicSequenceRank)); 9 | bs->mgr = manager; 10 | Node * node = allocateNode(mgr); 11 | bs->root = node->bid; 12 | bs->curSize = 0L; 13 | bs->rank = rank; 14 | return bs; 15 | } 16 | 17 | 18 | 19 | //ull DSRRank1(DynamicSequenceRank bs, ull pos) { 20 | // return -1L; 21 | //} 22 | // 23 | //ull DSRRank0(DynamicSequenceRank bs, ull pos) { 24 | // return pos - DBSRRank1(bs, pos); 25 | //} 26 | // 27 | //ull DSRSelect1(DynamicSequenceRank bs, ull ones) { 28 | // return -1L; 29 | //} 30 | // 31 | //ull DSRSelect0(DynamicSequenceRank bs, ull zeros) { 32 | // return -1L; 33 | //} 34 | // 35 | //ull DSRAccess(DynamicSequenceRank bs, ull pos) { 36 | // return -1L; 37 | //} 38 | // 39 | //void DSRInsert(DynamicSequenceRank bs, ull pos, uint * data, ull len) { 40 | // goToLeaf(bs, pos, 1); 41 | // 42 | //} 43 | // 44 | //void DSRDelete(DynamicSequenceRank bs, ull pos, ull len) { 45 | // 46 | //} 47 | // 48 | //void DSRReplace(DynamicSequenceRank bs, ull pos, uint * data, ull len) { 49 | // 50 | //} 51 | 52 | //DynamicSequence DBSCreateEmpty(uint (*fun(void *))); 53 | //DynamicSequence DBSCreate(uint * bits, ull length, uint blockSize, uint njumps, uint (*fun(void *))); 54 | //ull DBSAccess(DynamicSequence bs, ull pos); 55 | //void DBSInsert(DynamicSequence bs, ull pos, uint * data, ull len); 56 | //void DBSDelete(DynamicSequence bs, ull pos, ull len); 57 | //void DBSReplace(DynamicSequenceRank bs, ull pos, uint * data, ull len); 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /implementations/dk2tree/DynamicSequence.h: -------------------------------------------------------------------------------- 1 | #include "nodeManager.h" 2 | 3 | typedef uint * DSBlock; 4 | 5 | extern uint nIntsInternalEntry[]; 6 | extern uint nBitsInternalEntry[]; 7 | 8 | #define MAX_DEPTH 17 9 | 10 | typedef struct sDynamicSequence { 11 | ull curSize; 12 | BID root; 13 | uint depth; 14 | NodeManager *nodeManager; 15 | // uint *(*changeLeaf(Node *leaf, uint * newData, uint newDataSize, uint oldDataSize)); 16 | // uint (*splitLeaf(uint *data, uint dataSize, uint **leaf1, uint * leaf1Size, uint **leaf2, uint * leaf2Size)); 17 | // uint (*mergeLeaf(uint * data1, uint dataSize1, uint *data2, uint dataSize2, uint **mergeLeaf, uint * mergeLeafSize)); 18 | Node *path[MAX_DEPTH]; 19 | uint offsets[MAX_DEPTH]; 20 | ull acumOnes[MAX_DEPTH]; 21 | ull initSize[MAX_DEPTH]; 22 | ull maxSize[MAX_DEPTH]; 23 | byte rank; 24 | } *DynamicSequence; 25 | 26 | typedef struct sDynamicSequenceRank { 27 | ull curSize; 28 | ull curOnes; 29 | BID root; 30 | uint depth; 31 | NodeManager *mgr; 32 | // uint *(*changeLeaf(uint *leafData, uint leafSize, uint * newData, uint newDataSize, uint oldDataSize)); 33 | // uint (*splitLeaf(uint *data, uint dataSize, uint **leaf1, uint * leaf1Size, uint **leaf2, uint * leaf2Size)); 34 | // uint (*mergeLeaf(uint * data1, uint dataSize1, uint *data2, uint dataSize2, uint **mergeLeaf, uint * mergeLeafSize)); 35 | Node *path[MAX_DEPTH]; 36 | uint offsets[MAX_DEPTH]; 37 | ull acumOnes[MAX_DEPTH]; 38 | ull initPosLevel[MAX_DEPTH]; 39 | ull maxPosLevel[MAX_DEPTH]; 40 | byte rank; 41 | } *DynamicSequenceRank; 42 | 43 | 44 | DynamicSequenceRank DSRCreateEmpty(uint blockSize, uint njumps, uint *(*changeLeaf(uint *, uint, uint *, uint, uint)), 45 | uint (*splitLeaf(uint *, uint, uint **, uint *, uint **, uint *)), 46 | uint *(mergeLeaf(uint *, uint, uint *, uint, uint **, uint *))); 47 | //ull DSRRank1(DynamicSequenceRank bs, ull pos); 48 | //ull DSRRank0(DynamicSequenceRank bs, ull pos); 49 | //ull DRSelect1(DynamicSequenceRank bs, ull ones); 50 | //ull DBSRSelect0(DynamicSequenceRank bs, ull ones); 51 | //ull DSRAccess(DynamicSequenceRank bs, ull pos); 52 | //void DSRInsert(DynamicSequenceRank bs, ull pos, uint * data, ull len); 53 | //void DSRDelete(DynamicSequenceRank bs, ull pos, ull len); 54 | //void DSRReplace(DynamicSequenceRank bs, ull pos, uint * data, ull len); 55 | 56 | //DynamicBitmap DBSCreateEmpty(); 57 | //ull DBSAccess(DynamicBitmap bs, ull pos); 58 | //void DBSInsert(DynamicBitmap bs, ull pos, uint * data, ull len); 59 | //void DBSDelete(DynamicBitmap bs, ull pos, ull len); 60 | //void DBSReplace(DynamicBitmap bs, ull pos, uint * data, ull len); 61 | 62 | -------------------------------------------------------------------------------- /implementations/dk2tree/Makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | 3 | #MACHINE_FLAGS=-mpopcnt 4 | 5 | CACHE=mem 6 | 7 | BINS=testGraph testLoad testLoadFile testInsert testNeighbors testRebuild testRange project 8 | 9 | K2TREE=k2tree.a 10 | 11 | ifeq ($(CACHE),mem) 12 | OBJECTS=basic.o encoding.o util.o nodeManager-mem-complete.o k2tree-common.o k2tree-operations.o k2tree-impl.o hash.o MemoryManager.o vocUtils.o 13 | DEFS=-DMEMCACHE 14 | else 15 | OBJECTS=basic.o encoding.o util.o nodeManager-disk-complete.o k2tree-common.o k2tree-operations.o k2tree-impl.o hash.o MemoryManager.o vocUtils.o 16 | DEFS=-DRANDOMCACHE 17 | endif 18 | 19 | # ifeq ($(CACHE), mem) 20 | # DEFS=-DMEMCACHE 21 | # else 22 | # DEFS=-DRANDOMCACHE 23 | # endif 24 | 25 | CCFLAGS=-Wall -O9 $(MACHINE_FLAGS) $(DEFS) $(CUSTOM) -DNDEBUG 26 | 27 | # How to check the invoking target when calling make: 28 | # https://www.gnu.org/software/make/manual/html_node/Goals.html 29 | ifeq ($(MAKECMDGOALS),debug) 30 | CCFLAGS=-Wall -g $(MACHINE_FLAGS) $(DEFS) $(CUSTOM) -DDEBUGGING #-std=gnu89 #-std=gnu11 31 | endif 32 | 33 | 34 | %.o: %.c 35 | $(CC) $(CCFLAGS) -c $< -o $@ 36 | 37 | all: clean bin 38 | 39 | debug: clean bin 40 | 41 | archive: $(OBJECTS) 42 | ar rc $(K2TREE) $(OBJECTS) 43 | 44 | bin: archive $(BINS) 45 | 46 | project: archive 47 | $(CC) $(CCFLAGS) -o project main.c $(K2TREE) -lm 48 | 49 | testGraph: archive 50 | $(CC) $(CCFLAGS) -o testGraph testCreateFromGraph.c $(K2TREE) -lm 51 | 52 | testLoad: archive 53 | $(CC) $(CCFLAGS) -o testLoad testLoad.c $(K2TREE) -lm 54 | 55 | testLoadFile: archive 56 | $(CC) $(CCFLAGS) -o testLoadFile testLoadFromFile.c $(K2TREE) -lm 57 | 58 | testInsert: archive 59 | $(CC) $(CCFLAGS) -o testInsert testInsert.c $(K2TREE) -lm 60 | 61 | testNeighbors: archive 62 | $(CC) $(CCFLAGS) -o testNeighbors testNeighbors.c $(K2TREE) -lm 63 | 64 | testRebuild: archive 65 | $(CC) $(CCFLAGS) -o testRebuild testRebuild.c $(K2TREE) -lm 66 | 67 | testRange: archive 68 | $(CC) $(CCFLAGS) -o testRange testRange.c $(K2TREE) -lm 69 | 70 | clean: 71 | rm -f *.o *.a $(BINS) $(OBJECTS) 72 | -------------------------------------------------------------------------------- /implementations/dk2tree/MemoryManager.h: -------------------------------------------------------------------------------- 1 | /* Searches using text compressed and indexed with WTDC. 2 | 3 | Programmed by Susana Ladra. 4 | 5 | Author's contact: Susana Ladra, Databases Lab, University of 6 | A Coruna. Campus de Elvina s/n. Spain sladra@udc.es 7 | 8 | Copyright (C) 2006 Nieves R. Brisaboa, Antonio Farina and Susana Ladra 9 | Author's contact: asusanaladra@gmail.com 10 | 11 | This program is free software; you can redistribute it and/or 12 | modify it under the terms of the GNU General Public License 13 | as published by the Free Software Foundation; either version 2 14 | of the License, or (at your option) any later version. 15 | 16 | This program is distributed in the hope that it will be useful, 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | GNU General Public License for more details. 20 | 21 | You should have received a copy of the GNU General Public License 22 | along with this program; if not, write to the Free Software 23 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 24 | */ 25 | 26 | /*----------------------------------------------------------------------- 27 | MemoryManager.h: Purpose : Improve hash performance. 28 | Reserves large blocks of memory and gives pointers to small portions of that block 29 | when requested. This improves performance since a unique "LARGE ALLOCATION" 30 | of memory is needed (a unique call to malloc). It is also responsible of freeing memory. 31 | ------------------------------------------------------------------------*/ 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #include 39 | 40 | #ifndef DEFBYTE 41 | #define byte unsigned char 42 | #define DEFBYTE 43 | #endif 44 | 45 | #define LARGE_BLOCK_SIZE 10485760 /* Size of the blocks of memory that will be allocated*/ 46 | #define MAX_BLOCKS 128 /* Maximum number of blocks of size LARGE_BLOCK_SIZE that*/ 47 | /* can be allocated*/ 48 | 49 | /* 50 | * Definition of structure MemoryManager 51 | */ 52 | struct sMem { 53 | byte *BLOCKS[MAX_BLOCKS]; /*array of blocks of size LARGE_BLOCK_SIZE*/ 54 | unsigned int currentBlock; /*currentBlock in the array of blocks*/ 55 | unsigned long remainderBytes; /*number of bytes not yet assigned in BLOCKS[currentBlock]*/ 56 | byte *availableByte; /*pointer to next byte not yet assigned*/ 57 | }; 58 | 59 | typedef struct sMem *MemoryManager; 60 | 61 | MemoryManager createMemoryManager(void); 62 | void destroyMemoryManager(MemoryManager mm); 63 | void getMemoryBlock(MemoryManager mm, byte **dst, const unsigned int size); 64 | void createNewMemoryBlock(MemoryManager mm); 65 | 66 | unsigned int getMemoryUsage(MemoryManager mm); 67 | 68 | -------------------------------------------------------------------------------- /implementations/dk2tree/README.md: -------------------------------------------------------------------------------- 1 | # dk2tree graph data structure 2 | 3 | ## Description 4 | 5 | This directory contains the source-code of the **dk2tree**, the dynamic *k*2-tree structure based on bit vectors and described in the paper [Compressed representation of dynamic binary relations with applications](https://doi.org/10.1016/j.is.2017.05.003), 6 | by Nieves R. Brisaboa, Ana Cerdeira-Pena, Guillermo de Bernardo and Gonzalo Navarro (2017). 7 | 8 | ## Usage examples 9 | 10 | make 11 | ./project dataset 9 512 4 4 3 2 < ../../datasets/dataset-adds-lists.tsv 12 | 13 | > Running dynamic k2tree (UPC). 14 | > Finished parsing arguments. 15 | > Got kValues. 16 | > Created empty K2Tree. 17 | > K2Tree stack initiated. 18 | > Initial K2Tree info: 19 | N[0] ->2 20 | N[1] ->2 21 | N[2] ->1 22 | N[3] ->1 23 | N[4] ->1 24 | N[5] ->2 25 | N[6] ->1 26 | N[7] ->1 27 | N[8] ->0 28 | manager 0 2 blocks 29 | manager 1 0 blocks 30 | manager 2 0 blocks 31 | manager 3 0 blocks 32 | [INFO ][nodeManager-mem-complete.c:310]: sizes 545208 1024 33 | [INFO ][k2tree-common.c:1018]: mgr: 550328 34 | Memory usage : 550328 35 | Disk usage : 1824 36 | Destroying node manager.Creation time = -nan 37 | > Exiting. 38 | Loop time: 505.000000 39 | 40 | #### Argument info: 41 | # dataset - base name of the tested file. 42 | # 9 - number of vertices 43 | # 512 - block size 44 | # 4 - n-jumps 45 | # 4 - k-value 46 | # 3 - n-levels 47 | # 2 - last-k-value 48 | ## For more information on these parameters, check 49 | ## [Compressed representation of dynamic binary relations with applications] 50 | ## (https://doi.org/10.1016/j.is.2017.05.003) 51 | # ../../datasets/dataset-adds-lists.tsv - path to a graph operations file with 52 | edge additions followed by listings 53 | -------------------------------------------------------------------------------- /implementations/dk2tree/basic.h: -------------------------------------------------------------------------------- 1 | #ifndef BASICSINCLUDED 2 | #define BASICSINCLUDED 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | 11 | /* basics.h 12 | Copyright (C) 2005, Rodrigo Gonzalez, all rights reserved. 13 | 14 | Some preliminary stuff 15 | 16 | This library is free software; you can redistribute it and/or 17 | modify it under the terms of the GNU Lesser General Public 18 | License as published by the Free Software Foundation; either 19 | version 2.1 of the License, or (at your option) any later version. 20 | 21 | This library is distributed in the hope that it will be useful, 22 | but WITHOUT ANY WARRANTY; without even the implied warranty of 23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 24 | Lesser General Public License for more details. 25 | 26 | You should have received a copy of the GNU Lesser General Public 27 | License along with this library; if not, write to the Free Software 28 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 29 | 30 | */ 31 | 32 | 33 | 34 | #define mask31 0x0000001F 35 | 36 | #define max(x,y) ((x)>(y)?(x):(y)) 37 | #define min(x,y) ((x)<(y)?(x):(y)) 38 | 39 | /*numero de bits del entero de la maquina*/ 40 | #define W 32 41 | /* W-1 */ 42 | #define Wminusone 31 43 | /*numero de bits del entero de la maquina*/ 44 | #define WW 64 45 | /*bits para hacer la mascara para contar mas rapido*/ 46 | #define bitsM 8 47 | /*bytes que hacen una palabra */ 48 | #define BW 4 49 | #ifndef uchar 50 | #define uchar unsigned char 51 | #endif 52 | #ifndef uint 53 | #define uint unsigned int 54 | #endif 55 | #ifndef ulong 56 | #define ulong unsigned long 57 | #endif 58 | #define size_uchar 256 59 | 60 | #ifndef byte 61 | #define byte unsigned char 62 | #endif 63 | 64 | /* reads bit p from e */ 65 | #define bitgetchar(e,p) ((((e)[(p)/bitsM] >> ((p)%bitsM))) & 1) 66 | /* sets bit p in e */ 67 | #define bitsetchar(e,p) ((e)[(p)/bitsM] |= (1<<((p)%bitsM))) 68 | /* cleans bit p in e */ 69 | #define bitcleanchar(e,p) ((e)[(p)/bitsM] &= ~(1<<((p)%bitsM))) 70 | 71 | 72 | /* reads bit p from e */ 73 | #define bitget(e,p) ((((e)[(p)/W] >> ((p)%W))) & 1) 74 | /* sets bit p in e */ 75 | #define bitset(e,p) ((e)[(p)/W] |= (1<<((p)%W))) 76 | /* cleans bit p in e */ 77 | #define bitclean(e,p) ((e)[(p)/W] &= ~(1<<((p)%W))) 78 | 79 | /* numero de enteros necesarios para representar e elementos de largo n */ 80 | #define enteros(e,n) ((e)*(n))/W+(((e)*(n))%W > 0) 81 | /* bits needed to represent a number between 0 and n */ 82 | uint bits (uint n); 83 | 84 | 85 | 86 | uint GetField(uint *A, register uint len, register uint index); 87 | void SetField(uint *A,register uint len, register uint index,register uint x); 88 | 89 | 90 | uint GetVarField(uint *A, register uint ini, register uint fin); 91 | 92 | void SetVarField(uint *A,register uint ini, register uint fin,register uint x); 93 | 94 | unsigned GetFieldW32(uint *A,register uint index); 95 | 96 | 97 | void SetField32(uint *A, register uint index,register uint x) ; 98 | 99 | unsigned GetFieldW16(uint *A,register uint index); 100 | unsigned GetFieldW4(uint *A,register uint index) ; 101 | 102 | uint popcount (register int x); 103 | 104 | uint popcount16 (register int x); 105 | 106 | uint popcount8 (register int x); 107 | 108 | #endif 109 | -------------------------------------------------------------------------------- /implementations/dk2tree/comp.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define MAX 100000000 5 | 6 | int main(int argc, char **argv) { 7 | if (argc != 3) { 8 | exit(-1); 9 | } 10 | FILE * f1 = fopen(argv[1], "r"); 11 | FILE * f2 = fopen(argv[2], "r"); 12 | 13 | int size1, size2; 14 | 15 | int * buf1 = (uint *) malloc (MAX * sizeof(uint)); 16 | int * buf2 = (uint *) malloc (MAX * sizeof(uint)); 17 | 18 | int elem1, elem2; 19 | int iter = 0; 20 | do { 21 | printf("iter %d\n", iter); 22 | size1 = fread(buf1, sizeof(uint), MAX, f1); 23 | size2 = fread(buf2, sizeof(uint), MAX, f2); 24 | int i; 25 | for (i = 0; i < size1; i++) { 26 | elem1 = buf1[i]; 27 | elem2 = buf2[i]; 28 | if (elem1 < 0 && elem1 != elem2) printf("different - at iter %d pos %d\n", iter, i); 29 | if (elem1 >= 0 && elem1 != elem2-1) printf("different + at iter %d pos %d : %d VS %d\n", iter, i, elem1, elem2); 30 | } 31 | iter ++; 32 | } while (size1 > 0); 33 | 34 | exit(0); 35 | 36 | 37 | 38 | } 39 | 40 | 41 | -------------------------------------------------------------------------------- /implementations/dk2tree/debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | * debug.h 3 | * 4 | * Created on: 17/12/2012 5 | * Author: guillermo 6 | * 7 | * Utils for debugging code: 8 | * - Simple log facade 9 | * - Simple ASSERT macro to provide assert with optional messages 10 | * - Macros CHECK and CHECKT to print values only when debugging 11 | * 12 | * Macros are based on gcc constructs. 13 | * 14 | */ 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | #ifndef DEBUG_H_ 21 | #define DEBUG_H_ 22 | 23 | #define L_NEVER 0 24 | #define L_ERROR 1 25 | #define L_WARN 2 26 | #define L_INFO 3 27 | #define L_DEBUG 4 28 | #define L_TRACE 5 29 | #define L_ALL 10 30 | 31 | #define LOGLEVEL L_INFO 32 | 33 | #ifndef LOGLEVEL 34 | #ifdef NDEBUG 35 | #define LOGLEVEL L_INFO 36 | #else 37 | #define LOGLEVEL L_TRACE 38 | #endif 39 | #endif 40 | 41 | 42 | 43 | #define WHERESTR "[%s:%d]: " 44 | #define WHEREARG __FILE__, __LINE__ 45 | 46 | #define MYPRINT(fmt, where, ...) do{fprintf(stdout, fmt, where, ##__VA_ARGS__);fflush(stdout);}while(0) 47 | #define MYPRINTERR(fmt, where, ...) do{fprintf(stderr, fmt, where, ##__VA_ARGS__);fflush(stderr);}while(0) 48 | 49 | #if LOGLEVEL >= L_TRACE 50 | #define TRACE(_fmt, ...) MYPRINT("[TRACE]" WHERESTR _fmt, WHEREARG, __VA_ARGS__) 51 | #endif 52 | 53 | #if LOGLEVEL >= L_DEBUG 54 | #define DEBUG(_fmt, ...) MYPRINT("[DEBUG]" WHERESTR _fmt, WHEREARG, ##__VA_ARGS__) 55 | #endif 56 | 57 | #if LOGLEVEL >= L_INFO 58 | #define INFO(_fmt, ...) MYPRINT("[INFO ]" WHERESTR _fmt, WHEREARG, ##__VA_ARGS__) 59 | #endif 60 | 61 | #if LOGLEVEL >= L_WARN 62 | #define WARN(_fmt, ...) MYPRINT("[WARN ]" WHERESTR _fmt, WHEREARG, ##__VA_ARGS__) 63 | #endif 64 | 65 | #if LOGLEVEL >= L_ERROR 66 | #define ERROR(_fmt, ...) MYPRINTERR("[ERROR]" WHERESTR _fmt, WHEREARG, ##__VA_ARGS__) 67 | #endif 68 | 69 | #if LOGLEVEL >= L_ALL 70 | #define TEMP(_fmt, ...) MYPRINT("[TRACE]" WHERESTR _fmt, WHEREARG, __VA_ARGS__) 71 | #endif 72 | #define PRINT(x) INFO("%s=%d\n", #x, x) 73 | 74 | #define PRINTIF(cond, ...) do{int __x=(cond);if (__x) {MYPRINT(__VA_ARGS__);}}while(0); 75 | 76 | #ifndef NDEBUG 77 | #define ABORT(...) do{ERROR(__VA_ARGS__);abort();} while(0) 78 | #else 79 | #define ABORT(...) do{ERROR(__VA_ARGS__);exit(-1);} while(0) 80 | #endif 81 | 82 | #ifndef NDEBUG 83 | #define ASSERT(expr, ...) do{int __x = (int) expr; if (!__x) {ERROR("Assertion failed: %s\n", #expr); ABORT(__VA_ARGS__);}}while(0) 84 | #define CHECKT(x,t) DEBUG("%s: "t"\n", #x, x) 85 | #define CHECK(x) CHECKT(x,"%d") 86 | #endif 87 | 88 | #ifndef ERROR 89 | #define ERROR(...) 90 | #endif 91 | #ifndef WARN 92 | #define WARN(...) 93 | #endif 94 | #ifndef INFO 95 | #define INFO(...) 96 | #endif 97 | #ifndef DEBUG 98 | #define DEBUG(...) 99 | #endif 100 | #ifndef TRACE 101 | #define TRACE(...) 102 | #endif 103 | #ifndef TEMP 104 | #define TEMP(...) 105 | #endif 106 | #ifndef ASSERT 107 | #define ASSERT(...) 108 | #endif 109 | #ifndef CHECK 110 | #define CHECKT(...) 111 | #define CHECK(...) 112 | #endif 113 | 114 | 115 | 116 | 117 | #endif /* DEBUG_H_ */ 118 | -------------------------------------------------------------------------------- /implementations/dk2tree/encoding.c: -------------------------------------------------------------------------------- 1 | #include "encoding.h" 2 | 3 | 4 | //Vbyte encoding 5 | 6 | uint getEncodedSize(uint in) { 7 | uint res = 1; 8 | while (in >= 128) { 9 | res++; 10 | in = in >> 7; 11 | } 12 | return res; 13 | } 14 | 15 | uint encodeValue(uint in, byte * out) { 16 | uint bytesWritten = 0; 17 | while(1) { 18 | if (in < 128) { 19 | out[bytesWritten++] = in; 20 | break; 21 | } 22 | out[bytesWritten++] = 128 | (in&127); 23 | in = in>>7; 24 | } 25 | return bytesWritten; 26 | } 27 | 28 | uint decodeValue(byte *vbyte, uint *bytesRead) { 29 | uint ret = 0; 30 | uint shift = 0; 31 | uint temp; 32 | *bytesRead = 0; 33 | for (;;shift+=7) { 34 | temp = vbyte[(*bytesRead)++]; 35 | ret += (temp&0x7F) < 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include "util.h" 18 | 19 | #include "MemoryManager.h" 20 | 21 | #define JUMP 101 /*jump done when a collision appears*/ 22 | #define OCUP_HASH 1.5 /*index of occupation of the hash table*/ 23 | #define SMALL_PRIME 1009 /*a small prime number, used to compute a hash function*/ 24 | #define SEED 1159241 25 | /* Type definitions */ 26 | 27 | #define BASE_HASH_SIZE 8192 28 | 29 | #define STATUS_OK 0 30 | #define STATUS_DELETED 1 31 | #define STATUS_EMPTY 2 32 | 33 | #define MIN(a,b) (a < b) ? a : b 34 | #ifndef uint 35 | typedef unsigned int uint; 36 | #endif 37 | #define ISFOUND(h) (he->status == STATUS_OK) 38 | 39 | struct entry { 40 | // unsigned char * key; 41 | uint value; 42 | unsigned char status; 43 | }; 44 | typedef struct entry *hash_entry; 45 | 46 | struct Ht { 47 | MemoryManager memMgr; 48 | uint maxElem; 49 | uint numElem; 50 | int keySize; 51 | uint hashSize; 52 | struct entry *table; 53 | svector * words; 54 | }; 55 | typedef struct Ht *hash_table; 56 | 57 | unsigned int hashFunction(hash_table hash, const unsigned char *aWord); 58 | 59 | hash_table initialize_hash(unsigned int tamArq, uint keySize); 60 | hash_table resize_hash(hash_table old, uint newSize); 61 | void freeHashTable(hash_table hash, uint freeMemMgr); 62 | hash_entry insertElement(hash_table hash, unsigned char *aWord, 63 | register unsigned int *addr, uint value); 64 | void deleteElement(hash_table hash, unsigned int addr); 65 | hash_entry search(hash_table hash, const unsigned char *aWord, 66 | unsigned int *returnedAddr); 67 | uint memUsageHt(hash_table hash, uint includeMM); 68 | 69 | uint saveHash(hash_table hash, char * fileName); 70 | hash_table loadHash(char * fileName); 71 | 72 | 73 | -------------------------------------------------------------------------------- /implementations/dk2tree/k2tree-aux.h: -------------------------------------------------------------------------------- 1 | #ifndef K2TREE_AUX 2 | #define K2TREE_AUX 3 | 4 | #define DEF_QUEUE_MAX 50000000 5 | 6 | typedef struct sSimple { 7 | ull position; 8 | ull row; 9 | ull column; 10 | } SINGLE_QNODE; 11 | 12 | typedef struct sQueueSimple { 13 | SINGLE_QNODE els[DEF_QUEUE_MAX]; 14 | int ini; 15 | int fin; 16 | } SINGLE_QUEUE; 17 | 18 | SINGLE_QUEUE * getsq() { 19 | SINGLE_QUEUE * ret = (SINGLE_QUEUE *) malloc(sizeof(SINGLE_QUEUE)); 20 | ret->ini=DEF_QUEUE_MAX -1; 21 | ret->fin = 0; 22 | return ret; 23 | } 24 | 25 | int emptysq(SINGLE_QUEUE * queue) { 26 | return fin == (ini + 1) % DEF_QUEUE_MAX; 27 | } 28 | 29 | void pushsq(SINGLE_QUEUE * queue, ull position, ull row, ull column) { 30 | queue->ini++; 31 | queue->els[ini].position = position; 32 | queue->els[ini].row = row; 33 | queue->els[ini].column = column; 34 | } 35 | SINGLE_QNODE popsq(SINGLE_QUEUE * queue) { 36 | queue->fin = (queue->fin + 1) % DEF_QUEUE_MAX; 37 | } 38 | SINGLE_QNODE popsqn(SINGLE_QUEUE * queue, int n); 39 | 40 | 41 | #define addQueue(q, v) 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /implementations/dk2tree/k2tree-impl.h: -------------------------------------------------------------------------------- 1 | #ifndef K2TREE_IMPL 2 | #define K2TREE_IMPL 3 | 4 | #include "k2tree-common.h" 5 | 6 | 7 | Node * goToLeaf(K2Tree * k2tree, uint operation, uint reset, ull pos, ull comparepos, uint offsetPosReal); 8 | 9 | void changeLeaf(K2Tree * k2tree, Node ** path, uint * offsets, uint depth, 10 | uint * newData, uint newDataSizeBits, uint oldDataSizeBits, uint newDataOffsetBits, 11 | uint newDataEntries, uint oldDataEntries, uint newDataOnes, uint oldDataOnes, 12 | ull *leafOffset, ull * ones, ull * pos); 13 | 14 | //extern inline uint countOnes(K2Tree * k2tree, Node *node, int _x, uint * entries); 15 | extern uint countOnes(K2Tree * k2tree, Node *node, int _x, uint * entries); 16 | 17 | 18 | 19 | void alterSamples(K2Tree * k2tree, Node * node, int iniPos, int diffOnes); 20 | void fillSamples(K2Tree * k2tree, Node * node, int iniPos); 21 | uint nLocateEntry(K2Tree * k2tree, Node * node, int nEntry); 22 | uint * getWordSingleOne(uint pos, uint length); 23 | 24 | uint findChild1(uint * _data, uint nEntries, ull pos, uint offsetPosReal, byte operation, ull * _acumOnes, ull * _acumEntries, BID * child, ull *_curEntries); 25 | uint findChild2(uint * _data, uint nEntries, ull pos, uint offsetPosReal, byte operation, ull * _curEntries, ull * _acumEntries, BID * child); 26 | void resetPath(K2Tree * k2tree); 27 | Node * getChild(K2Tree * k2tree, Node * internalNode, int child); 28 | 29 | int getNSamples(K2Tree * k2tree, int nodeType); 30 | 31 | #endif /* K2TREE_IMPL */ 32 | -------------------------------------------------------------------------------- /implementations/dk2tree/lru.c: -------------------------------------------------------------------------------- 1 | #include "lru.h" 2 | /* 3 | Cola para implementar LRU. 4 | Permite eliminar un elemento (posición) calquera, 5 | engadir como mru e obter o lru. 6 | Implementación: lista doblemente enlazada con operacións de cola (push, pop) e acceso directo a posicións para eliminar 7 | Utiliza 12*size bytes (+overhead) 8 | */ 9 | 10 | 11 | LRUList * initLRU(int size) { 12 | LRUList * list = (LRUList *) malloc(sizeof(LRUList)); 13 | list->next = (int *) malloc(size*sizeof(int)); 14 | list->prev = (int *) malloc(size*sizeof(int)); 15 | list->lru = 0; 16 | int i; 17 | for (i = 0; i < size-1; i++) { 18 | list->next[i] = i+1; 19 | } 20 | for (i = 1; i < size; i++) { 21 | list->prev[i] = i-1; 22 | } 23 | list->next[size-1] = 0; 24 | list->prev[0] = size-1; 25 | return list; 26 | } 27 | 28 | void extractPositionLRU(LRUList * list, int pos) { 29 | if (pos == list->lru) { 30 | //We are extracting the head (lru) element 31 | list->lru = list->next[pos]; 32 | } 33 | list->next[list->prev[pos]] = list->next[pos]; 34 | list->prev[list->next[pos]] = list->prev[pos]; 35 | } 36 | 37 | int popLRU(LRUList * list) { 38 | int ret = list->lru; 39 | extractPositionLRU(list, list->lru); 40 | return ret; 41 | } 42 | 43 | void pushLRU(LRUList * list, int pos) { 44 | int oldmru = list->prev[list->lru]; 45 | list->next[oldmru] = pos; 46 | list->prev[pos] = oldmru; 47 | list->next[pos] = list->lru; 48 | list->prev[list->lru] = pos; 49 | } 50 | 51 | void printLRU(LRUList * list) { 52 | int curpos = list->lru; 53 | do { 54 | printf("%2d ", curpos); 55 | curpos = list->next[curpos]; 56 | } while(curpos != list->lru); 57 | printf("\n"); 58 | } 59 | 60 | -------------------------------------------------------------------------------- /implementations/dk2tree/lru.h: -------------------------------------------------------------------------------- 1 | #include "util.h" 2 | 3 | #define POS_HEAD (-1) 4 | #define POS_NONE (-2) 5 | 6 | typedef struct sLRUList { 7 | int *next; 8 | int *prev; 9 | int lru; 10 | } LRUList; 11 | 12 | LRUList * initLRU(int size); 13 | 14 | void extractPositionLRU(LRUList * list, int pos); 15 | 16 | int popLRU(LRUList * list); 17 | 18 | void pushLRU(LRUList * list, int pos); 19 | 20 | -------------------------------------------------------------------------------- /implementations/dk2tree/nodeManager-disk.c: -------------------------------------------------------------------------------- 1 | #include "nodeManager.h" 2 | 3 | extern uint MAX_BLOCKS_NM; 4 | 5 | void preDestroy(BasicNodeManager * mgr) { 6 | int i; 7 | int lastNode = -1; 8 | for (i = 0; i < MAX_BLOCKS_NM; i++) { 9 | if (mgr->cache[i].status == UNUSED) { 10 | writeNode(mgr, i); 11 | lastNode = i; 12 | } else if (mgr->cache[i].status == USED) { 13 | printf("position %d of cache is in use (BID = %d)!\n", i, mgr->cache[i].node->bid); 14 | } 15 | } 16 | printf("preDestroy: last node = %d\n", lastNode); 17 | } 18 | 19 | inline int hasCacheInfo() { 20 | return 1; 21 | } 22 | 23 | inline int getCachePosition(BasicNodeManager * mgr, BID bid) { 24 | return mgr->cachePositions[bid]; 25 | } 26 | 27 | inline void setCachePosition(BasicNodeManager * mgr, BID bid, int pos) { 28 | mgr->cachePositions[bid] = pos; 29 | } 30 | 31 | inline void clearCachePosition(BasicNodeManager *mgr, BID bid) { 32 | mgr->cachePositions[bid] = -1; 33 | } 34 | 35 | inline void doSaveNode(BasicNodeManager * mgr, Node *n) { 36 | fseek(mgr->file, RAWBID(n->bid) * mgr->blockSize, SEEK_SET); 37 | fwrite(n->data, 1, mgr->blockSize, mgr->file); 38 | } 39 | 40 | inline void _saveNode(BasicNodeManager * mgr, Node *n) { 41 | /* doSaveNode(mgr, n);*/ 42 | } 43 | inline int getFreePosition(BasicNodeManager * mgr, BID bid) { 44 | uint i; 45 | int start = bid % (MAX_BLOCKS_NM); 46 | uint njumps = 0; 47 | uint JUMP = 1; 48 | // naccesos[start]++; 49 | 50 | // if (bid == 255) { 51 | // DEBUG("start = %d\n", start); 52 | // for (i = 0; i < MAX_BLOCKS_NM; i++) { 53 | // DEBUG("cache[%d] = {status = %d, node = %x}\n", i, mgr->cache[i].status, mgr->cache[i].node); 54 | // DEBUG("bid = %d\n", RAWBID(mgr->cache[i].node->bid)); 55 | // } 56 | // } 57 | // for (i = 0; i < MAX_BLOCKS_NM; i++) { 58 | // if (mgr->cache[i].node && RAWBID(mgr->cache[i].node->bid) > 10000) { 59 | // ERROR("Failed\n"); 60 | // return 1/0; 61 | // } 62 | // } 63 | 64 | for (i = start; njumps++ < MAX_BLOCKS_NM ; i = (i + JUMP) % (MAX_BLOCKS_NM)) { 65 | if (mgr->cache[i].status == EMPTY) return i; 66 | if (mgr->cache[i].status == UNUSED) { 67 | doSaveNode(mgr, mgr->cache[i].node); 68 | if (mgr->cachePositions[RAWBID(mgr->cache[i].node->bid)] == i) { 69 | mgr->cachePositions[RAWBID(mgr->cache[i].node->bid)] = -1; 70 | } 71 | return i; 72 | } 73 | // ncolisiones++; 74 | } 75 | ERROR("No free cache positions!?"); 76 | exit(EXIT_UNEXPECTED); 77 | // return -1; 78 | } 79 | 80 | -------------------------------------------------------------------------------- /implementations/dk2tree/nodeManager-mem.c: -------------------------------------------------------------------------------- 1 | #include "nodeManager.h" 2 | 3 | void preDestroy(BasicNodeManager * mgr) { 4 | int i; 5 | int lastNode; 6 | for (i = 0; i < MAX_BLOCKS_NM; i++) { 7 | if (mgr->cache[i].status == UNUSED) { 8 | writeNode(mgr, i); 9 | lastNode = i; 10 | } 11 | } 12 | printf("preDestroy: last node = %d\n", lastNode); 13 | } 14 | 15 | inline int hasCacheInfo() { 16 | return 0; 17 | } 18 | 19 | inline int getCachePosition(BasicNodeManager * mgr, BID bid) { 20 | if (mgr->cache[bid].status == EMPTY) return -1; 21 | return bid; 22 | } 23 | 24 | inline void setCachePosition(BasicNodeManager * mgr, BID bid, int pos) { 25 | return; 26 | } 27 | 28 | inline void clearCachePosition(BasicNodeManager *mgr, BID bid) { 29 | return; 30 | } 31 | 32 | inline void _saveNode(BasicNodeManager * mgr, Node *n) { 33 | return; 34 | } 35 | 36 | inline int getFreePosition(BasicNodeManager * mgr, BID bid) { 37 | return bid; 38 | } 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /implementations/dk2tree/nodeManager.h: -------------------------------------------------------------------------------- 1 | #ifndef __NODEMANAGER_H__ 2 | 3 | #define __NODEMANAGER_H__ 4 | 5 | #include "util.h" 6 | #include 7 | 8 | 9 | #define EMPTY 1 10 | #define UNUSED 2 11 | #define USED 4 12 | #define DIRTY 8 13 | #define F_DIRTY 16 14 | 15 | 16 | 17 | typedef uint BID; 18 | typedef unsigned char NodeType; 19 | 20 | #define NODETYPE(BID) ((BID >> 24) & 0xFF) 21 | #define RAWBID(BID) (BID & 0x00FFFFFF) 22 | 23 | #define ADDNODETYPE(N, NT) (N->bid = N->bid | ((NT & 0xFF)<<24)) 24 | #define SETNODEBID(bid, nt) (bid = bid | ((nt&0xFF) << 24)) 25 | 26 | #define BaseNodeType 0 27 | 28 | //uint naccesos[MAX_BLOCKS_NM]; 29 | //uint ncolisiones; 30 | 31 | typedef struct sNode { 32 | BID bid; 33 | uint * data; 34 | } Node; 35 | 36 | 37 | typedef struct sbNodeManager { 38 | FILE * file; 39 | char * fileName; 40 | int fileSize; 41 | FILE * emptyFile; 42 | char * emptyFileName; 43 | uint blockSize; 44 | uint maxBlockSize; 45 | #ifdef MEMCACHE 46 | Node **cache; 47 | #else 48 | uint maxBlocks; 49 | Node *cache; 50 | byte *statuscache; 51 | vector *cachePositions; 52 | // IntQueue blockFIFO; 53 | #endif 54 | IntStack emptyBlocksList; 55 | } BasicNodeManager; 56 | 57 | typedef struct sNodeManager { 58 | uint nSizes; 59 | uint jump; 60 | uint blockSize; 61 | BasicNodeManager **delegates; 62 | } NodeManager; 63 | 64 | 65 | NodeManager * createNodeManager(char * fileName, uint blockSize, uint njumps); 66 | 67 | void destroyNodeManager(NodeManager * mgr); 68 | 69 | Node * allocateNode(NodeManager * mgr); 70 | 71 | Node * allocateANode(NodeManager *mgr, NodeType nt); 72 | 73 | Node * allocateAnyNode(NodeManager *mgr); 74 | 75 | Node * readNode(NodeManager * mgr, BID bid); 76 | 77 | void saveNode(NodeManager * mgr, Node * node); 78 | 79 | void releaseNode(NodeManager * mgr, Node * node); 80 | 81 | void destroyNode(NodeManager *mgr, Node * node); 82 | 83 | uint memUsageMgr(NodeManager * mgr); 84 | uint diskUsageMgr(NodeManager * mgr); 85 | 86 | /*private*/ 87 | int getFreePosition(BasicNodeManager * mgr, BID bid); 88 | int hasCacheInfo(void); 89 | /*void preLoad(BasicNodeManager * mgr);*/ 90 | void preDestroy(BasicNodeManager *mgr); 91 | int getCachePosition(BasicNodeManager *mgr, BID bid); 92 | void setCachePosition(BasicNodeManager *mgr, BID bid, int pos); 93 | void clearCachePosition(BasicNodeManager *mgr, BID id); 94 | void _saveNode(BasicNodeManager *mgr, Node *node); 95 | 96 | 97 | void writeNode(BasicNodeManager * mgr, int pos); 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /implementations/dk2tree/testCreateFromGraph.c: -------------------------------------------------------------------------------- 1 | #include "k2tree-common.h" 2 | #include "timing.h" 3 | 4 | int main(int argc, char ** argv) { 5 | 6 | if (argc < 6) { 7 | printf("Usage: %s ( )* []\n", argv[0]); 8 | exit(EXIT_UNEXPECTED); 9 | } 10 | { 11 | char * sourceFile = argv[1]; 12 | char * graphFile = argv[2]; 13 | char * vocFile = (char *)malloc(256*sizeof(char)); 14 | uint blockSize = atoi(argv[3]); 15 | uint njumps = atoi(argv[4]); 16 | K2Tree *tree; 17 | uint i; 18 | 19 | uint nvalues = argc - argc%2 - 5; 20 | uint leafLevels = (argc % 2)? atoi(argv[argc-1]) : 1; 21 | uint * values; 22 | 23 | strcpy(vocFile, "dic-wg-8.voc"); //FIXME: Variable, pasar como parametro se se quere usar 24 | // strcpy(vocFile, "onlyeu-2005.voc"); 25 | 26 | values = (uint *) malloc(nvalues * sizeof(uint)); 27 | for (i = 0; i < nvalues; i++) { 28 | values[i] = atoi(argv[5+i]); 29 | } 30 | 31 | 32 | ticks= (double)sysconf(_SC_CLK_TCK); 33 | startTimer(); 34 | 35 | tree = createK2Tree(sourceFile, graphFile, vocFile, blockSize, njumps, nvalues, values, leafLevels); 36 | 37 | // DEBUG("Delete node\n"); 38 | // deleteNode(tree, 0); 39 | 40 | // DEBUG("Get neighbors\n"); 41 | // uint *n1 = findNeighbors(tree, 0); 42 | // if (n1[0]) DEBUG("Has %d neighbors\n", n1[0]); 43 | // n1 = findRevNeighbors(tree, 0); 44 | // if (n1[0]) DEBUG("Has %d revneighbors\n", n1[0]); 45 | 46 | // 47 | // DEBUG("k2tree has %d nodes\n", tree->nNodesReal); 48 | // 49 | // 50 | // INFO("Creation : %f\n", timeFromBegin()); 51 | 52 | // rebuildLastLevel(tree); 53 | 54 | // replaceByOptimal(tree->voc); 55 | 56 | // if (tree->useDictionary) { 57 | // INFO("%d\n", getCompressedSize(tree->voc)); 58 | // INFO("%d\n", getOptimalSize(tree->voc)); 59 | // INFO("%d\n", getFixedSize(tree->voc)); 60 | // } 61 | 62 | free(values); 63 | free(vocFile); 64 | 65 | INFO("Memory usage : %ld\n", memUsageK2Tree(tree)); 66 | INFO("Disk usage : %ld\n", diskUsageK2Tree(tree)); 67 | 68 | destroyK2Tree(tree); 69 | 70 | INFO("Creation time = %f\n", timeFromBegin()); 71 | } 72 | exit(0); 73 | } 74 | -------------------------------------------------------------------------------- /implementations/dk2tree/testInsert.c: -------------------------------------------------------------------------------- 1 | #include "k2tree-common.h" 2 | 3 | int main(int argc, char ** argv) { 4 | 5 | char * fileName; 6 | 7 | if (argc < 2) { 8 | printf("Usage: %s ", argv[0]); 9 | exit(EXIT_UNEXPECTED); 10 | } 11 | 12 | fileName = argv[1]; 13 | 14 | { 15 | K2Tree * tree = loadK2Tree(fileName, 0); 16 | 17 | int from = atoi(argv[2]); 18 | int to = atoi(argv[3]); 19 | byte res; 20 | 21 | insertEdge(tree, from , to); 22 | DEBUG("Inserted (%d->%d)\n", from, to); 23 | 24 | res = findEdge(tree, from, to); 25 | if (!res) 26 | ERROR("Failed! Node %d->%d not inserted properly\n", from, to); 27 | DEBUG("Result of getting value = %d\n", res); 28 | 29 | 30 | DEBUG("Destroying k2tree\n"); 31 | destroyK2Tree(tree); 32 | } 33 | exit(0); 34 | } 35 | -------------------------------------------------------------------------------- /implementations/dk2tree/testLoad.c: -------------------------------------------------------------------------------- 1 | #include "k2tree-common.h" 2 | #include "timing.h" 3 | 4 | 5 | int main(int argc, char ** argv) { 6 | 7 | 8 | char * fileName; 9 | 10 | if (argc < 6) { 11 | printf("Usage: %s ", argv[0]); 12 | exit(EXIT_UNEXPECTED); 13 | } 14 | 15 | 16 | fileName = argv[1]; 17 | 18 | { 19 | K2Tree * tree = loadK2Tree(fileName, 1); 20 | 21 | int fFrom = atoi(argv[2]); 22 | int lFrom = atoi(argv[3]); 23 | int fTo = atoi(argv[4]); 24 | int lTo = atoi(argv[5]); 25 | uint from = 0, to = 5; 26 | 27 | ticks= (double)sysconf(_SC_CLK_TCK); 28 | startTimer(); 29 | 30 | 31 | 32 | 33 | for (from = fFrom; from < lFrom ; from ++){ 34 | for (to = fTo; to < lTo; to++){ 35 | byte res = findEdge(tree, from , to); 36 | if (res) DEBUG("%4d->%4d\n", from, to); 37 | } 38 | } 39 | 40 | destroyK2Tree(tree); 41 | 42 | DEBUG("time = %f\n", timeFromBegin()); 43 | } 44 | exit(0); 45 | } 46 | -------------------------------------------------------------------------------- /implementations/dk2tree/testLoadFromFile.c: -------------------------------------------------------------------------------- 1 | #include "k2tree-common.h" 2 | #include "timing.h" 3 | 4 | int main(int argc, char ** argv) { 5 | 6 | int foo; 7 | if (argc != 3) { 8 | printf("Usage: %s \n", argv[0]); 9 | exit(EXIT_UNEXPECTED); 10 | } 11 | 12 | 13 | ticks= (double)sysconf(_SC_CLK_TCK); 14 | startTimer(); 15 | 16 | { 17 | char * sourceFileName = argv[1]; 18 | char * graphFile = argv[2]; 19 | 20 | int i, val; 21 | uint nodesOrig, edges; 22 | int currentNode; 23 | int res; 24 | FILE * sourceFile = fopen(sourceFileName,"r"); 25 | 26 | K2Tree * k2tree = loadK2Tree(graphFile, 1); 27 | 28 | 29 | sourceFile = fopen(sourceFileName,"r"); 30 | foo = fread(&(nodesOrig),sizeof(uint),1,sourceFile); 31 | if (foo != 1) 32 | exit(IO_ERROR); 33 | foo = fread(&(edges),sizeof(uint),1,sourceFile); 34 | 35 | 36 | currentNode = -1; 37 | for (i = 0; i < nodesOrig + edges; i++) { 38 | foo = fread(&(val), sizeof(uint), 1, sourceFile); 39 | if (foo != 1){ 40 | exit(IO_ERROR); 41 | } 42 | if (val < 0) { 43 | currentNode++; 44 | if (!(currentNode % 1000)) DEBUG("Current node = %d\n", currentNode); 45 | } else { 46 | res = findEdge(k2tree, currentNode, val-1); 47 | if (!res) { 48 | ERROR("Failed for node %d->%d\n", currentNode, val-1); 49 | } 50 | } 51 | } 52 | 53 | 54 | fclose(sourceFile); 55 | 56 | 57 | destroyK2Tree(k2tree); 58 | 59 | DEBUG("time = %f\n", timeFromBegin()); 60 | } 61 | exit(0); 62 | } 63 | -------------------------------------------------------------------------------- /implementations/dk2tree/testNeighbors.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "k2tree-common.h" 3 | #include "timing.h" 4 | 5 | void swap(int * array, int p1, int p2) { 6 | int aux = array[p1]; 7 | array[p1] = array[p2]; 8 | array[p2] = aux; 9 | } 10 | 11 | int * permute(int n) { 12 | int * ret = (int *) malloc(n*sizeof(int)); 13 | int i; 14 | srand(7); 15 | for (i = 0; i < n; i++) { 16 | ret[i] = i; 17 | } 18 | for (i = 0; i < n; i++) { 19 | int newpos = rand() % (i+1); 20 | swap(ret, i, newpos); 21 | } 22 | return ret; 23 | } 24 | 25 | 26 | int main(int argc, char ** argv) { 27 | 28 | char * fileName; 29 | K2Tree * tree; 30 | int i; 31 | ull nNeighbors; 32 | // int from, lastFrom; 33 | 34 | if (argc < 2) { 35 | printf("Usage: %s ", argv[0]); 36 | exit(EXIT_UNEXPECTED); 37 | } 38 | 39 | fileName = argv[1]; 40 | 41 | ticks= (double)sysconf(_SC_CLK_TCK); 42 | startTimer(); 43 | 44 | tree = loadK2Tree(fileName, 1); 45 | 46 | DEBUG("time = %f\n", timeFromBegin()); 47 | 48 | int n = tree->nNodesReal; 49 | int * perm = permute(n); 50 | // 51 | DEBUG("time = %f\n", timeFromBegin()); 52 | 53 | nNeighbors = 0; 54 | //int j; 55 | uint * nn; 56 | for (i = 0; i < tree->nNodesReal ; i++) { 57 | if (!(i%100000)) printf(" iter %d\n", i); 58 | nn = findNeighbors(tree, perm[i]); 59 | nNeighbors += nn[0]; 60 | // for (j = 0; j < nn[0]; j++) { 61 | // printf("%d ", nn[1+j]); 62 | // } 63 | // printf("\n"); 64 | // nNeighbors += findRevNeighbors(tree, i)[0]; 65 | } 66 | 67 | free(perm); 68 | 69 | DEBUG("time = %lf, neighbors = %lu\n", timeFromBegin(), nNeighbors); 70 | 71 | destroyK2Tree(tree); 72 | 73 | exit(0); 74 | } 75 | -------------------------------------------------------------------------------- /implementations/dk2tree/testOptimizeLastLevel.c: -------------------------------------------------------------------------------- 1 | #include "k2tree-common.h" 2 | #include "stdlib.h" 3 | #include "timing.h" 4 | 5 | int main(int argc, char ** argv) { 6 | 7 | char * fileName; 8 | K2Tree * tree; 9 | 10 | if (argc < 3) { 11 | printf("Usage: %s ", argv[0]); 12 | exit(EXIT_UNEXPECTED); 13 | } 14 | 15 | fileName = argv[1]; 16 | 17 | tree = loadK2Tree(fileName, 0); 18 | 19 | rebuildLastLevel(tree); 20 | 21 | replaceByOptimal(tree->voc); 22 | 23 | destroyK2Tree(tree); 24 | 25 | exit(0); 26 | } 27 | -------------------------------------------------------------------------------- /implementations/dk2tree/testRange.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "k2tree-common.h" 3 | #include "timing.h" 4 | #include 5 | 6 | void swap(int * array, int p1, int p2) { 7 | int aux = array[p1]; 8 | array[p1] = array[p2]; 9 | array[p2] = aux; 10 | } 11 | 12 | int * permute(int n) { 13 | int * ret = (int *) malloc(n*sizeof(int)); 14 | int i; 15 | srand(7); 16 | for (i = 0; i < n; i++) { 17 | ret[i] = i; 18 | } 19 | for (i = 0; i < n; i++) { 20 | int newpos = rand() % (i+1); 21 | swap(ret, i, newpos); 22 | } 23 | return ret; 24 | } 25 | 26 | 27 | 28 | 29 | 30 | int main(int argc, char ** argv) { 31 | 32 | K2Tree * k2tree; 33 | // int i; 34 | 35 | if (argc < 2) { 36 | printf("Usage: %s ", argv[0]); 37 | exit(EXIT_UNEXPECTED); 38 | } 39 | 40 | 41 | ticks= (double)sysconf(_SC_CLK_TCK); 42 | startTimer(); 43 | 44 | k2tree = loadK2Tree(argv[1], 1); 45 | 46 | uint **v = findRange(k2tree, atoi(argv[2]), atoi(argv[3]), atoi(argv[4]), atoi(argv[5])); 47 | 48 | 49 | // uint * res = (uint *) malloc(v[0][0] * sizeof(uint)); 50 | 51 | // for (i = 0; i < v[0][0]; i++) { 52 | // res[i] = i; 53 | // } 54 | 55 | // qsort(res, v[0][0], sizeof(uint), (__compar_fn_t)sorter); 56 | // 57 | // printf("sorted!\n"); 58 | //// for (i = 0; i < v[0][0] - 1; i++) { 59 | //// printf("%d->%d\n", v[0][res[i]+1], v[1][res[i]+1]); 60 | //// } 61 | // 62 | // FILE * fout = fopen("out","w+"); 63 | // int val = 862664; 64 | // fwrite(&val, sizeof(uint), 1, fout); 65 | // fwrite(v[0], sizeof(uint), 1, fout); 66 | // 67 | // val = 0; 68 | //// fwrite(&val, sizeof(uint), 1, fout); 69 | // int lastFrom = 0; 70 | // 71 | // for (i = 0; i < v[0][0]; i++) { 72 | // uint newFrom = v[0][res[i]+1] + 1; 73 | // uint newTo = v[1][res[i]+1] + 1; 74 | //// printf("%d->%d\n", newFrom, newTo); 75 | // if (newFrom > lastFrom) { 76 | // uint j; 77 | // for (j = lastFrom + 1; j <= newFrom; j++) { 78 | // val--; 79 | // fwrite(&val, sizeof(uint), 1, fout); 80 | // } 81 | // lastFrom = newFrom; 82 | // } 83 | //// fwrite(&newFrom, sizeof(uint), 1, fout); 84 | // fwrite(&newTo, sizeof(uint), 1, fout); 85 | // } 86 | // fclose(fout); 87 | // 88 | printf("total:%d\n", v[0][0]); 89 | // for (i = 0; i < v[0][0]; i++) { 90 | // printf("%d->%d\n", v[0][1+i], v[1][1+i]); 91 | // } 92 | 93 | destroyK2Tree(k2tree); 94 | 95 | exit(0); 96 | } 97 | -------------------------------------------------------------------------------- /implementations/dk2tree/testRebuild.c: -------------------------------------------------------------------------------- 1 | #include "k2tree-common.h" 2 | #include "stdlib.h" 3 | #include "timing.h" 4 | 5 | uint **v; 6 | 7 | int sorter(void * p1, void * p2) { 8 | uint i1 = *((uint *)p1); 9 | uint i2 = *((uint *)p2); 10 | int res = v[0][i1+1] - v[0][i2+1]; 11 | if (!res) 12 | res = v[1][i1+1] - v[1][i2+1]; 13 | return res; 14 | } 15 | 16 | 17 | int main(int argc, char ** argv) { 18 | 19 | char * fileName; 20 | K2Tree * tree; 21 | 22 | if (argc < 3) { 23 | printf("Usage: %s ", argv[0]); 24 | exit(EXIT_UNEXPECTED); 25 | } 26 | 27 | fileName = argv[1]; 28 | 29 | tree = loadK2Tree(fileName, 0); 30 | 31 | ticks= (double)sysconf(_SC_CLK_TCK); 32 | startTimer(); 33 | { 34 | uint i,j; 35 | FILE * fout = fopen(argv[2], "w+"); 36 | uint curNode = 0; 37 | uint nNodes = (uint) tree->nNodesReal; 38 | uint nEdges = (uint) tree->nEdges; 39 | ull nNeighbors = 0; 40 | uint * neighbors; 41 | fwrite(&nNodes, sizeof(uint), 1, fout); 42 | fwrite(&nEdges, sizeof(uint), 1, fout); 43 | 44 | DEBUG("k2tree has %d nodes %d edges\n", nNodes, nEdges); 45 | 46 | // printNode(tree, tree->root1); 47 | // printNode(tree, tree->root2); 48 | 49 | if (format == EDGE_LIST) { 50 | //Rebuild using range and sorting should be faster 51 | if (tree->nEdges > DEF_BIG_SIZE) { 52 | ERROR("Edges will not fit in range search. Returning"); 53 | exit(EXIT_UNEXPECTED); 54 | } 55 | 56 | v = findRange(tree, 0, tree->nNodesReal-1, 0, tree->nNodesReal-1); 57 | 58 | if (v[0][0] != tree->nEdges) { 59 | ERROR("Unexpected result. Got %d edges in full range (graph has %ld edges)\n", v[0][0], tree->nEdges); 60 | exit(EXIT_UNEXPECTED); 61 | } 62 | 63 | uint * res = (uint *) malloc(v[0][0] * sizeof(uint)); 64 | 65 | for (i = 0; i < v[0][0]; i++) { 66 | res[i] = i; 67 | } 68 | 69 | qsort(res, v[0][0], sizeof(uint), (__compar_fn_t)sorter); 70 | 71 | 72 | for (j = 0; j < v[0][0]; j++) { 73 | uint from = v[0][res[j]+1]; 74 | uint to = v[1][res[j]+1]; 75 | fwrite(&from, sizeof(uint), 1, fout); 76 | fwrite(&to, sizeof(uint), 1, fout); 77 | } 78 | 79 | 80 | 81 | } else { 82 | 83 | for (i = 0; i < tree->nNodesReal; i++) { 84 | int foo; 85 | if(!(i%100000)) DEBUG("Finding neighbors of %d\n", i); 86 | curNode--; 87 | fwrite(&curNode, sizeof(int), 1, fout); 88 | neighbors = findNeighbors(tree, i); 89 | nNeighbors+=neighbors[0]; 90 | 91 | for (j = 0; j < neighbors[0]; j++) { 92 | foo = (int) neighbors[j+1]+1; 93 | fwrite(&foo, sizeof(int), 1, fout); 94 | } 95 | } 96 | } 97 | destroyK2Tree(tree); 98 | 99 | INFO("time = %f, neighbors = %lu, us/e = %lf\n", timeFromBegin(), nNeighbors, timeFromBegin()*1000000.0/nNeighbors); 100 | } 101 | exit(0); 102 | } 103 | -------------------------------------------------------------------------------- /implementations/dk2tree/timing.h: -------------------------------------------------------------------------------- 1 | #ifndef __TIMING_H__ 2 | #define __TIMING_H__ 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | double ticks; 10 | struct tms t1,t2,t3; 11 | 12 | void startTimer() { 13 | times (&t1); 14 | } 15 | 16 | double timeFromLast() { 17 | times (&t3); 18 | return ((t3.tms_utime+t3.tms_stime)-(t2.tms_utime+t2.tms_stime))/ticks; 19 | t2 = t3; 20 | } 21 | double timeFromBegin() { 22 | times (&t2); 23 | return ((t2.tms_utime+t2.tms_stime)-(t1.tms_utime+t1.tms_stime))/ticks; 24 | // return ((t2.tms_utime)-(t1.tms_utime))/ticks; 25 | } 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /implementations/dk2tree/vocUtils.h: -------------------------------------------------------------------------------- 1 | #ifndef __VOCUTILS_H__ 2 | 3 | #define __VOCUTILS_H__ 4 | 5 | #include "basic.h" 6 | #include "hash.h" 7 | #include "util.h" 8 | 9 | #define MAX_WORDS_VOC 5000000 10 | #define MAX_FREQS_VOC 5000000 11 | 12 | typedef struct svoc { 13 | uint maxSize; 14 | uint nWords; 15 | uint nWordsReal; 16 | uint wordLength; 17 | vector * posInTH; 18 | hash_table inverse; 19 | vector * freqs; 20 | IntStack emptyCodes; 21 | int readonly; 22 | uint compressedSize; 23 | uint optimalSize; 24 | vector *o2s; 25 | vector *s2o; 26 | vector *top; 27 | uint maxFreq; 28 | unsigned char * words; 29 | } VOC; 30 | 31 | VOC * loadVocabulary(char * basename, uint readonly); 32 | VOC * createEmptyVocabulary(uint wordLen); 33 | 34 | void freeVocabulary(VOC * voc); 35 | 36 | void saveVocabulary(VOC * voc, char * filename); 37 | 38 | uint memUsageVocabulary(VOC * voc); 39 | uint diskUsageVocabulary(VOC * voc); 40 | 41 | unsigned char * getWordVocabulary(VOC * voc, uint pos); 42 | 43 | uint getOptimalPosition(VOC * voc, uint word); 44 | 45 | void printWordVocabulary(VOC * voc, uint pos); 46 | 47 | hash_entry getEntryWord(VOC * voc, unsigned char * word, unsigned int * addr); 48 | 49 | hash_entry insertWord(VOC * voc, unsigned char * word, unsigned int * addr); 50 | 51 | ull addEntryVocabulary(VOC * voc, unsigned char * word); 52 | void removeEntryVocabulary(VOC * voc, unsigned char * word); 53 | 54 | uint getCompressedSize(VOC *voc); 55 | uint getOptimalSize(VOC *voc); 56 | 57 | void replaceByOptimal(VOC * voc); 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /implementations/k2tree/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | 3 | kt_decompressTree 4 | adylist_setop_intersection 5 | kt_getReverseNeightbors 6 | kt_toList 7 | kt_fromList 8 | adylist_setop_complement 9 | adylist_setop_symmdiff 10 | kt_getCell 11 | kt_setop_intersection 12 | adylist_setop_difference 13 | adylist_setop_union 14 | kt_getNeightbors 15 | kt_setop_complement 16 | kt_setop_symmdiff 17 | kt_buildTree 18 | kt_getRange 19 | kt_setop_difference 20 | kt_setop_union 21 | 22 | project 23 | 24 | *.exe -------------------------------------------------------------------------------- /implementations/k2tree/Entry.c: -------------------------------------------------------------------------------- 1 | #include "Entry.h" 2 | 3 | inline unsigned char getLevel(ENTRY e) { 4 | return e.e >>2; 5 | } 6 | 7 | inline unsigned char getRa(ENTRY e) { 8 | return (e.e & 0x02)>>1; 9 | } 10 | 11 | inline unsigned char getRb(ENTRY e) { 12 | return e.e & 0x01; 13 | } 14 | 15 | inline ENTRY setEntry(unsigned char l, unsigned char ra, unsigned char rb) { 16 | ENTRY e ; 17 | e.e = (unsigned char) (l<<2) + (ra<<1) + (rb); 18 | return e; 19 | } 20 | -------------------------------------------------------------------------------- /implementations/k2tree/Entry.h: -------------------------------------------------------------------------------- 1 | #include 2 | typedef struct entry 3 | { 4 | /**************************** 5 | * b b b b b b b b * 6 | * -----l----- Ra Rb * 7 | ***************************** 8 | */ 9 | unsigned char e; 10 | }ENTRY; 11 | 12 | /* 13 | * Crea un objeto de tipo ENTRY 14 | */ 15 | ENTRY setEntry(unsigned char l, unsigned char ra, unsigned char rb); 16 | /* 17 | * obtiene el nivel 18 | */ 19 | unsigned char getLevel(ENTRY e); 20 | /* 21 | * obtiene Ra 22 | */ 23 | unsigned char getRa(ENTRY e); 24 | /* 25 | * obtiene Rb 26 | */ 27 | unsigned char getRb(ENTRY e); 28 | -------------------------------------------------------------------------------- /implementations/k2tree/Makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | 3 | OBJECTS=basic.o bitrankw32int.o misBits.o adylist.o adylist_setOperations.o\ 4 | pair.o kTree.o Entry.o NodeQueue.o Queue.o kt_setOperations.o 5 | 6 | BINS=kt_decompressTree kt_buildTree kt_toList kt_fromList project\ 7 | kt_setop_union kt_setop_intersection kt_setop_difference kt_setop_symmdiff kt_setop_complement\ 8 | kt_getCell kt_getNeightbors kt_getReverseNeightbors kt_getRange\ 9 | adylist_setop_union adylist_setop_intersection adylist_setop_difference adylist_setop_symmdiff adylist_setop_complement 10 | 11 | CCFLAGS=-Wall -O9 -DNDEBUG 12 | 13 | # How to check the invoking target when calling make: 14 | # https://www.gnu.org/software/make/manual/html_node/Goals.html 15 | ifeq ($(MAKECMDGOALS),debug) 16 | CCFLAGS=-Wall -g -DDEBUGGING 17 | endif 18 | 19 | 20 | DEST=. 21 | 22 | %.o: %.c 23 | $(CC) $(CCFLAGS) -c $< -o $@ 24 | 25 | all: clean bin 26 | 27 | debug: clean bin 28 | 29 | bin: $(OBJECTS) $(BINS) 30 | 31 | project: 32 | $(CC) $(CCFLAGS) -o $(DEST)/project main.c $(OBJECTS) -lm 33 | 34 | adylist_setop_union: 35 | $(CC) $(CCFLAGS) -o $(DEST)/adylist_setop_union adylist_setop_union.c $(OBJECTS) -lm 36 | 37 | adylist_setop_intersection: 38 | $(CC) $(CCFLAGS) -o $(DEST)/adylist_setop_intersection adylist_setop_intersection.c $(OBJECTS) -lm 39 | 40 | adylist_setop_difference: 41 | $(CC) $(CCFLAGS) -o $(DEST)/adylist_setop_difference adylist_setop_difference.c $(OBJECTS) -lm 42 | 43 | adylist_setop_symmdiff: 44 | $(CC) $(CCFLAGS) -o $(DEST)/adylist_setop_symmdiff adylist_setop_symmdiff.c $(OBJECTS) -lm 45 | 46 | adylist_setop_complement: 47 | $(CC) $(CCFLAGS) -o $(DEST)/adylist_setop_complement adylist_setop_complement.c $(OBJECTS) -lm 48 | 49 | kt_decompressTree: 50 | $(CC) $(CCFLAGS) -o $(DEST)/kt_decompressTree kt_decompressTree.c $(OBJECTS) -lm 51 | 52 | kt_fromList: 53 | $(CC) $(CCFLAGS) -o $(DEST)/kt_fromList kt_fromList.c $(OBJECTS) -lm 54 | 55 | kt_toList: 56 | $(CC) $(CCFLAGS) -o $(DEST)/kt_toList kt_toList.c $(OBJECTS) -lm 57 | 58 | kt_buildTree: 59 | $(CC) $(CCFLAGS) -o $(DEST)/kt_buildTree kt_buildTree.c $(OBJECTS) -lm 60 | 61 | kt_setop_union: 62 | $(CC) $(CCFLAGS) -o $(DEST)/kt_setop_union kt_setop_union.c $(OBJECTS) -lm 63 | 64 | kt_setop_difference: 65 | $(CC) $(CCFLAGS) -o $(DEST)/kt_setop_difference kt_setop_difference.c $(OBJECTS) -lm 66 | 67 | kt_setop_intersection: 68 | $(CC) $(CCFLAGS) -o $(DEST)/kt_setop_intersection kt_setop_intersection.c $(OBJECTS) -lm 69 | 70 | kt_setop_symmdiff: 71 | $(CC) $(CCFLAGS) -o $(DEST)/kt_setop_symmdiff kt_setop_symmdiff.c $(OBJECTS) -lm 72 | 73 | kt_setop_complement: 74 | $(CC) $(CCFLAGS) -o $(DEST)/kt_setop_complement kt_setop_complement.c $(OBJECTS) -lm 75 | 76 | kt_getCell: 77 | $(CC) $(CCFLAGS) -o $(DEST)/kt_getCell kt_getCell.c $(OBJECTS) -lm 78 | 79 | kt_getNeightbors: 80 | $(CC) $(CCFLAGS) -o $(DEST)/kt_getNeightbors kt_getNeightbors.c $(OBJECTS) -lm 81 | 82 | kt_getReverseNeightbors: 83 | $(CC) $(CCFLAGS) -o $(DEST)/kt_getReverseNeightbors kt_getReverseNeightbors.c $(OBJECTS) -lm 84 | 85 | kt_getRange: 86 | $(CC) $(CCFLAGS) -o $(DEST)/kt_getRange kt_getRange.c $(OBJECTS) -lm 87 | 88 | clean: 89 | rm -f $(OBJECTS) $(BINS) 90 | cd $(DEST); rm -f *.a $(BINS) *.exe *.o 91 | -------------------------------------------------------------------------------- /implementations/k2tree/NodeQueue.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "NodeQueue.h" 3 | #include 4 | 5 | 6 | NODEQUEUE * newNodeQueue(unsigned char s) { 7 | NODEQUEUE *n; 8 | n = (NODEQUEUE *) malloc(sizeof(NODEQUEUE)); 9 | n->t=s; 10 | n->r=0; 11 | n->f=0; 12 | n->u=0; 13 | n->e=(ENTRY *)malloc( n->t*sizeof(ENTRY)); 14 | n->next = NULL; 15 | return n; 16 | } 17 | 18 | int insertarEntry(NODEQUEUE * n, ENTRY nuevo){ 19 | if(estaLleno(n)){ 20 | return 0; 21 | } 22 | 23 | if(estaVacio(n)){ 24 | n->r = 0; 25 | n->f = 0; 26 | }else if(n->r +1 == n->t){ 27 | n->r = 0; 28 | }else{ 29 | n->r = n->r +1; 30 | } 31 | 32 | n->e[n->r] = nuevo; 33 | n->u = n->u +1; 34 | 35 | return 1; 36 | } 37 | 38 | ENTRY extraerEntry(NODEQUEUE * n){ 39 | ENTRY retorno = n->e[n->f]; 40 | 41 | if(n->f +1 == n->t){ 42 | n->f = 0; 43 | }else{ 44 | n->f = n->f +1; 45 | } 46 | n->u = n->u -1; 47 | 48 | return retorno; 49 | } 50 | 51 | unsigned char estaLleno(NODEQUEUE *n) { 52 | return (unsigned char) (n->u == n->t); 53 | } 54 | 55 | unsigned char estaVacio(NODEQUEUE *n) { 56 | return (unsigned char) (n->u == 0); 57 | } 58 | 59 | void destroyNodeQueue(NODEQUEUE *n){ 60 | free(n->e); 61 | free(n); 62 | return; 63 | } -------------------------------------------------------------------------------- /implementations/k2tree/NodeQueue.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Entry.h" 3 | 4 | typedef struct NodeQueue { 5 | unsigned char t; // Tamaño del nodo 6 | unsigned char f; // front dentro del nodo 7 | unsigned char r; // rear dentro del nodo 8 | unsigned char u; // numero de elementos en el nodo 9 | ENTRY *e; 10 | struct NodeQueue * next; 11 | } NODEQUEUE; 12 | 13 | NODEQUEUE * newNodeQueue(unsigned char size);// Crea un nuevo nodo 14 | int insertarEntry(NODEQUEUE * n, ENTRY nuevo); // Inserta un nuevo ENTRY en el nodo. Si retorna 0 falló la inserción. 15 | ENTRY extraerEntry(NODEQUEUE * n); 16 | unsigned char estaLleno(NODEQUEUE *n);// Verifica si un nodo está lleno 17 | unsigned char estaVacio(NODEQUEUE *n);// y si un nodo esta vacio 18 | void destroyNodeQueue(NODEQUEUE *n); //Elimina el NodeQueue -------------------------------------------------------------------------------- /implementations/k2tree/Queue.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Queue.h" 3 | #include 4 | 5 | /**************************************/ 6 | QUEUE * newQueue(unsigned int nodSiz) { 7 | QUEUE *q = (QUEUE *) malloc(sizeof(QUEUE)) ; 8 | q->nodeSize = nodSiz; 9 | q->cant = 0; 10 | q->front = newNodeQueue(nodSiz); 11 | q->rear = q->front; 12 | return q; 13 | } 14 | 15 | /************************************/ 16 | void Insert(QUEUE *q, ENTRY ent) { 17 | if(estaLleno(q->rear)) { 18 | //El Nodo rear esta lleno 19 | q->rear->next = newNodeQueue(q->nodeSize); 20 | q->rear = q->rear->next; 21 | } 22 | if(insertarEntry(q->rear, ent)); 23 | q->cant ++; 24 | } 25 | 26 | /*******************************/ 27 | ENTRY Delete(QUEUE *q) { 28 | ENTRY ee; 29 | if(q->cant > 0){ 30 | if(estaVacio(q->front)){ //El NodeQueue front está vacío y se debe trasladar 31 | NODEQUEUE* siguiente = q->front->next; 32 | destroyNodeQueue(q->front); 33 | q->front = siguiente; 34 | } 35 | ee = extraerEntry(q->front); 36 | q->cant --; 37 | } 38 | return ee; 39 | } 40 | 41 | /********************************/ 42 | int size(QUEUE *q) { 43 | int sz =0; 44 | NODEQUEUE *n; 45 | for (n=q->front; n!=NULL;n=n->next){ 46 | sz++; 47 | } 48 | return sz; 49 | } 50 | 51 | -------------------------------------------------------------------------------- /implementations/k2tree/Queue.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include "NodeQueue.h" 3 | 4 | typedef struct Queue { 5 | unsigned int nodeSize; //tamaño definido para los NodeQueue de Queue 6 | unsigned int cant; //cantidad de elementos contenidos hasta el momento. 7 | NODEQUEUE * front; // puntero a primer nodo de la cola 8 | NODEQUEUE * rear; // puntero al último nodo de la cola 9 | } QUEUE; 10 | 11 | QUEUE * newQueue(unsigned int nodeSize); // Crea una nueva cola. 12 | void Insert(QUEUE *q, ENTRY e); // Inserta un objeto a la cola 13 | ENTRY Delete(QUEUE *q); // elimina y devuelve un objeto de la cola 14 | int size(QUEUE *q); -------------------------------------------------------------------------------- /implementations/k2tree/README.md: -------------------------------------------------------------------------------- 1 | # k2tree graph data structure 2 | 3 | ## Description 4 | 5 | This directory contains the source-code of the **k2tree**, the static *k*2-tree structure which is described in the paper [Compact Representation of Web Graphs with Extended Functionality](https://doi.org/10.1016/j.is.2013.08.003), 6 | by Nieves R. Brisaboa, Susana Ladra and Gonzalo Navarro (2014). 7 | 8 | ## Usage examples 9 | 10 | make 11 | 12 | # This is the static k2-tree version, need to generate .kt format file first. 13 | ./kt_buildTree ../../datasets/dataset.adj dataset 14 | mv dataset.kt ../../datasets/ 15 | 16 | ./project ../../datasets/dataset dataset-lists_eval < ../../datasets/dataset-lists.tsv 17 | 18 | (2) 19 | (2) 20 | (1) 21 | (1) 22 | (1) 23 | (2) 24 | (0) 25 | (0) 26 | (0) 27 | > Exiting. 28 | Loop time: 70.000000 29 | 30 | #### Argument info: 31 | # ../../datasets/dataset - path to dataset file (written without .kt extension) 32 | # ../../datasets/dataset-lists.tsv - path to a graph operations 33 | file with neighborhood listing operations exclusively 34 | -------------------------------------------------------------------------------- /implementations/k2tree/adylist.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "basic.h" 5 | 6 | typedef struct adyList{ 7 | uint numNodes; 8 | int* listady; 9 | ulong numEdges; 10 | }ALREP; 11 | 12 | ALREP * loadAdyacencyList(char * basename); 13 | void destroyAdyacencyList(ALREP * list); 14 | void saveAdyacencyList(ALREP * list, char * basename); 15 | 16 | uint adylist_getCell(ALREP * lista, uint p0, uint p1); 17 | uint * adylist_getNeightbors(ALREP * list, uint p0); 18 | uint * adylist_getRange(ALREP * lista, int p0, int p1, int q0, int q1); 19 | uint * adylist_getReverseNeightbors(ALREP * lista, uint p0); 20 | 21 | ulong * indexList(ALREP * list); -------------------------------------------------------------------------------- /implementations/k2tree/adylist_setOperations.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "basic.h" 4 | 5 | #ifndef adyList_h 6 | #define adyList_h 7 | #include "adylist.h" 8 | #endif 9 | 10 | ALREP * adylistUnionOperation(ALREP * A, ALREP * B); 11 | ALREP * adylistDifferenceOperation(ALREP * A, ALREP * B); 12 | ALREP * adylistIntersectionOperation(ALREP * A, ALREP * B); 13 | ALREP * adylistSymmetricDifferenceOperation(ALREP * A, ALREP * B); 14 | ALREP * adylistComplementOperation(ALREP * A); 15 | 16 | -------------------------------------------------------------------------------- /implementations/k2tree/adylist_setop_complement.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "adylist_setOperations.h" 3 | 4 | int main(int argc, char* argv[]){ 5 | if(argc<3){ 6 | fprintf(stderr,"USAGE: %s \n",argv[0]); 7 | return(-1); 8 | } 9 | /* 10 | char *filename = (char *) malloc(sizeof(char)*(strlen(argv[1])+8)); 11 | strcpy(filename,argv[1]); 12 | strcat(filename,".rbfull"); 13 | FILE * ft = fopen(filename,"r"); 14 | uint nodes; 15 | fread(&nodes,sizeof(uint),1,ft); 16 | ulong edges; 17 | fread(&edges,sizeof(ulong),1,ft); 18 | int* adyList = (int*)malloc(sizeof(int)*(edges+nodes)); 19 | fread(adyList,sizeof(int), nodes+edges,ft); 20 | fclose(ft); 21 | free(filename); 22 | */ 23 | 24 | ALREP * A = loadAdyacencyList(argv[1]); 25 | 26 | // Desplegando Lista de Adyacencia 27 | /* 28 | printf("Lista de Adyacencia de %s\n", argv[1]); 29 | printf("Nodes: %d\n", nodes); 30 | printf("Edges: %ld\n", edges); 31 | ulong i; 32 | for(i=0; i 2 | #include "adylist_setOperations.h" 3 | 4 | int main(int argc, char* argv[]){ 5 | 6 | if(argc<4){ 7 | fprintf(stderr,"USAGE: %s \n",argv[0]); 8 | return(-1); 9 | } 10 | 11 | // Cargando Lista de Adyacencia A 12 | /* 13 | char *filename = (char *) malloc(sizeof(char)*(strlen(argv[1])+8)); 14 | strcpy(filename,argv[1]); 15 | strcat(filename,".rbfull"); 16 | FILE * ft = fopen(filename,"r"); 17 | uint nodes; 18 | fread(&nodes,sizeof(uint),1,ft); 19 | ulong edgesA; 20 | fread(&edgesA,sizeof(ulong),1,ft); 21 | int* listadyA = (int*)malloc(sizeof(int)*(edgesA+nodes)); 22 | fread(listadyA,sizeof(int), nodes+edgesA,ft); 23 | fclose(ft); 24 | free(filename); 25 | */ 26 | ALREP * A = loadAdyacencyList(argv[1]); 27 | 28 | // Cargando Lista de Adyacencia B 29 | /* 30 | filename = (char *) malloc(sizeof(char)*(strlen(argv[1])+8)); 31 | strcpy(filename,argv[2]); 32 | strcat(filename,".rbfull"); 33 | ft = fopen(filename,"r"); 34 | uint nodesB; 35 | fread(&nodesB,sizeof(uint),1,ft); 36 | ulong edgesB; 37 | fread(&edgesB,sizeof(ulong),1,ft); 38 | int* listadyB = (int*)malloc(sizeof(int)*(edgesB+nodesB)); 39 | fread(listadyB,sizeof(int), nodesB+edgesB,ft); 40 | fclose(ft); 41 | free(filename); 42 | */ 43 | ALREP * B = loadAdyacencyList(argv[2]); 44 | // Desplegando A 45 | /* 46 | printf("Lista de Adyacencia de %s\n", argv[1]); 47 | printf("Nodes: %d\n", nodes); 48 | printf("Edges: %ld\n", edgesA); 49 | ulong i; 50 | for(i=0; i 2 | #include "adylist_setOperations.h" 3 | 4 | int main(int argc, char* argv[]){ 5 | 6 | if(argc<4){ 7 | fprintf(stderr,"USAGE: %s \n",argv[0]); 8 | return(-1); 9 | } 10 | 11 | // Cargando Lista de Adyacencia A 12 | /* 13 | char *filename = (char *) malloc(sizeof(char)*(strlen(argv[1])+8)); 14 | strcpy(filename,argv[1]); 15 | strcat(filename,".rbfull"); 16 | FILE * ft = fopen(filename,"r"); 17 | uint nodes; 18 | fread(&nodes,sizeof(uint),1,ft); 19 | ulong edgesA; 20 | fread(&edgesA,sizeof(ulong),1,ft); 21 | int* listadyA = (int*)malloc(sizeof(int)*(edgesA+nodes)); 22 | fread(listadyA,sizeof(int), nodes+edgesA,ft); 23 | fclose(ft); 24 | free(filename); 25 | */ 26 | ALREP * A = loadAdyacencyList(argv[1]); 27 | 28 | // Cargando Lista de Adyacencia B 29 | /* 30 | filename = (char *) malloc(sizeof(char)*(strlen(argv[1])+8)); 31 | strcpy(filename,argv[2]); 32 | strcat(filename,".rbfull"); 33 | ft = fopen(filename,"r"); 34 | uint nodesB; 35 | fread(&nodesB,sizeof(uint),1,ft); 36 | ulong edgesB; 37 | fread(&edgesB,sizeof(ulong),1,ft); 38 | int* listadyB = (int*)malloc(sizeof(int)*(edgesB+nodesB)); 39 | fread(listadyB,sizeof(int), nodesB+edgesB,ft); 40 | fclose(ft); 41 | free(filename); 42 | */ 43 | ALREP * B = loadAdyacencyList(argv[2]); 44 | 45 | // Desplegando A 46 | /* 47 | printf("Lista de Adyacencia de %s\n", argv[1]); 48 | printf("Nodes: %d\n", nodes); 49 | printf("Edges: %ld\n", edgesA); 50 | ulong i; 51 | for(i=0; i 2 | #include "adylist_setOperations.h" 3 | 4 | int main(int argc, char* argv[]){ 5 | 6 | if(argc<4){ 7 | fprintf(stderr,"USAGE: %s \n",argv[0]); 8 | return(-1); 9 | } 10 | 11 | // Cargando Lista de Adyacencia A 12 | /* 13 | char *filename = (char *) malloc(sizeof(char)*(strlen(argv[1])+8)); 14 | strcpy(filename,argv[1]); 15 | strcat(filename,".rbfull"); 16 | FILE * ft = fopen(filename,"r"); 17 | uint nodes; 18 | fread(&nodes,sizeof(uint),1,ft); 19 | ulong edgesA; 20 | fread(&edgesA,sizeof(ulong),1,ft); 21 | int* listadyA = (int*)malloc(sizeof(int)*(edgesA+nodes)); 22 | fread(listadyA,sizeof(int), nodes+edgesA,ft); 23 | fclose(ft); 24 | free(filename); 25 | */ 26 | 27 | ALREP * A = loadAdyacencyList(argv[1]); 28 | 29 | // Cargando Lista de Adyacencia B 30 | /* 31 | filename = (char *) malloc(sizeof(char)*(strlen(argv[1])+8)); 32 | strcpy(filename,argv[2]); 33 | strcat(filename,".rbfull"); 34 | ft = fopen(filename,"r"); 35 | uint nodesB; 36 | fread(&nodesB,sizeof(uint),1,ft); 37 | ulong edgesB; 38 | fread(&edgesB,sizeof(ulong),1,ft); 39 | int* listadyB = (int*)malloc(sizeof(int)*(edgesB+nodesB)); 40 | fread(listadyB,sizeof(int), nodesB+edgesB,ft); 41 | fclose(ft); 42 | free(filename); 43 | */ 44 | ALREP * B = loadAdyacencyList(argv[2]); 45 | 46 | // Desplegando A 47 | /* 48 | printf("Lista de Adyacencia de %s\n", argv[1]); 49 | printf("Nodes: %d\n", nodes); 50 | printf("Edges: %ld\n", edgesA); 51 | ulong i; 52 | for(i=0; i 2 | #include "adylist_setOperations.h" 3 | 4 | int main(int argc, char* argv[]){ 5 | 6 | if(argc<4){ 7 | fprintf(stderr,"USAGE: %s \n",argv[0]); 8 | return(-1); 9 | } 10 | 11 | // Cargando Lista de Adyacencia A 12 | ALREP * A = loadAdyacencyList(argv[1]); 13 | // Cargando Lista de Adyacencia B 14 | ALREP * B = loadAdyacencyList(argv[2]); 15 | 16 | ALREP * listadyResult = adylistUnionOperation(A, B); 17 | if(listadyResult == NULL){ 18 | printf("Error en la operación...\n"); 19 | return 0; 20 | } 21 | 22 | destroyAdyacencyList(A); 23 | destroyAdyacencyList(B); 24 | // Desplegando Resultado de la Unión 25 | //saveAdyList(edgesResult[0], nodes, listadyResult, argv[3]); 26 | saveAdyacencyList(listadyResult, argv[3]); 27 | destroyAdyacencyList(listadyResult); 28 | 29 | return 0; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /implementations/k2tree/basic.h: -------------------------------------------------------------------------------- 1 | #ifndef BASICSINCLUDED 2 | #define BASICSINCLUDED 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | /* basics.h 13 | Copyright (C) 2005, Rodrigo Gonzalez, all rights reserved. 14 | 15 | Some preliminary stuff 16 | 17 | This library is free software; you can redistribute it and/or 18 | modify it under the terms of the GNU Lesser General Public 19 | License as published by the Free Software Foundation; either 20 | version 2.1 of the License, or (at your option) any later version. 21 | 22 | This library is distributed in the hope that it will be useful, 23 | but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | Lesser General Public License for more details. 26 | 27 | You should have received a copy of the GNU Lesser General Public 28 | License along with this library; if not, write to the Free Software 29 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 30 | 31 | */ 32 | 33 | 34 | 35 | #define mask31 0x0000001F 36 | 37 | #define max(x,y) ((x)>(y)?(x):(y)) 38 | #define min(x,y) ((x)<(y)?(x):(y)) 39 | 40 | /*numero de bits del entero de la maquina*/ 41 | #define W 32 42 | /* W-1 */ 43 | #define Wminusone 31 44 | /*numero de bits del entero de la maquina*/ 45 | #define WW 64 46 | /*bits para hacer la mascara para contar mas rapido*/ 47 | #define bitsM 8 48 | /*bytes que hacen una palabra */ 49 | #define BW 4 50 | #ifndef uchar 51 | #define uchar unsigned char 52 | #endif 53 | #ifndef uint 54 | #define uint unsigned int 55 | #endif 56 | #ifndef ulong 57 | #define ulong unsigned long 58 | #endif 59 | #define size_uchar 256 60 | 61 | /* reads bit p from e */ 62 | #define bitget(e,p) ((((e)[(p)/W] >> ((p)%W))) & 1) 63 | /* sets bit p in e */ 64 | #define bitset(e,p) ((e)[(p)/W] |= (1<<((p)%W))) 65 | /* cleans bit p in e */ 66 | #define bitclean(e,p) ((e)[(p)/W] &= ~(1<<((p)%W))) 67 | 68 | /* numero de enteros necesarios para representar e elementos de largo n */ 69 | #define enteros(e,n) ((e)*(n))/W+(((e)*(n))%W > 0) 70 | /* bits needed to represent a number between 0 and n */ 71 | uint bits (uint n); 72 | 73 | 74 | 75 | uint GetField(uint *A, register uint len, register uint index); 76 | void SetField(uint *A,register uint len, register uint index,register uint x); 77 | 78 | 79 | uint GetVarField(uint *A, register uint ini, register uint fin); 80 | 81 | void SetVarField(uint *A,register uint ini, register uint fin,register uint x); 82 | 83 | unsigned GetFieldW32(uint *A,register uint index); 84 | 85 | 86 | void SetField32(uint *A, register uint index,register uint x) ; 87 | 88 | unsigned GetFieldW16(uint *A,register uint index); 89 | unsigned GetFieldW4(uint *A,register uint index) ; 90 | 91 | uint popcount (register int x); 92 | 93 | uint popcount16 (register int x); 94 | 95 | uint popcount8 (register int x); 96 | #endif 97 | -------------------------------------------------------------------------------- /implementations/k2tree/bitrankw32int.h: -------------------------------------------------------------------------------- 1 | #ifndef BitRankW32Int_h 2 | #define BitRankW32Int_h 3 | #include "basic.h" 4 | /* bitarray.h 5 | Copyright (C) 2005, Rodrigo Gonzalez, all rights reserved. 6 | 7 | New RANK, SELECT, SELECT-NEXT and SPARSE RANK implementations. 8 | 9 | This library is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Lesser General Public 11 | License as published by the Free Software Foundation; either 12 | version 2.1 of the License, or (at your option) any later version. 13 | 14 | This library is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | Lesser General Public License for more details. 18 | 19 | You should have received a copy of the GNU Lesser General Public 20 | License along with this library; if not, write to the Free Software 21 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | 23 | */ 24 | 25 | 26 | 27 | ///////////// 28 | //Rank(B,i)// 29 | ///////////// 30 | //_factor = 0 => s=W*lgn 31 | //_factor = P => s=W*P 32 | //Is interesting to notice 33 | //factor=2 => overhead 50% 34 | //factor=3 => overhead 33% 35 | //factor=4 => overhead 25% 36 | //factor=20=> overhead 5% 37 | 38 | typedef struct sbitRankW32Int{ 39 | uint *data; 40 | char owner; 41 | uint integers; 42 | uint factor,b,s; 43 | uint *Rs; //superblock array 44 | uint n; 45 | } bitRankW32Int; 46 | //uso interno para contruir el indice rank 47 | uint buildRankSub(bitRankW32Int * br,uint ini,uint fin); 48 | void buildRank(bitRankW32Int * br); //crea indice para rank 49 | 50 | bitRankW32Int * createBitRankW32Int(uint *bitarray, uint n, char owner, uint factor); 51 | void destroyBitRankW32Int(bitRankW32Int * br); //destructor 52 | uint isBitSet(bitRankW32Int * br, uint i); 53 | uint rank(bitRankW32Int * br, uint i); //Nivel 1 bin, nivel 2 sec-pop y nivel 3 sec-bit 54 | uint lenght_in_bits(bitRankW32Int * br); 55 | uint prev(bitRankW32Int * br, uint start); // gives the largest index i<=start such that IsBitSet(i)=true 56 | uint bselect(bitRankW32Int * br, uint x); // gives the position of the x:th 1. 57 | uint select0(bitRankW32Int * br, uint x); // gives the position of the x:th 0. 58 | uint select1(bitRankW32Int * br, uint x); // gives the position of the x:th 1. 59 | uint spaceRequirementInBits(bitRankW32Int * br); 60 | /*load-save functions*/ 61 | int save(bitRankW32Int * br, FILE *f); 62 | int load(bitRankW32Int * br, FILE *f); 63 | bitRankW32Int * createBitRankW32IntFile(FILE *f, int *error); 64 | 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /implementations/k2tree/kTree.h: -------------------------------------------------------------------------------- 1 | #ifndef KTREE_H 2 | #define KTREE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include "bitrankw32int.h" 8 | #include "basic.h" 9 | #define MAX_INFO 1024*1024+10 10 | 11 | 12 | 13 | typedef struct matrixRep 14 | { 15 | bitRankW32Int * btl; //Bitmap representando T:L 16 | uint btl_len; //Numero de bits de T:L 17 | uint bt_len; //Numero de bits de T 18 | int maxLevel; //Nivel maximo del arbol 19 | uint numberOfNodes; 20 | ulong numberOfEdges; 21 | uint * div_level_table; 22 | uint * info; 23 | uint * info2[2]; 24 | uint * element; 25 | uint * basex; 26 | uint * basey; 27 | int iniq; 28 | int finq; 29 | }MREP; 30 | 31 | 32 | #define K 2 33 | 34 | MREP * compactCreateKTree(uint * xedges, uint *yedges, uint numberOfNodes,ulong numberOfEdges, uint maxl); 35 | 36 | 37 | uint * compactAdjacencyList(MREP * rep, int x); 38 | uint * compact2AdjacencyList(MREP * rep, int x); 39 | uint * compactInverseList(MREP * rep, int y); 40 | uint ** compactRangeQuery(MREP * rep, uint p1, uint p2, uint q1, uint q2); 41 | uint compactCheckLinkQuery(MREP * rep, uint p, uint q); 42 | uint compact2CheckLinkQuery(MREP * rep, uint p, uint q); 43 | uint compactCheckRangeQuery(MREP * rep, uint p1, uint p2, uint q1, uint q2); 44 | 45 | int * compactFullDecompression(MREP * rep); 46 | 47 | MREP * loadRepresentation(char * basename); 48 | void saveRepresentation(MREP * rep, char * basename); 49 | void destroyRepresentation(MREP * rep); 50 | 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /implementations/k2tree/kt_buildTree.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "kTree.h" 5 | 6 | 7 | 8 | int main(int argc, char* argv[]){ 9 | FILE *f; 10 | uint nodes; 11 | ulong edges; 12 | register ulong i; 13 | 14 | 15 | 16 | if(argc<3){ 17 | fprintf(stderr,"USAGE: %s \n",argv[0]); 18 | return(-1); 19 | } 20 | 21 | 22 | f = fopen(argv[1],"r"); 23 | fread(&nodes,sizeof(uint),1,f); 24 | 25 | printf("> #nodes:\t%u\n", nodes); 26 | 27 | 28 | uint max_level = floor(log(nodes)/log(K)); 29 | if(floor(log(nodes)/log(K))==(log(nodes)/log(K))) { 30 | max_level=max_level-1; 31 | } 32 | fread(&edges,sizeof(ulong),1,f); 33 | uint nodes_read=0; 34 | 35 | printf("> #edges:\t%lu\n", edges); 36 | 37 | 38 | 39 | uint *xedges = (uint *)malloc(sizeof(uint)*edges); 40 | uint *yedges = (uint *)malloc(sizeof(uint)*edges); 41 | uint cedg = 0; 42 | for(i=0;iinfo = (uint *)malloc(sizeof(uint)*MAX_INFO); 63 | rep->element = (uint *)malloc(sizeof(uint)*MAX_INFO); 64 | rep->basex = (uint *)malloc(sizeof(uint)*MAX_INFO); 65 | rep->basey = (uint *)malloc(sizeof(uint)*MAX_INFO); 66 | rep->iniq = -1; 67 | rep->finq =-1; 68 | rep->div_level_table = (uint *)malloc(sizeof(uint)*rep->maxLevel); 69 | for(i=0;imaxLevel;i++) 70 | rep->div_level_table[i]=exp_pow(K,rep->maxLevel-i); 71 | */ 72 | 73 | saveRepresentation(rep,argv[2]); 74 | destroyRepresentation(rep); 75 | 76 | free(xedges); 77 | free(yedges); 78 | fclose(f); 79 | return 0; 80 | } 81 | 82 | 83 | -------------------------------------------------------------------------------- /implementations/k2tree/kt_decompressTree.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "kTree.h" 5 | 6 | 7 | 8 | int main(int argc, char* argv[]){ 9 | 10 | if(argc<3){ 11 | fprintf(stderr,"USAGE: %s \n",argv[0]); 12 | return(-1); 13 | } 14 | 15 | char *filename = (char *)malloc(sizeof(char)*(strlen(argv[1])+10)); 16 | MREP * rep = loadRepresentation(argv[1]); 17 | 18 | strcpy(filename,argv[2]); 19 | strcat(filename,".rbfull"); 20 | FILE *fr = fopen(filename,"w"); 21 | fwrite(&(rep->numberOfNodes),sizeof(uint),1,fr); 22 | fwrite(&(rep->numberOfEdges),sizeof(ulong),1,fr); 23 | 24 | int * listady; 25 | listady = (int *) compactFullDecompression(rep); 26 | 27 | fwrite(listady,sizeof(int),rep->numberOfNodes+rep->numberOfEdges,fr); 28 | 29 | fclose(fr); 30 | printf("%s\n", filename); 31 | destroyRepresentation(rep); 32 | free(filename); 33 | free(listady); 34 | return 0; 35 | } -------------------------------------------------------------------------------- /implementations/k2tree/kt_fromList.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "kTree.h" 4 | #include "adylist.h" 5 | 6 | 7 | int main(int argc, char* argv[]){ 8 | uint nodes; 9 | ulong edges; 10 | register ulong i; 11 | 12 | if(argc<3){ 13 | fprintf(stderr,"USAGE: %s \n",argv[0]); 14 | return(-1); 15 | } 16 | 17 | 18 | ALREP * lista = (ALREP *) loadAdyacencyList(argv[1]); 19 | nodes = lista->numNodes; 20 | edges = lista->numEdges; 21 | 22 | uint max_level = floor(log(nodes)/log(K)); 23 | if(floor(log(nodes)/log(K))==(log(nodes)/log(K))) { 24 | max_level=max_level-1; 25 | } 26 | 27 | uint nodes_read=0; 28 | uint *xedges = (uint *)malloc(sizeof(uint)*edges); 29 | uint *yedges = (uint *)malloc(sizeof(uint)*edges); 30 | uint cedg = 0; 31 | int k; 32 | for(i=0;ilistady[i]; 34 | if(k<0) { 35 | nodes_read++; 36 | } 37 | else { 38 | k--; 39 | xedges[cedg]=nodes_read-1; 40 | yedges[cedg]=k; 41 | cedg++; 42 | } 43 | } 44 | 45 | MREP * rep; 46 | 47 | rep = compactCreateKTree(xedges, yedges, nodes,edges,max_level); 48 | saveRepresentation(rep,argv[2]); 49 | 50 | destroyAdyacencyList(lista); 51 | destroyRepresentation(rep); 52 | 53 | free(xedges); 54 | free(yedges); 55 | 56 | return 0; 57 | } 58 | 59 | 60 | -------------------------------------------------------------------------------- /implementations/k2tree/kt_getCell.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "kTree.h" 4 | 5 | int main(int argc, char * argv[]){ 6 | setbuf(stdin, NULL); 7 | if(argc<4){ 8 | fprintf(stderr,"USAGE: %s \n",argv[0]); 9 | return(-1); 10 | } 11 | 12 | MREP * rep = loadRepresentation(argv[1]); 13 | 14 | int idOrigen = atoi(argv[2]); 15 | int idDestino = atoi(argv[3]); 16 | 17 | uint resp = compact2CheckLinkQuery(rep, idOrigen, idDestino); 18 | printf("%u\n", resp); 19 | 20 | destroyRepresentation(rep); 21 | 22 | return 0; 23 | } -------------------------------------------------------------------------------- /implementations/k2tree/kt_getNeightbors.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "kTree.h" 4 | 5 | int main(int argc, char * argv[]){ 6 | setbuf(stdin, NULL); 7 | if(argc<3){ 8 | fprintf(stderr,"USAGE: %s \n",argv[0]); 9 | return(-1); 10 | } 11 | MREP * rep = loadRepresentation(argv[1]); 12 | 13 | uint i; 14 | int idNodo = atoi(argv[2]); 15 | uint * listady; 16 | 17 | printf("> Neighbor of: %u\n", idNodo); 18 | 19 | listady = compact2AdjacencyList(rep, idNodo); 20 | printf("(%u)\t", listady[0]); 21 | for(i=0; i 2 | #include 3 | #include "kTree.h" 4 | 5 | int main(int argc, char * argv[]){ 6 | setbuf(stdin, NULL); 7 | if(argc<6){ 8 | fprintf(stderr,"USAGE: %s \n",argv[0]); 9 | return(-1); 10 | } 11 | 12 | MREP * rep = loadRepresentation(argv[1]); 13 | 14 | uint p1=atoi(argv[2]); 15 | uint p2=atoi(argv[3]); 16 | uint q1=atoi(argv[4]); 17 | uint q2=atoi(argv[5]); 18 | 19 | uint ** respuesta = compactRangeQuery(rep, p1, p2, q1, q2); 20 | 21 | printf("Range: [%d,%d]-[%d,%d], total of links %d\n",p1,p2,q1,q2,respuesta[0][0]); 22 | uint i = respuesta[0][0]; 23 | for(i=0;i 2 | #include 3 | #include "kTree.h" 4 | 5 | int main(int argc, char * argv[]){ 6 | setbuf(stdin, NULL); 7 | if(argc<3){ 8 | fprintf(stderr,"USAGE: %s \n",argv[0]); 9 | return(-1); 10 | } 11 | MREP * rep = loadRepresentation(argv[1]); 12 | uint i; 13 | int idNodo = atoi(argv[2]); 14 | uint * listady; 15 | listady = compactInverseList(rep, idNodo); 16 | printf("(%u)\t", listady[0]); 17 | for(i=0; i 2 | #include 3 | #include "Queue.h" 4 | #include "misBits.h" 5 | #include "kTree.h" 6 | 7 | /* 8 | Implementado con la última versión del BitMap que desplaza para concatenar. 9 | */ 10 | 11 | 12 | MREP * createFromBitmap(misBits * C, int maximalLevel, ulong numNodos, ulong numEdges); 13 | MREP * k2tree_union(MREP * repA, MREP * repB); 14 | MREP * k2tree_symmetricdifference(MREP * repA, MREP * repB); 15 | MREP * k2tree_intersection(MREP * repA, MREP * repB); 16 | MREP * k2tree_difference(MREP * repA, MREP * repB); 17 | MREP * k2tree_complement(MREP * repA); -------------------------------------------------------------------------------- /implementations/k2tree/kt_setop_complement.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "kt_setOperations.h" 3 | 4 | int main(int argc, char * argv[]){ 5 | if(argc < 3){ 6 | fprintf(stderr,"USAGE: %s \n", argv[0]); 7 | return(-1); 8 | } 9 | 10 | /* 11 | setbuf(stdout, NULL); 12 | */ 13 | 14 | MREP * repA = loadRepresentation(argv[1]); 15 | MREP * result = k2tree_complement(repA); 16 | 17 | if(result == NULL){ 18 | printf("Fallo en la operación.\n"); 19 | return -1; 20 | } 21 | 22 | destroyRepresentation(repA); 23 | saveRepresentation(result, argv[2]); 24 | destroyRepresentation(result); 25 | return 0; 26 | } 27 | 28 | /* 29 | 30 | 31 | int main(int argc, char * argv[]){ 32 | if(argc < 3){ 33 | fprintf(stderr,"USAGE: %s \n", argv[0]); 34 | return(-1); 35 | } 36 | 37 | // BBOORRAARR 38 | setbuf(stdout, NULL); 39 | // BBOORRAARR 40 | 41 | MREP * repA = loadRepresentation(argv[1]); 42 | 43 | //uint maximalNodes; 44 | uint maximalLevel = repA->maxLevel; 45 | 46 | ulong * pRepA = posByLevel(repA); 47 | 48 | ulong * minBits = (ulong *) malloc(sizeof(ulong) * (maximalLevel+1)); 49 | if(minBits == NULL){ 50 | printf("Error en la reserva de memoria.\n"); 51 | return (-1); 52 | } 53 | // Para el complemento, el peor caso es generar como resultado de la 54 | // operación una representación que no compacte sectores 55 | // Por lo que se reserva el espacio necesario para una representación completa 56 | 57 | ulong i, auxNodes = K*K; 58 | for(i=0; i<=maximalLevel; i++){ 59 | minBits[i] = auxNodes; 60 | //maximalNodes+=minBits[i]; 61 | auxNodes = auxNodes * (K*K); 62 | } 63 | 64 | misBits * C = nuevoBitMap(maximalLevel+1, minBits); 65 | if(C == NULL){ 66 | printf("Error en la reserva de memoria.\n"); 67 | return (-1); 68 | } 69 | 70 | // Variable para calcular el número de vínculos dentro de la operación. 71 | ulong limiteSuperior = repA->div_level_table[0] * 2 - 1; 72 | ulong limits[4] = {0, limiteSuperior, 0, limiteSuperior}; 73 | 74 | complementOperation(0u, repA, pRepA, C, limits); 75 | ulong vinculolos = concatenar(C); 76 | ulong numNodos = repA->numberOfNodes; 77 | destroyRepresentation(repA); 78 | saveOperation(C, maximalLevel, argv[2], numNodos, vinculolos); 79 | return 0; 80 | } 81 | */ -------------------------------------------------------------------------------- /implementations/k2tree/kt_setop_difference.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "kt_setOperations.h" 3 | 4 | int main(int argc, char * argv[]){ 5 | if(argc < 4){ 6 | fprintf(stderr,"USAGE: %s \n", argv[0]); 7 | return(-1); 8 | } 9 | 10 | MREP * repA = loadRepresentation(argv[1]); 11 | MREP * repB = loadRepresentation(argv[2]); 12 | MREP * result = k2tree_difference(repA, repB); 13 | 14 | if(result == NULL){ 15 | printf("Fallo en la operación.\n"); 16 | return -1; 17 | } 18 | 19 | destroyRepresentation(repA); 20 | destroyRepresentation(repB); 21 | saveRepresentation(result, argv[3]); 22 | destroyRepresentation(result); 23 | return 0; 24 | } 25 | 26 | /* 27 | RESPALDO... PREVIO A LA IMPLEMENTACIÓN DE LAS FUNCIONES CON DOS/UN PARAMETROS Y RETORNAN MREP 28 | 29 | int main(int argc, char * argv[]){ 30 | if(argc < 4){ 31 | fprintf(stderr,"USAGE: %s \n", argv[0]); 32 | return(-1); 33 | } 34 | 35 | MREP * repA = loadRepresentation(argv[1]); 36 | MREP * repB = loadRepresentation(argv[2]); 37 | 38 | ulong maximalBits = repA->btl_len; 39 | uint maximalLevel = repA->maxLevel; 40 | 41 | ulong * pRepA = posByLevel(repA); 42 | ulong * pRepB = posByLevel(repB); 43 | 44 | ulong * minBits = (ulong *) malloc(sizeof(ulong)*(maximalLevel+1)); 45 | if(minBits == NULL){ 46 | printf("Error en la reserva de memoria.\n"); 47 | return (-1); 48 | } 49 | // En la diferencia, la reserva de espacio debe ser suficiente para almacenar 50 | // la representación completa del primer k2-tree, ya que podrían no tener 51 | // elementos en común. 52 | uint i; 53 | for(i=0; i<=maximalLevel; i++){ 54 | minBits[i] = pRepA[i+1] - pRepA[i]; 55 | } 56 | minBits[maximalLevel] = maximalBits - pRepA[maximalLevel]; 57 | 58 | misBits * C = nuevoBitMap(maximalLevel+1, minBits); 59 | if(C == NULL){ 60 | printf("Error en la reserva de memoria.\n"); 61 | return (-1); 62 | } 63 | 64 | differenceOperation(0u, repA, repB, pRepA, pRepB, C); 65 | ulong vinculolos = concatenar(C); 66 | ulong numNodos = repA->numberOfNodes; 67 | 68 | destroyRepresentation(repA); 69 | destroyRepresentation(repB); 70 | 71 | saveOperation(C, maximalLevel, argv[3], numNodos, vinculolos); 72 | return 0; 73 | } 74 | */ -------------------------------------------------------------------------------- /implementations/k2tree/kt_setop_intersection.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "kt_setOperations.h" 3 | 4 | int main(int argc, char * argv[]){ 5 | if(argc < 4){ 6 | fprintf(stderr,"USAGE: %s \n", argv[0]); 7 | return(-1); 8 | } 9 | 10 | /* 11 | setbuf(stdout, NULL); 12 | */ 13 | 14 | MREP * repA = loadRepresentation(argv[1]); 15 | MREP * repB = loadRepresentation(argv[2]); 16 | MREP * result = k2tree_intersection(repA, repB); 17 | 18 | if(result == NULL){ 19 | printf("Fallo en la operación.\n"); 20 | return -1; 21 | } 22 | 23 | destroyRepresentation(repA); 24 | destroyRepresentation(repB); 25 | saveRepresentation(result, argv[3]); 26 | destroyRepresentation(result); 27 | return 0; 28 | } 29 | 30 | /* 31 | RESPALDO... PREVIO A LA IMPLEMENTACIÓN DE LAS FUNCIONES CON DOS/UN PARAMETROS Y RETORNAN MREP 32 | 33 | int main(int argc, char * argv[]){ 34 | if(argc < 4){ 35 | fprintf(stderr,"USAGE: %s \n", argv[0]); 36 | return(-1); 37 | } 38 | 39 | // BBOORRAARR 40 | setbuf(stdout, NULL); 41 | // BBOORRAARR 42 | 43 | MREP * repA = loadRepresentation(argv[1]); 44 | MREP * repB = loadRepresentation(argv[2]); 45 | uint maximalLevel = repA->maxLevel; 46 | 47 | ulong * pRepA = posByLevel(repA); 48 | ulong * pRepB = posByLevel(repB); 49 | 50 | ulong * minBits = (ulong *) malloc(sizeof(ulong)*(maximalLevel+1)); 51 | if(minBits == NULL){ 52 | printf("Se ha generado un problema...\n"); 53 | return 0; 54 | } 55 | // La intersección podría tener a lo más, tantas celdas activas 56 | // como las que posee el menor de los dos elementos operados. 57 | 58 | ulong numBitsByLevelA, numBitsByLevelB; 59 | uint i; 60 | for(i = 0; i <= maximalLevel; i++){ 61 | // printf("%d/%d\t", i,maximalLevel); 62 | if(i==repA->maxLevel){ 63 | // printf("a \t"); 64 | numBitsByLevelA = repA->btl_len - pRepA[i]; 65 | numBitsByLevelB = repB->btl_len - pRepB[i]; 66 | // printf("b \n"); 67 | }else{ 68 | // printf("A \t"); 69 | numBitsByLevelA = pRepA[i+1] - pRepA[i]; 70 | numBitsByLevelB = pRepB[i+1] - pRepB[i]; 71 | // printf("B \n"); 72 | } 73 | // printf("X \t"); 74 | // printf("minBitsA: %d\t\tminBitsB: %d\t\t", numBitsByLevelA, numBitsByLevelB); 75 | minBits[i] = (numBitsByLevelA > numBitsByLevelB)?numBitsByLevelB:numBitsByLevelA; 76 | // printf("X \t"); 77 | // printf("minBits[%d] = %d\n", i, minBits[i]); 78 | // printf("-------\n"); 79 | } 80 | 81 | // printf("nuevoBitMap inicio\n"); 82 | misBits * C = nuevoBitMap(maximalLevel+1, minBits); 83 | if(C == NULL){ 84 | printf("Error en la reserva de memoria.\n"); 85 | return (-1); 86 | } 87 | intersectionOperation(0u, repA, repB, pRepA, pRepB, C); 88 | ulong vinculolos = concatenar(C); 89 | ulong numNodos = repA->numberOfNodes; 90 | 91 | destroyRepresentation(repA); 92 | destroyRepresentation(repB); 93 | 94 | saveOperation(C, maximalLevel, argv[3], numNodos, vinculolos); 95 | return 0; 96 | } 97 | */ -------------------------------------------------------------------------------- /implementations/k2tree/kt_setop_symmdiff.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "kt_setOperations.h" 3 | 4 | int main(int argc, char * argv[]){ 5 | if(argc < 4){ 6 | fprintf(stderr,"USAGE: %s \n", argv[0]); 7 | return(-1); 8 | } 9 | 10 | MREP * repA = loadRepresentation(argv[1]); 11 | MREP * repB = loadRepresentation(argv[2]); 12 | 13 | MREP * result = k2tree_symmetricdifference(repA, repB); 14 | 15 | if(result == NULL){ 16 | printf("Fallo en la operación.\n"); 17 | return -1; 18 | } 19 | 20 | destroyRepresentation(repA); 21 | destroyRepresentation(repB); 22 | saveRepresentation(result, argv[3]); 23 | return 0; 24 | } 25 | 26 | /* 27 | RESPALDO... PREVIO A LA IMPLEMENTACIÓN DE LAS FUNCIONES CON DOS/UN PARAMETROS Y RETORNAN MREP 28 | 29 | int main(int argc, char * argv[]){ 30 | if(argc < 4){ 31 | fprintf(stderr,"USAGE: %s \n", argv[0]); 32 | return(-1); 33 | } 34 | 35 | MREP * repA = loadRepresentation(argv[1]); 36 | MREP * repB = loadRepresentation(argv[2]); 37 | 38 | //uint maximalNodes; 39 | uint maximalLevel = repA->maxLevel; 40 | 41 | ulong * pRepA = posByLevel(repA); 42 | ulong * pRepB = posByLevel(repB); 43 | 44 | ulong * minBits = (ulong *) malloc(sizeof(ulong)*(maximalLevel+1)); 45 | if(minBits == NULL){ 46 | printf("Error en la reserva de memoria.\n"); 47 | return (-1); 48 | } 49 | // En el peor de los casos (en términos de espacio), la diferencia simétrica podría 50 | // generar una representación completa de un grafo de k niveles, por lo que 51 | // se reserva todos los bits posibles en base a la cantidad de niveles. 52 | 53 | uint i; 54 | ulong auxNodes = K*K; 55 | for(i=0; i<=maximalLevel; i++){ 56 | minBits[i] = auxNodes; 57 | //maximalNodes+=minBits[i]; 58 | auxNodes = auxNodes * (K*K); 59 | } 60 | 61 | misBits * C = nuevoBitMap(maximalLevel+1, minBits); 62 | if(C == NULL){ 63 | printf("Error en la reserva de memoria.\n"); 64 | return (-1); 65 | } 66 | 67 | symmetricDifferenceOperation(0u, repA, repB, pRepA, pRepB, C); 68 | ulong vinculolos = concatenar(C); 69 | ulong numNodos = repA->numberOfNodes; 70 | 71 | destroyRepresentation(repA); 72 | destroyRepresentation(repB); 73 | 74 | saveOperation(C, maximalLevel, argv[3], numNodos, vinculolos); 75 | return 0; 76 | } 77 | */ -------------------------------------------------------------------------------- /implementations/k2tree/kt_setop_union.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "kt_setOperations.h" 3 | 4 | int main(int argc, char * argv[]){ 5 | if(argc < 4){ 6 | fprintf(stderr,"USAGE: %s \n", argv[0]); 7 | return(-1); 8 | } 9 | 10 | MREP * repA = loadRepresentation(argv[1]); 11 | MREP * repB = loadRepresentation(argv[2]); 12 | MREP * result = k2tree_union(repA, repB); 13 | 14 | if(result == NULL){ 15 | printf("Operación de unión finalizada..\n"); 16 | return -1; 17 | } 18 | 19 | saveRepresentation(result, argv[3]); 20 | destroyRepresentation(repA); 21 | destroyRepresentation(repB); 22 | destroyRepresentation(result); 23 | return 0; 24 | } 25 | 26 | 27 | /* 28 | RESPALDO... PREVIO A LA IMPLEMENTACIÓN DE LAS FUNCIONES CON DOS/UN PARAMETROS Y RETORNAN MREP 29 | 30 | int main(int argc, char * argv[]){ 31 | if(argc < 4){ 32 | fprintf(stderr,"USAGE: %s \n", argv[0]); 33 | return(-1); 34 | } 35 | 36 | MREP * repA = loadRepresentation(argv[1]); 37 | MREP * repB = loadRepresentation(argv[2]); 38 | 39 | uint maximalLevel = repA->maxLevel; 40 | 41 | ulong i = 0, maximalBits = 0, calculador = 1; 42 | 43 | for(i = 0; i <= maximalLevel; i++){ 44 | calculador *= (K*K); 45 | maximalBits += calculador; 46 | } 47 | 48 | ulong minBits[] = {maximalBits}; 49 | // En la unión, el peor de los casos corresponde a generar una 50 | // representación completa de un k2-tree, sin sectores en 0. 51 | 52 | misBits * C = nuevoBitMap(1u, minBits); 53 | if(C == NULL){ 54 | printf("Error en la reserva de memoria.\n"); 55 | return (-1); 56 | } 57 | 58 | ulong numEdges = unionOperation(repA, repB, C); 59 | concatenar(C); 60 | ulong numNodos = repA->numberOfNodes; 61 | 62 | destroyRepresentation(repA); 63 | destroyRepresentation(repB); 64 | 65 | saveOperation(C, maximalLevel, argv[3], numNodos, numEdges); 66 | return 0; 67 | } 68 | */ -------------------------------------------------------------------------------- /implementations/k2tree/kt_toList.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "kTree.h" 3 | #include "adylist.h" 4 | 5 | 6 | 7 | int main(int argc, char* argv[]){ 8 | if(argc<3){ 9 | fprintf(stderr,"USAGE: %s \n",argv[0]); 10 | return(-1); 11 | } 12 | 13 | MREP * rep = loadRepresentation(argv[1]); 14 | int * listady; 15 | listady = (int *) compactFullDecompression(rep); 16 | 17 | ALREP * adyList = (ALREP *) malloc(sizeof(struct adyList)); 18 | adyList->numNodes = rep->numberOfNodes; 19 | adyList->numEdges = rep->numberOfEdges; 20 | adyList->listady = listady; 21 | 22 | saveAdyacencyList(adyList, argv[2]); 23 | 24 | destroyAdyacencyList(adyList); 25 | destroyRepresentation(rep); 26 | return 0; 27 | } -------------------------------------------------------------------------------- /implementations/k2tree/misBits.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include "basic.h" 3 | 4 | /* 5 | ** Esta estructura permite crear un bitmap segmentado que puede ser completado 6 | ** de manera independiente según nivel/segmento. 7 | ** La concatenación reúne todos segmentos de bits en uno solo segmento, transformandolo a un nivel. 8 | ** Esto evita crear un bitmap por nivel y posteriormente otro 9 | ** capaz de contener los bits de todos los niveles. (Lo que duplicaría la información.) 10 | */ 11 | 12 | typedef struct MISBITS{ 13 | ulong * pos; // Posiciones de inicio para cada nivel del bitmap 14 | ulong * n; // Número de elementos de cada nivel del bitmap 15 | uint niveles; // Cantidad de niveles del bitmap 16 | ulong tam; // Tamaño del bitmap (Capacidad) 17 | ulong cant; // Número de elementos totales del bitmap 18 | ulong numEdges; // Número de 1s al último nivel del bitmap 19 | uint * bitsm; 20 | } misBits; 21 | 22 | misBits* nuevoBitMap(uint levels, ulong * cants); 23 | // Crea una nueva instancia de misBits con niveles y cantidad de elementos por nivel 24 | 25 | void setBit(misBits* bitses, uint level, uint cont); 26 | // Inserta el bit al final de la cadena según el nivel en . 27 | 28 | void bitSeter(misBits* bitses, uint level, ulong i); 29 | // Asigna un valor 1 al i-ésimo bit en el nivel sin manipular cant de 30 | // ni tampoco manipula n. 31 | 32 | uint isBitSeted(misBits* bitses, uint level, ulong i); 33 | // Retorna el contenido del i-ésimo bit (0 o 1) en el nivel . 34 | 35 | void destruirBitMap(misBits* bitses); 36 | // Destruye la estructura A EXCEPCIÓN DE bitses->bitsm que se deja para construir bitmaps. 37 | 38 | void destruirTodoBitmap(misBits* bitses); 39 | // Destruyte TODA la estructura. 40 | 41 | ulong concatenar(misBits* bitses); 42 | // Concatena los bits de todos los niveles en un bitmap de un nivel y lo retorna. 43 | // Modifica los valores de level y tam. 44 | // Libera pos y n 45 | 46 | void prepararBitmap(misBits* bitses, int objectsBRWT,uint numNodes); 47 | // Ordena el bitmap de un BRWTREP desplazando los elementos de los nodos hacia la izquierda 48 | // Esto debido a que la CONSTRUCCIÓN genera los vínculos dejando espacios en el bitmap 49 | // Esta función se DEBE invocar previo a la concatenación cuando se construye el bitmap. -------------------------------------------------------------------------------- /implementations/k2tree/pair.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "pair.h" 3 | 4 | PAIR newPair(uint a, uint b){ 5 | PAIR pair; 6 | pair.a = a; 7 | pair.b = b; 8 | return pair; 9 | } -------------------------------------------------------------------------------- /implementations/k2tree/pair.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include "basic.h" 3 | 4 | typedef struct Pair{ 5 | char a; 6 | char b; 7 | }PAIR; 8 | 9 | PAIR newPair(uint a, uint b); -------------------------------------------------------------------------------- /implementations/k2trie/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | 3 | project 4 | 5 | *.exe -------------------------------------------------------------------------------- /implementations/k2trie/Makefile: -------------------------------------------------------------------------------- 1 | CPP=g++ 2 | 3 | OBJECTS=treeBlock.o 4 | 5 | BINS=project 6 | 7 | CPPFLAGS=-Wall -O9 -DNDEBUG 8 | 9 | # How to check the invoking target when calling make: 10 | # https://www.gnu.org/software/make/manual/html_node/Goals.html 11 | ifeq ($(MAKECMDGOALS),debug) 12 | CPPFLAGS=-Wall -g -DDEBUGGING 13 | endif 14 | 15 | DEST=. 16 | 17 | %.o: %.c 18 | $(CPP) $(CPPFLAGS) -c $< -o $@ 19 | 20 | all: clean bin 21 | 22 | debug: clean bin 23 | 24 | bin: $(OBJECTS) $(BINS) 25 | 26 | project: 27 | $(CPP) $(CPPFLAGS) -o $(DEST)/project main.cpp $(OBJECTS) -lm 28 | 29 | clean: 30 | rm -f project *.o 31 | -------------------------------------------------------------------------------- /implementations/k2trie/README.md: -------------------------------------------------------------------------------- 1 | # k2trie graph data structure 2 | 3 | ## Description 4 | 5 | This directory contains the source-code of the **k2trie**, the dynamic *k*2-trie structure described in the paper [Faster Dynamic Compressed d-ary Relations](https://doi.org/10.1007/978-3-030-32686-9_30), 6 | by Diego Arroyuelo, Guillermo de Bernardo, Travis Gagie and Gonzalo Navarro (2019). 7 | 8 | ## Usage examples 9 | 10 | make 11 | 12 | ./project 96 96 1024 8 10 0.99 257 < ../../datasets/dataset-adds-checks.tsv 13 | 14 | Got 96 96 1024, 8 10, 0.990000, 257, 9 15 | 1 16 | 1 17 | 1 18 | 1 19 | 1 20 | 1 21 | 1 22 | 1 23 | 1 24 | 1 25 | 1 26 | 0 27 | > Exiting. 28 | Loop time: 86.000000 29 | 30 | #### Argument info: 31 | # 96 - S1: Currently not in use 32 | # 96 - S2: Default size for blocks at depths between L1 and L2 33 | # 1024 - S3: Default size for blocks at depths higher than L2 34 | # 8 - L1: Maximum depth for pointer-based trie (the trie uses pointers up to this depth). The code assumes that at least L1 levels exist 35 | # 10 - L2: Depth separating block sizes S2 and S3 36 | # 0.99 - Alpha: Node filling rate 37 | # 257 - Number of nodes in the graph 38 | # Assumptions: S3 > S2, L2 > L1, L1 < log(nNodes) 39 | ## For more information on these parameters, check 40 | ## [Faster Dynamic Compressed d-ary Relations] 41 | ## (https://doi.org/10.1007/978-3-030-32686-9_30) 42 | # ../../datasets/dataset-adds-lists.tsv - path to a graph operations file with 43 | edge additions followed by listings 44 | -------------------------------------------------------------------------------- /implementations/sdk2tree/.gitignore: -------------------------------------------------------------------------------- 1 | adylist_setop_complement 2 | adylist_setop_difference 3 | adylist_setop_intersection 4 | adylist_setop_symmdiff 5 | adylist_setop_union 6 | kt_buildTree 7 | kt_decompressTree 8 | kt_fromList 9 | kt_getCell 10 | kt_getNeightbors 11 | kt_getRange 12 | kt_getReverseNeightbors 13 | kt_setop_complement 14 | kt_setop_difference 15 | kt_setop_intersection 16 | kt_setop_symmdiff 17 | kt_setop_union 18 | kt_toList 19 | project 20 | 21 | *.exe 22 | 23 | *.o -------------------------------------------------------------------------------- /implementations/sdk2tree/Entry.c: -------------------------------------------------------------------------------- 1 | #include "Entry.h" 2 | 3 | inline unsigned char getLevel(ENTRY e) { 4 | return e.e >>2; 5 | } 6 | 7 | inline unsigned char getRa(ENTRY e) { 8 | return (e.e & 0x02)>>1; 9 | } 10 | 11 | inline unsigned char getRb(ENTRY e) { 12 | return e.e & 0x01; 13 | } 14 | 15 | inline ENTRY setEntry(unsigned char l, unsigned char ra, unsigned char rb) { 16 | ENTRY e ; 17 | e.e = (unsigned char) (l<<2) + (ra<<1) + (rb); 18 | return e; 19 | } 20 | -------------------------------------------------------------------------------- /implementations/sdk2tree/Entry.h: -------------------------------------------------------------------------------- 1 | #include 2 | typedef struct entry 3 | { 4 | /**************************** 5 | * b b b b b b b b * 6 | * -----l----- Ra Rb * 7 | ***************************** 8 | */ 9 | unsigned char e; 10 | }ENTRY; 11 | 12 | /* 13 | * Crea un objeto de tipo ENTRY 14 | */ 15 | ENTRY setEntry(unsigned char l, unsigned char ra, unsigned char rb); 16 | /* 17 | * obtiene el nivel 18 | */ 19 | unsigned char getLevel(ENTRY e); 20 | /* 21 | * obtiene Ra 22 | */ 23 | unsigned char getRa(ENTRY e); 24 | /* 25 | * obtiene Rb 26 | */ 27 | unsigned char getRb(ENTRY e); 28 | -------------------------------------------------------------------------------- /implementations/sdk2tree/Makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | 3 | OBJECTS=basic.o bitrankw32int.o misBits.o adylist.o adylist_setOperations.o\ 4 | pair.o kTree.o Entry.o NodeQueue.o Queue.o kt_setOperations.o 5 | 6 | BINS=kt_decompressTree kt_buildTree kt_toList kt_fromList\ 7 | kt_setop_union kt_setop_intersection kt_setop_difference kt_setop_symmdiff kt_setop_complement\ 8 | kt_getCell kt_getNeightbors kt_getReverseNeightbors kt_getRange\ 9 | adylist_setop_union adylist_setop_intersection adylist_setop_difference adylist_setop_symmdiff adylist_setop_complement\ 10 | project 11 | 12 | CCFLAGS=-Wall -O9 -DNDEBUG 13 | 14 | # How to check the invoking target when calling make: 15 | # https://www.gnu.org/software/make/manual/html_node/Goals.html 16 | ifeq ($(MAKECMDGOALS),debug) 17 | CCFLAGS=-Wall -g -DDEBUGGING 18 | endif 19 | 20 | DEST=. 21 | 22 | %.o: %.c 23 | $(CC) $(CCFLAGS) -c $< -o $@ 24 | 25 | all: clean bin 26 | 27 | debug: clean bin 28 | 29 | bin: $(OBJECTS) $(BINS) 30 | 31 | project: $(OBJECTS) main.c 32 | $(CC) $(CCFLAGS) -o $(DEST)/project main.c $(OBJECTS) -lm 33 | 34 | adylist_setop_union: 35 | $(CC) $(CCFLAGS) -o $(DEST)/adylist_setop_union adylist_setop_union.c $(OBJECTS) -lm 36 | 37 | adylist_setop_intersection: 38 | $(CC) $(CCFLAGS) -o $(DEST)/adylist_setop_intersection adylist_setop_intersection.c $(OBJECTS) -lm 39 | 40 | adylist_setop_difference: 41 | $(CC) $(CCFLAGS) -o $(DEST)/adylist_setop_difference adylist_setop_difference.c $(OBJECTS) -lm 42 | 43 | adylist_setop_symmdiff: 44 | $(CC) $(CCFLAGS) -o $(DEST)/adylist_setop_symmdiff adylist_setop_symmdiff.c $(OBJECTS) -lm 45 | 46 | adylist_setop_complement: 47 | $(CC) $(CCFLAGS) -o $(DEST)/adylist_setop_complement adylist_setop_complement.c $(OBJECTS) -lm 48 | 49 | kt_decompressTree: 50 | $(CC) $(CCFLAGS) -o $(DEST)/kt_decompressTree kt_decompressTree.c $(OBJECTS) -lm 51 | 52 | kt_fromList: 53 | $(CC) $(CCFLAGS) -o $(DEST)/kt_fromList kt_fromList.c $(OBJECTS) -lm 54 | 55 | kt_toList: 56 | $(CC) $(CCFLAGS) -o $(DEST)/kt_toList kt_toList.c $(OBJECTS) -lm 57 | 58 | kt_buildTree: 59 | $(CC) $(CCFLAGS) -o $(DEST)/kt_buildTree kt_buildTree.c $(OBJECTS) -lm 60 | 61 | kt_setop_union: 62 | $(CC) $(CCFLAGS) -o $(DEST)/kt_setop_union kt_setop_union.c $(OBJECTS) -lm 63 | 64 | kt_setop_difference: 65 | $(CC) $(CCFLAGS) -o $(DEST)/kt_setop_difference kt_setop_difference.c $(OBJECTS) -lm 66 | 67 | kt_setop_intersection: 68 | $(CC) $(CCFLAGS) -o $(DEST)/kt_setop_intersection kt_setop_intersection.c $(OBJECTS) -lm 69 | 70 | kt_setop_symmdiff: 71 | $(CC) $(CCFLAGS) -o $(DEST)/kt_setop_symmdiff kt_setop_symmdiff.c $(OBJECTS) -lm 72 | 73 | kt_setop_complement: 74 | $(CC) $(CCFLAGS) -o $(DEST)/kt_setop_complement kt_setop_complement.c $(OBJECTS) -lm 75 | 76 | kt_getCell: 77 | $(CC) $(CCFLAGS) -o $(DEST)/kt_getCell kt_getCell.c $(OBJECTS) -lm 78 | 79 | kt_getNeightbors: 80 | $(CC) $(CCFLAGS) -o $(DEST)/kt_getNeightbors kt_getNeightbors.c $(OBJECTS) -lm 81 | 82 | kt_getReverseNeightbors: 83 | $(CC) $(CCFLAGS) -o $(DEST)/kt_getReverseNeightbors kt_getReverseNeightbors.c $(OBJECTS) -lm 84 | 85 | kt_getRange: 86 | $(CC) $(CCFLAGS) -o $(DEST)/kt_getRange kt_getRange.c $(OBJECTS) -lm 87 | 88 | clean: 89 | rm -f $(OBJECTS) $(BINS) 90 | cd $(DEST); rm -f *.a $(BINS) 91 | -------------------------------------------------------------------------------- /implementations/sdk2tree/NodeQueue.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "NodeQueue.h" 3 | #include 4 | 5 | 6 | NODEQUEUE * newNodeQueue(unsigned char s) { 7 | NODEQUEUE *n; 8 | n = (NODEQUEUE *) malloc(sizeof(NODEQUEUE)); 9 | n->t=s; 10 | n->r=0; 11 | n->f=0; 12 | n->u=0; 13 | n->e=(ENTRY *)malloc( n->t*sizeof(ENTRY)); 14 | n->next = NULL; 15 | return n; 16 | } 17 | 18 | int insertarEntry(NODEQUEUE * n, ENTRY nuevo){ 19 | if(estaLleno(n)){ 20 | return 0; 21 | } 22 | 23 | if(estaVacio(n)){ 24 | n->r = 0; 25 | n->f = 0; 26 | }else if(n->r +1 == n->t){ 27 | n->r = 0; 28 | }else{ 29 | n->r = n->r +1; 30 | } 31 | 32 | n->e[n->r] = nuevo; 33 | n->u = n->u +1; 34 | 35 | return 1; 36 | } 37 | 38 | ENTRY extraerEntry(NODEQUEUE * n){ 39 | ENTRY retorno = n->e[n->f]; 40 | 41 | if(n->f +1 == n->t){ 42 | n->f = 0; 43 | }else{ 44 | n->f = n->f +1; 45 | } 46 | n->u = n->u -1; 47 | 48 | return retorno; 49 | } 50 | 51 | unsigned char estaLleno(NODEQUEUE *n) { 52 | return (unsigned char) (n->u == n->t); 53 | } 54 | 55 | unsigned char estaVacio(NODEQUEUE *n) { 56 | return (unsigned char) (n->u == 0); 57 | } 58 | 59 | void destroyNodeQueue(NODEQUEUE *n){ 60 | free(n->e); 61 | free(n); 62 | return; 63 | } 64 | -------------------------------------------------------------------------------- /implementations/sdk2tree/NodeQueue.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Entry.h" 3 | 4 | typedef struct NodeQueue { 5 | unsigned char t; // Tamaño del nodo 6 | unsigned char f; // front dentro del nodo 7 | unsigned char r; // rear dentro del nodo 8 | unsigned char u; // numero de elementos en el nodo 9 | ENTRY *e; 10 | struct NodeQueue * next; 11 | } NODEQUEUE; 12 | 13 | NODEQUEUE * newNodeQueue(unsigned char size);// Crea un nuevo nodo 14 | int insertarEntry(NODEQUEUE * n, ENTRY nuevo); // Inserta un nuevo ENTRY en el nodo. Si retorna 0 falló la inserción. 15 | ENTRY extraerEntry(NODEQUEUE * n); 16 | unsigned char estaLleno(NODEQUEUE *n);// Verifica si un nodo está lleno 17 | unsigned char estaVacio(NODEQUEUE *n);// y si un nodo esta vacio 18 | void destroyNodeQueue(NODEQUEUE *n); //Elimina el NodeQueue -------------------------------------------------------------------------------- /implementations/sdk2tree/Queue.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Queue.h" 3 | #include 4 | 5 | /**************************************/ 6 | QUEUE * newQueue(unsigned int nodSiz) { 7 | QUEUE *q = (QUEUE *) malloc(sizeof(QUEUE)) ; 8 | q->nodeSize = nodSiz; 9 | q->cant = 0; 10 | q->front = newNodeQueue(nodSiz); 11 | q->rear = q->front; 12 | return q; 13 | } 14 | 15 | /************************************/ 16 | void Insert(QUEUE *q, ENTRY ent) { 17 | if(estaLleno(q->rear)) { 18 | //El Nodo rear esta lleno 19 | q->rear->next = newNodeQueue(q->nodeSize); 20 | q->rear = q->rear->next; 21 | } 22 | if(insertarEntry(q->rear, ent)); 23 | q->cant ++; 24 | } 25 | 26 | /*******************************/ 27 | ENTRY Delete(QUEUE *q) { 28 | ENTRY ee; 29 | if(q->cant > 0){ 30 | if(estaVacio(q->front)){ //El NodeQueue front está vacío y se debe trasladar 31 | NODEQUEUE* siguiente = q->front->next; 32 | destroyNodeQueue(q->front); 33 | q->front = siguiente; 34 | } 35 | ee = extraerEntry(q->front); 36 | q->cant --; 37 | } 38 | return ee; 39 | } 40 | 41 | /********************************/ 42 | int size(QUEUE *q) { 43 | int sz =0; 44 | NODEQUEUE *n; 45 | for (n=q->front; n!=NULL;n=n->next){ 46 | sz++; 47 | } 48 | return sz; 49 | } 50 | 51 | -------------------------------------------------------------------------------- /implementations/sdk2tree/Queue.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include "NodeQueue.h" 3 | 4 | typedef struct Queue { 5 | unsigned int nodeSize; //tamaño definido para los NodeQueue de Queue 6 | unsigned int cant; //cantidad de elementos contenidos hasta el momento. 7 | NODEQUEUE * front; // puntero a primer nodo de la cola 8 | NODEQUEUE * rear; // puntero al último nodo de la cola 9 | } QUEUE; 10 | 11 | QUEUE * newQueue(unsigned int nodeSize); // Crea una nueva cola. 12 | void Insert(QUEUE *q, ENTRY e); // Inserta un objeto a la cola 13 | ENTRY Delete(QUEUE *q); // elimina y devuelve un objeto de la cola 14 | int size(QUEUE *q); -------------------------------------------------------------------------------- /implementations/sdk2tree/README.md: -------------------------------------------------------------------------------- 1 | # sdk2tree graph data structure 2 | 3 | ## Description 4 | 5 | This directory contains the source-code of the **sdk2tree**, the dynamic *k*2-tree structure described in [On Dynamic Succinct Graph Representations](https://doi.org/10.1109/DCC47342.2020.00029), 6 | by Miguel E. Coimbra, Alexandre P. Francisco, Luís MS Russo, Guillermo De Bernardo, Susana Ladra and Gonzalo Navarro (2020). 7 | 8 | ## Usage examples 9 | 10 | make 11 | ./project 9 < ../../datasets/dataset-adds-lists.tsv 12 | 13 | Running dynamic k2tree (INESC-ID). 14 | N[0] ->2 15 | N[1] ->2 16 | N[2] ->1 17 | N[3] ->1 18 | N[4] ->1 19 | N[5] ->2 20 | N[6] ->1 21 | N[7] ->1 22 | N[8] ->0 23 | > Exiting. 24 | Loop time: 0.000203 25 | 26 | #### Argument info: 27 | # 9 - number of vertices 28 | # ../../datasets/dataset-adds-lists.tsv - path to a graph operations file with edge additions followed by listings 29 | -------------------------------------------------------------------------------- /implementations/sdk2tree/adylist.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "basic.h" 5 | 6 | typedef struct adyList{ 7 | uint numNodes; 8 | int* listady; 9 | ulong numEdges; 10 | }ALREP; 11 | 12 | ALREP * loadAdyacencyList(char * basename); 13 | void destroyAdyacencyList(ALREP * list); 14 | void saveAdyacencyList(ALREP * list, char * basename); 15 | 16 | uint adylist_getCell(ALREP * lista, uint p0, uint p1); 17 | uint * adylist_getNeightbors(ALREP * list, uint p0); 18 | uint * adylist_getRange(ALREP * lista, int p0, int p1, int q0, int q1); 19 | uint * adylist_getReverseNeightbors(ALREP * lista, uint p0); 20 | 21 | ulong * indexList(ALREP * list); -------------------------------------------------------------------------------- /implementations/sdk2tree/adylist_setOperations.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "basic.h" 4 | 5 | #ifndef adyList_h 6 | #define adyList_h 7 | #include "adylist.h" 8 | #endif 9 | 10 | ALREP * adylistUnionOperation(ALREP * A, ALREP * B); 11 | ALREP * adylistDifferenceOperation(ALREP * A, ALREP * B); 12 | ALREP * adylistIntersectionOperation(ALREP * A, ALREP * B); 13 | ALREP * adylistSymmetricDifferenceOperation(ALREP * A, ALREP * B); 14 | ALREP * adylistComplementOperation(ALREP * A); 15 | 16 | -------------------------------------------------------------------------------- /implementations/sdk2tree/adylist_setop_complement.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "adylist_setOperations.h" 3 | 4 | int main(int argc, char* argv[]){ 5 | if(argc<3){ 6 | fprintf(stderr,"USAGE: %s \n",argv[0]); 7 | return(-1); 8 | } 9 | /* 10 | char *filename = (char *) malloc(sizeof(char)*(strlen(argv[1])+8)); 11 | strcpy(filename,argv[1]); 12 | strcat(filename,".rbfull"); 13 | FILE * ft = fopen(filename,"r"); 14 | uint nodes; 15 | fread(&nodes,sizeof(uint),1,ft); 16 | ulong edges; 17 | fread(&edges,sizeof(ulong),1,ft); 18 | int* adyList = (int*)malloc(sizeof(int)*(edges+nodes)); 19 | fread(adyList,sizeof(int), nodes+edges,ft); 20 | fclose(ft); 21 | free(filename); 22 | */ 23 | 24 | ALREP * A = loadAdyacencyList(argv[1]); 25 | 26 | // Desplegando Lista de Adyacencia 27 | /* 28 | printf("Lista de Adyacencia de %s\n", argv[1]); 29 | printf("Nodes: %d\n", nodes); 30 | printf("Edges: %ld\n", edges); 31 | ulong i; 32 | for(i=0; i 2 | #include "adylist_setOperations.h" 3 | 4 | int main(int argc, char* argv[]){ 5 | 6 | if(argc<4){ 7 | fprintf(stderr,"USAGE: %s \n",argv[0]); 8 | return(-1); 9 | } 10 | 11 | // Cargando Lista de Adyacencia A 12 | /* 13 | char *filename = (char *) malloc(sizeof(char)*(strlen(argv[1])+8)); 14 | strcpy(filename,argv[1]); 15 | strcat(filename,".rbfull"); 16 | FILE * ft = fopen(filename,"r"); 17 | uint nodes; 18 | fread(&nodes,sizeof(uint),1,ft); 19 | ulong edgesA; 20 | fread(&edgesA,sizeof(ulong),1,ft); 21 | int* listadyA = (int*)malloc(sizeof(int)*(edgesA+nodes)); 22 | fread(listadyA,sizeof(int), nodes+edgesA,ft); 23 | fclose(ft); 24 | free(filename); 25 | */ 26 | ALREP * A = loadAdyacencyList(argv[1]); 27 | 28 | // Cargando Lista de Adyacencia B 29 | /* 30 | filename = (char *) malloc(sizeof(char)*(strlen(argv[1])+8)); 31 | strcpy(filename,argv[2]); 32 | strcat(filename,".rbfull"); 33 | ft = fopen(filename,"r"); 34 | uint nodesB; 35 | fread(&nodesB,sizeof(uint),1,ft); 36 | ulong edgesB; 37 | fread(&edgesB,sizeof(ulong),1,ft); 38 | int* listadyB = (int*)malloc(sizeof(int)*(edgesB+nodesB)); 39 | fread(listadyB,sizeof(int), nodesB+edgesB,ft); 40 | fclose(ft); 41 | free(filename); 42 | */ 43 | ALREP * B = loadAdyacencyList(argv[2]); 44 | // Desplegando A 45 | /* 46 | printf("Lista de Adyacencia de %s\n", argv[1]); 47 | printf("Nodes: %d\n", nodes); 48 | printf("Edges: %ld\n", edgesA); 49 | ulong i; 50 | for(i=0; i 2 | #include "adylist_setOperations.h" 3 | 4 | int main(int argc, char* argv[]){ 5 | 6 | if(argc<4){ 7 | fprintf(stderr,"USAGE: %s \n",argv[0]); 8 | return(-1); 9 | } 10 | 11 | // Cargando Lista de Adyacencia A 12 | /* 13 | char *filename = (char *) malloc(sizeof(char)*(strlen(argv[1])+8)); 14 | strcpy(filename,argv[1]); 15 | strcat(filename,".rbfull"); 16 | FILE * ft = fopen(filename,"r"); 17 | uint nodes; 18 | fread(&nodes,sizeof(uint),1,ft); 19 | ulong edgesA; 20 | fread(&edgesA,sizeof(ulong),1,ft); 21 | int* listadyA = (int*)malloc(sizeof(int)*(edgesA+nodes)); 22 | fread(listadyA,sizeof(int), nodes+edgesA,ft); 23 | fclose(ft); 24 | free(filename); 25 | */ 26 | ALREP * A = loadAdyacencyList(argv[1]); 27 | 28 | // Cargando Lista de Adyacencia B 29 | /* 30 | filename = (char *) malloc(sizeof(char)*(strlen(argv[1])+8)); 31 | strcpy(filename,argv[2]); 32 | strcat(filename,".rbfull"); 33 | ft = fopen(filename,"r"); 34 | uint nodesB; 35 | fread(&nodesB,sizeof(uint),1,ft); 36 | ulong edgesB; 37 | fread(&edgesB,sizeof(ulong),1,ft); 38 | int* listadyB = (int*)malloc(sizeof(int)*(edgesB+nodesB)); 39 | fread(listadyB,sizeof(int), nodesB+edgesB,ft); 40 | fclose(ft); 41 | free(filename); 42 | */ 43 | ALREP * B = loadAdyacencyList(argv[2]); 44 | 45 | // Desplegando A 46 | /* 47 | printf("Lista de Adyacencia de %s\n", argv[1]); 48 | printf("Nodes: %d\n", nodes); 49 | printf("Edges: %ld\n", edgesA); 50 | ulong i; 51 | for(i=0; i 2 | #include "adylist_setOperations.h" 3 | 4 | int main(int argc, char* argv[]){ 5 | 6 | if(argc<4){ 7 | fprintf(stderr,"USAGE: %s \n",argv[0]); 8 | return(-1); 9 | } 10 | 11 | // Cargando Lista de Adyacencia A 12 | /* 13 | char *filename = (char *) malloc(sizeof(char)*(strlen(argv[1])+8)); 14 | strcpy(filename,argv[1]); 15 | strcat(filename,".rbfull"); 16 | FILE * ft = fopen(filename,"r"); 17 | uint nodes; 18 | fread(&nodes,sizeof(uint),1,ft); 19 | ulong edgesA; 20 | fread(&edgesA,sizeof(ulong),1,ft); 21 | int* listadyA = (int*)malloc(sizeof(int)*(edgesA+nodes)); 22 | fread(listadyA,sizeof(int), nodes+edgesA,ft); 23 | fclose(ft); 24 | free(filename); 25 | */ 26 | 27 | ALREP * A = loadAdyacencyList(argv[1]); 28 | 29 | // Cargando Lista de Adyacencia B 30 | /* 31 | filename = (char *) malloc(sizeof(char)*(strlen(argv[1])+8)); 32 | strcpy(filename,argv[2]); 33 | strcat(filename,".rbfull"); 34 | ft = fopen(filename,"r"); 35 | uint nodesB; 36 | fread(&nodesB,sizeof(uint),1,ft); 37 | ulong edgesB; 38 | fread(&edgesB,sizeof(ulong),1,ft); 39 | int* listadyB = (int*)malloc(sizeof(int)*(edgesB+nodesB)); 40 | fread(listadyB,sizeof(int), nodesB+edgesB,ft); 41 | fclose(ft); 42 | free(filename); 43 | */ 44 | ALREP * B = loadAdyacencyList(argv[2]); 45 | 46 | // Desplegando A 47 | /* 48 | printf("Lista de Adyacencia de %s\n", argv[1]); 49 | printf("Nodes: %d\n", nodes); 50 | printf("Edges: %ld\n", edgesA); 51 | ulong i; 52 | for(i=0; i 2 | #include "adylist_setOperations.h" 3 | 4 | int main(int argc, char* argv[]){ 5 | 6 | if(argc<4){ 7 | fprintf(stderr,"USAGE: %s \n",argv[0]); 8 | return(-1); 9 | } 10 | 11 | // Cargando Lista de Adyacencia A 12 | ALREP * A = loadAdyacencyList(argv[1]); 13 | // Cargando Lista de Adyacencia B 14 | ALREP * B = loadAdyacencyList(argv[2]); 15 | 16 | ALREP * listadyResult = adylistUnionOperation(A, B); 17 | if(listadyResult == NULL){ 18 | printf("Error en la operación...\n"); 19 | return 0; 20 | } 21 | 22 | destroyAdyacencyList(A); 23 | destroyAdyacencyList(B); 24 | // Desplegando Resultado de la Unión 25 | //saveAdyList(edgesResult[0], nodes, listadyResult, argv[3]); 26 | saveAdyacencyList(listadyResult, argv[3]); 27 | destroyAdyacencyList(listadyResult); 28 | 29 | return 0; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /implementations/sdk2tree/basic.h: -------------------------------------------------------------------------------- 1 | #ifndef BASICSINCLUDED 2 | #define BASICSINCLUDED 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | /* basics.h 13 | Copyright (C) 2005, Rodrigo Gonzalez, all rights reserved. 14 | 15 | Some preliminary stuff 16 | 17 | This library is free software; you can redistribute it and/or 18 | modify it under the terms of the GNU Lesser General Public 19 | License as published by the Free Software Foundation; either 20 | version 2.1 of the License, or (at your option) any later version. 21 | 22 | This library is distributed in the hope that it will be useful, 23 | but WITHOUT ANY WARRANTY; without even the implied warranty of 24 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 25 | Lesser General Public License for more details. 26 | 27 | You should have received a copy of the GNU Lesser General Public 28 | License along with this library; if not, write to the Free Software 29 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 30 | 31 | */ 32 | 33 | 34 | 35 | #define mask31 0x0000001F 36 | 37 | #define max(x,y) ((x)>(y)?(x):(y)) 38 | #define min(x,y) ((x)<(y)?(x):(y)) 39 | 40 | /*numero de bits del entero de la maquina*/ 41 | #define W 32 42 | /* W-1 */ 43 | #define Wminusone 31 44 | /*numero de bits del entero de la maquina*/ 45 | #define WW 64 46 | /*bits para hacer la mascara para contar mas rapido*/ 47 | #define bitsM 8 48 | /*bytes que hacen una palabra */ 49 | #define BW 4 50 | #ifndef uchar 51 | #define uchar unsigned char 52 | #endif 53 | #ifndef uint 54 | #define uint unsigned int 55 | #endif 56 | #ifndef ulong 57 | #define ulong unsigned long 58 | #endif 59 | #define size_uchar 256 60 | 61 | /* reads bit p from e */ 62 | #define bitget(e,p) ((((e)[(p)/W] >> ((p)%W))) & 1) 63 | /* sets bit p in e */ 64 | #define bitset(e,p) ((e)[(p)/W] |= (1<<((p)%W))) 65 | /* cleans bit p in e */ 66 | #define bitclean(e,p) ((e)[(p)/W] &= ~(1<<((p)%W))) 67 | 68 | /* numero de enteros necesarios para representar e elementos de largo n */ 69 | #define enteros(e,n) ((e)*(n))/W+(((e)*(n))%W > 0) 70 | /* bits needed to represent a number between 0 and n */ 71 | uint bits (uint n); 72 | 73 | 74 | 75 | uint GetField(uint *A, register uint len, register uint index); 76 | void SetField(uint *A,register uint len, register uint index,register uint x); 77 | 78 | 79 | uint GetVarField(uint *A, register uint ini, register uint fin); 80 | 81 | void SetVarField(uint *A,register uint ini, register uint fin,register uint x); 82 | 83 | unsigned GetFieldW32(uint *A,register uint index); 84 | 85 | 86 | void SetField32(uint *A, register uint index,register uint x) ; 87 | 88 | unsigned GetFieldW16(uint *A,register uint index); 89 | unsigned GetFieldW4(uint *A,register uint index) ; 90 | 91 | uint popcount (register int x); 92 | 93 | uint popcount16 (register int x); 94 | 95 | uint popcount8 (register int x); 96 | #endif 97 | -------------------------------------------------------------------------------- /implementations/sdk2tree/bitrankw32int.h: -------------------------------------------------------------------------------- 1 | #ifndef BitRankW32Int_h 2 | #define BitRankW32Int_h 3 | #include "basic.h" 4 | /* bitarray.h 5 | Copyright (C) 2005, Rodrigo Gonzalez, all rights reserved. 6 | 7 | New RANK, SELECT, SELECT-NEXT and SPARSE RANK implementations. 8 | 9 | This library is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Lesser General Public 11 | License as published by the Free Software Foundation; either 12 | version 2.1 of the License, or (at your option) any later version. 13 | 14 | This library is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | Lesser General Public License for more details. 18 | 19 | You should have received a copy of the GNU Lesser General Public 20 | License along with this library; if not, write to the Free Software 21 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | 23 | */ 24 | 25 | 26 | 27 | ///////////// 28 | //Rank(B,i)// 29 | ///////////// 30 | //_factor = 0 => s=W*lgn 31 | //_factor = P => s=W*P 32 | //Is interesting to notice 33 | //factor=2 => overhead 50% 34 | //factor=3 => overhead 33% 35 | //factor=4 => overhead 25% 36 | //factor=20=> overhead 5% 37 | 38 | typedef struct sbitRankW32Int{ 39 | uint *data; 40 | char owner; 41 | uint integers; 42 | uint factor,b,s; 43 | uint *Rs; //superblock array 44 | uint n; 45 | } bitRankW32Int; 46 | //uso interno para contruir el indice rank 47 | uint buildRankSub(bitRankW32Int * br,uint ini,uint fin); 48 | void buildRank(bitRankW32Int * br); //crea indice para rank 49 | 50 | bitRankW32Int * createBitRankW32Int(uint *bitarray, uint n, char owner, uint factor); 51 | void destroyBitRankW32Int(bitRankW32Int * br); //destructor 52 | uint isBitSet(bitRankW32Int * br, uint i); 53 | uint rank(bitRankW32Int * br, uint i); //Nivel 1 bin, nivel 2 sec-pop y nivel 3 sec-bit 54 | uint lenght_in_bits(bitRankW32Int * br); 55 | uint prev(bitRankW32Int * br, uint start); // gives the largest index i<=start such that IsBitSet(i)=true 56 | uint bselect(bitRankW32Int * br, uint x); // gives the position of the x:th 1. 57 | uint select0(bitRankW32Int * br, uint x); // gives the position of the x:th 0. 58 | uint select1(bitRankW32Int * br, uint x); // gives the position of the x:th 1. 59 | uint spaceRequirementInBits(bitRankW32Int * br); 60 | /*load-save functions*/ 61 | int save(bitRankW32Int * br, FILE *f); 62 | int load(bitRankW32Int * br, FILE *f); 63 | bitRankW32Int * createBitRankW32IntFile(FILE *f, int *error); 64 | 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /implementations/sdk2tree/kTree.h: -------------------------------------------------------------------------------- 1 | #ifndef KTREE_H 2 | #define KTREE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "bitrankw32int.h" 9 | #include "basic.h" 10 | #define MAX_INFO 1024*1024+10 11 | 12 | 13 | 14 | typedef struct matrixRep 15 | { 16 | bitRankW32Int * btl; //Bitmap representando T:L 17 | uint btl_len; //Numero de bits de T:L 18 | uint bt_len; //Numero de bits de T 19 | int maxLevel; //Nivel maximo del arbol 20 | uint numberOfNodes; 21 | ulong numberOfEdges; 22 | ulong numberOfMarkedEdges; 23 | uint * div_level_table; 24 | uint * info; 25 | uint * info2[2]; 26 | uint * element; 27 | uint * basex; 28 | uint * basey; 29 | int iniq; 30 | int finq; 31 | }MREP; 32 | 33 | 34 | #define K 2 35 | 36 | MREP * compactCreateKTree(uint * xedges, uint *yedges, uint numberOfNodes,ulong numberOfEdges, uint maxl); 37 | 38 | 39 | uint * compactAdjacencyList(MREP * rep, int x); 40 | uint * compact2AdjacencyList(MREP * rep, int x); 41 | uint * compactInverseList(MREP * rep, int y); 42 | uint ** compactRangeQuery(MREP * rep, uint p1, uint p2, uint q1, uint q2); 43 | uint compactCheckLinkQuery(MREP * rep, uint p, uint q); 44 | uint compact2CheckLinkQuery(MREP * rep, uint p, uint q); 45 | uint compact2CheckAddLinkQuery(MREP * rep, uint p, uint q); 46 | uint compactCheckRangeQuery(MREP * rep, uint p1, uint p2, uint q1, uint q2); 47 | uint compact2MarkLinkDeleted(MREP * rep, uint p, uint q); 48 | 49 | int * compactFullDecompression(MREP * rep); 50 | 51 | void edgeIterator(MREP * rep, int (*proc)(uint32_t u, uint32_t v)); 52 | 53 | MREP * loadRepresentation(char * basename); 54 | void saveRepresentation(MREP * rep, char * basename); 55 | void destroyRepresentation(MREP * rep); 56 | 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /implementations/sdk2tree/kt_buildTree.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "kTree.h" 5 | 6 | 7 | 8 | int main(int argc, char* argv[]){ 9 | FILE *f; 10 | uint nodes; 11 | ulong edges; 12 | register ulong i; 13 | 14 | if(argc<3){ 15 | fprintf(stderr,"USAGE: %s \n",argv[0]); 16 | return(-1); 17 | } 18 | 19 | 20 | f = fopen(argv[1],"r"); 21 | fread(&nodes,sizeof(uint),1,f); 22 | 23 | printf("> #nodes:\t%d\n", nodes); 24 | 25 | 26 | uint max_level = floor(log(nodes)/log(K)); 27 | if(floor(log(nodes)/log(K))==(log(nodes)/log(K))) { 28 | max_level=max_level-1; 29 | } 30 | fread(&edges,sizeof(ulong),1,f); 31 | uint nodes_read=0; 32 | 33 | printf("> #edges:\t%ld\n", edges); 34 | 35 | 36 | 37 | uint *xedges = (uint *)malloc(sizeof(uint)*edges); 38 | uint *yedges = (uint *)malloc(sizeof(uint)*edges); 39 | uint cedg = 0; 40 | for(i=0;iinfo = (uint *)malloc(sizeof(uint)*MAX_INFO); 61 | rep->element = (uint *)malloc(sizeof(uint)*MAX_INFO); 62 | rep->basex = (uint *)malloc(sizeof(uint)*MAX_INFO); 63 | rep->basey = (uint *)malloc(sizeof(uint)*MAX_INFO); 64 | rep->iniq = -1; 65 | rep->finq =-1; 66 | rep->div_level_table = (uint *)malloc(sizeof(uint)*rep->maxLevel); 67 | for(i=0;imaxLevel;i++) 68 | rep->div_level_table[i]=exp_pow(K,rep->maxLevel-i); 69 | */ 70 | 71 | saveRepresentation(rep,argv[2]); 72 | destroyRepresentation(rep); 73 | 74 | free(xedges); 75 | free(yedges); 76 | fclose(f); 77 | return 0; 78 | } 79 | 80 | 81 | -------------------------------------------------------------------------------- /implementations/sdk2tree/kt_decompressTree.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "kTree.h" 5 | 6 | 7 | 8 | int main(int argc, char* argv[]){ 9 | 10 | if(argc<3){ 11 | fprintf(stderr,"USAGE: %s \n",argv[0]); 12 | return(-1); 13 | } 14 | 15 | char *filename = (char *)malloc(sizeof(char)*(strlen(argv[1])+10)); 16 | MREP * rep = loadRepresentation(argv[1]); 17 | 18 | strcpy(filename,argv[2]); 19 | strcat(filename,".rbfull"); 20 | FILE *fr = fopen(filename,"w"); 21 | fwrite(&(rep->numberOfNodes),sizeof(uint),1,fr); 22 | fwrite(&(rep->numberOfEdges),sizeof(ulong),1,fr); 23 | 24 | int * listady; 25 | listady = (int *) compactFullDecompression(rep); 26 | 27 | fwrite(listady,sizeof(int),rep->numberOfNodes+rep->numberOfEdges,fr); 28 | 29 | fclose(fr); 30 | printf("%s\n", filename); 31 | destroyRepresentation(rep); 32 | free(filename); 33 | free(listady); 34 | return 0; 35 | } -------------------------------------------------------------------------------- /implementations/sdk2tree/kt_fromList.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "kTree.h" 4 | #include "adylist.h" 5 | 6 | 7 | int main(int argc, char* argv[]){ 8 | uint nodes; 9 | ulong edges; 10 | register ulong i; 11 | 12 | if(argc<3){ 13 | fprintf(stderr,"USAGE: %s \n",argv[0]); 14 | return(-1); 15 | } 16 | 17 | 18 | ALREP * lista = (ALREP *) loadAdyacencyList(argv[1]); 19 | nodes = lista->numNodes; 20 | edges = lista->numEdges; 21 | 22 | uint max_level = floor(log(nodes)/log(K)); 23 | if(floor(log(nodes)/log(K))==(log(nodes)/log(K))) { 24 | max_level=max_level-1; 25 | } 26 | 27 | uint nodes_read=0; 28 | uint *xedges = (uint *)malloc(sizeof(uint)*edges); 29 | uint *yedges = (uint *)malloc(sizeof(uint)*edges); 30 | uint cedg = 0; 31 | int k; 32 | for(i=0;ilistady[i]; 34 | if(k<0) { 35 | nodes_read++; 36 | } 37 | else { 38 | k--; 39 | xedges[cedg]=nodes_read-1; 40 | yedges[cedg]=k; 41 | cedg++; 42 | } 43 | } 44 | 45 | MREP * rep; 46 | 47 | rep = compactCreateKTree(xedges, yedges, nodes,edges,max_level); 48 | saveRepresentation(rep,argv[2]); 49 | 50 | destroyAdyacencyList(lista); 51 | destroyRepresentation(rep); 52 | 53 | free(xedges); 54 | free(yedges); 55 | 56 | return 0; 57 | } 58 | 59 | 60 | -------------------------------------------------------------------------------- /implementations/sdk2tree/kt_getCell.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "kTree.h" 4 | 5 | int main(int argc, char * argv[]){ 6 | setbuf(stdin, NULL); 7 | if(argc<4){ 8 | fprintf(stderr,"USAGE: %s \n",argv[0]); 9 | return(-1); 10 | } 11 | 12 | MREP * rep = loadRepresentation(argv[1]); 13 | 14 | int idOrigen = atoi(argv[2]); 15 | int idDestino = atoi(argv[3]); 16 | 17 | uint resp = compact2CheckLinkQuery(rep, idOrigen, idDestino); 18 | printf("%u\n", resp); 19 | 20 | destroyRepresentation(rep); 21 | 22 | return 0; 23 | } -------------------------------------------------------------------------------- /implementations/sdk2tree/kt_getNeightbors.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "kTree.h" 4 | 5 | int main(int argc, char * argv[]){ 6 | setbuf(stdin, NULL); 7 | if(argc<3){ 8 | fprintf(stderr,"USAGE: %s \n",argv[0]); 9 | return(-1); 10 | } 11 | MREP * rep = loadRepresentation(argv[1]); 12 | 13 | uint i; 14 | int idNodo = atoi(argv[2]); 15 | uint * listady; 16 | listady = compact2AdjacencyList(rep, idNodo); 17 | printf("(%u)\t", listady[0]); 18 | for(i=0; i 2 | #include 3 | #include "kTree.h" 4 | 5 | int main(int argc, char * argv[]){ 6 | setbuf(stdin, NULL); 7 | if(argc<6){ 8 | fprintf(stderr,"USAGE: %s \n",argv[0]); 9 | return(-1); 10 | } 11 | 12 | MREP * rep = loadRepresentation(argv[1]); 13 | 14 | uint p1=atoi(argv[2]); 15 | uint p2=atoi(argv[3]); 16 | uint q1=atoi(argv[4]); 17 | uint q2=atoi(argv[5]); 18 | 19 | uint ** respuesta = compactRangeQuery(rep, p1, p2, q1, q2); 20 | 21 | printf("Range: [%d,%d]-[%d,%d], total of links %d\n",p1,p2,q1,q2,respuesta[0][0]); 22 | uint i = respuesta[0][0]; 23 | for(i=0;i 2 | #include 3 | #include "kTree.h" 4 | 5 | int main(int argc, char * argv[]){ 6 | setbuf(stdin, NULL); 7 | if(argc<3){ 8 | fprintf(stderr,"USAGE: %s \n",argv[0]); 9 | return(-1); 10 | } 11 | MREP * rep = loadRepresentation(argv[1]); 12 | uint i; 13 | int idNodo = atoi(argv[2]); 14 | uint * listady; 15 | listady = compactInverseList(rep, idNodo); 16 | printf("(%u)\t", listady[0]); 17 | for(i=0; i 2 | #include 3 | #include "Queue.h" 4 | #include "misBits.h" 5 | #include "kTree.h" 6 | 7 | /* 8 | Implementado con la última versión del BitMap que desplaza para concatenar. 9 | */ 10 | 11 | 12 | MREP * createFromBitmap(misBits * C, int maximalLevel, ulong numNodos, ulong numEdges); 13 | MREP * k2tree_union(MREP * repA, MREP * repB); 14 | MREP * k2tree_symmetricdifference(MREP * repA, MREP * repB); 15 | MREP * k2tree_intersection(MREP * repA, MREP * repB); 16 | MREP * k2tree_difference(MREP * repA, MREP * repB); 17 | MREP * k2tree_complement(MREP * repA); -------------------------------------------------------------------------------- /implementations/sdk2tree/kt_setop_complement.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "kt_setOperations.h" 3 | 4 | int main(int argc, char * argv[]){ 5 | if(argc < 3){ 6 | fprintf(stderr,"USAGE: %s \n", argv[0]); 7 | return(-1); 8 | } 9 | 10 | /* 11 | setbuf(stdout, NULL); 12 | */ 13 | 14 | MREP * repA = loadRepresentation(argv[1]); 15 | MREP * result = k2tree_complement(repA); 16 | 17 | if(result == NULL){ 18 | printf("Fallo en la operación.\n"); 19 | return -1; 20 | } 21 | 22 | destroyRepresentation(repA); 23 | saveRepresentation(result, argv[2]); 24 | destroyRepresentation(result); 25 | return 0; 26 | } 27 | 28 | /* 29 | 30 | 31 | int main(int argc, char * argv[]){ 32 | if(argc < 3){ 33 | fprintf(stderr,"USAGE: %s \n", argv[0]); 34 | return(-1); 35 | } 36 | 37 | // BBOORRAARR 38 | setbuf(stdout, NULL); 39 | // BBOORRAARR 40 | 41 | MREP * repA = loadRepresentation(argv[1]); 42 | 43 | //uint maximalNodes; 44 | uint maximalLevel = repA->maxLevel; 45 | 46 | ulong * pRepA = posByLevel(repA); 47 | 48 | ulong * minBits = (ulong *) malloc(sizeof(ulong) * (maximalLevel+1)); 49 | if(minBits == NULL){ 50 | printf("Error en la reserva de memoria.\n"); 51 | return (-1); 52 | } 53 | // Para el complemento, el peor caso es generar como resultado de la 54 | // operación una representación que no compacte sectores 55 | // Por lo que se reserva el espacio necesario para una representación completa 56 | 57 | ulong i, auxNodes = K*K; 58 | for(i=0; i<=maximalLevel; i++){ 59 | minBits[i] = auxNodes; 60 | //maximalNodes+=minBits[i]; 61 | auxNodes = auxNodes * (K*K); 62 | } 63 | 64 | misBits * C = nuevoBitMap(maximalLevel+1, minBits); 65 | if(C == NULL){ 66 | printf("Error en la reserva de memoria.\n"); 67 | return (-1); 68 | } 69 | 70 | // Variable para calcular el número de vínculos dentro de la operación. 71 | ulong limiteSuperior = repA->div_level_table[0] * 2 - 1; 72 | ulong limits[4] = {0, limiteSuperior, 0, limiteSuperior}; 73 | 74 | complementOperation(0u, repA, pRepA, C, limits); 75 | ulong vinculolos = concatenar(C); 76 | ulong numNodos = repA->numberOfNodes; 77 | destroyRepresentation(repA); 78 | saveOperation(C, maximalLevel, argv[2], numNodos, vinculolos); 79 | return 0; 80 | } 81 | */ -------------------------------------------------------------------------------- /implementations/sdk2tree/kt_setop_difference.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "kt_setOperations.h" 3 | 4 | int main(int argc, char * argv[]){ 5 | if(argc < 4){ 6 | fprintf(stderr,"USAGE: %s \n", argv[0]); 7 | return(-1); 8 | } 9 | 10 | MREP * repA = loadRepresentation(argv[1]); 11 | MREP * repB = loadRepresentation(argv[2]); 12 | MREP * result = k2tree_difference(repA, repB); 13 | 14 | if(result == NULL){ 15 | printf("Fallo en la operación.\n"); 16 | return -1; 17 | } 18 | 19 | destroyRepresentation(repA); 20 | destroyRepresentation(repB); 21 | saveRepresentation(result, argv[3]); 22 | destroyRepresentation(result); 23 | return 0; 24 | } 25 | 26 | /* 27 | RESPALDO... PREVIO A LA IMPLEMENTACIÓN DE LAS FUNCIONES CON DOS/UN PARAMETROS Y RETORNAN MREP 28 | 29 | int main(int argc, char * argv[]){ 30 | if(argc < 4){ 31 | fprintf(stderr,"USAGE: %s \n", argv[0]); 32 | return(-1); 33 | } 34 | 35 | MREP * repA = loadRepresentation(argv[1]); 36 | MREP * repB = loadRepresentation(argv[2]); 37 | 38 | ulong maximalBits = repA->btl_len; 39 | uint maximalLevel = repA->maxLevel; 40 | 41 | ulong * pRepA = posByLevel(repA); 42 | ulong * pRepB = posByLevel(repB); 43 | 44 | ulong * minBits = (ulong *) malloc(sizeof(ulong)*(maximalLevel+1)); 45 | if(minBits == NULL){ 46 | printf("Error en la reserva de memoria.\n"); 47 | return (-1); 48 | } 49 | // En la diferencia, la reserva de espacio debe ser suficiente para almacenar 50 | // la representación completa del primer k2-tree, ya que podrían no tener 51 | // elementos en común. 52 | uint i; 53 | for(i=0; i<=maximalLevel; i++){ 54 | minBits[i] = pRepA[i+1] - pRepA[i]; 55 | } 56 | minBits[maximalLevel] = maximalBits - pRepA[maximalLevel]; 57 | 58 | misBits * C = nuevoBitMap(maximalLevel+1, minBits); 59 | if(C == NULL){ 60 | printf("Error en la reserva de memoria.\n"); 61 | return (-1); 62 | } 63 | 64 | differenceOperation(0u, repA, repB, pRepA, pRepB, C); 65 | ulong vinculolos = concatenar(C); 66 | ulong numNodos = repA->numberOfNodes; 67 | 68 | destroyRepresentation(repA); 69 | destroyRepresentation(repB); 70 | 71 | saveOperation(C, maximalLevel, argv[3], numNodos, vinculolos); 72 | return 0; 73 | } 74 | */ -------------------------------------------------------------------------------- /implementations/sdk2tree/kt_setop_intersection.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "kt_setOperations.h" 3 | 4 | int main(int argc, char * argv[]){ 5 | if(argc < 4){ 6 | fprintf(stderr,"USAGE: %s \n", argv[0]); 7 | return(-1); 8 | } 9 | 10 | /* 11 | setbuf(stdout, NULL); 12 | */ 13 | 14 | MREP * repA = loadRepresentation(argv[1]); 15 | MREP * repB = loadRepresentation(argv[2]); 16 | MREP * result = k2tree_intersection(repA, repB); 17 | 18 | if(result == NULL){ 19 | printf("Fallo en la operación.\n"); 20 | return -1; 21 | } 22 | 23 | destroyRepresentation(repA); 24 | destroyRepresentation(repB); 25 | saveRepresentation(result, argv[3]); 26 | destroyRepresentation(result); 27 | return 0; 28 | } 29 | 30 | /* 31 | RESPALDO... PREVIO A LA IMPLEMENTACIÓN DE LAS FUNCIONES CON DOS/UN PARAMETROS Y RETORNAN MREP 32 | 33 | int main(int argc, char * argv[]){ 34 | if(argc < 4){ 35 | fprintf(stderr,"USAGE: %s \n", argv[0]); 36 | return(-1); 37 | } 38 | 39 | // BBOORRAARR 40 | setbuf(stdout, NULL); 41 | // BBOORRAARR 42 | 43 | MREP * repA = loadRepresentation(argv[1]); 44 | MREP * repB = loadRepresentation(argv[2]); 45 | uint maximalLevel = repA->maxLevel; 46 | 47 | ulong * pRepA = posByLevel(repA); 48 | ulong * pRepB = posByLevel(repB); 49 | 50 | ulong * minBits = (ulong *) malloc(sizeof(ulong)*(maximalLevel+1)); 51 | if(minBits == NULL){ 52 | printf("Se ha generado un problema...\n"); 53 | return 0; 54 | } 55 | // La intersección podría tener a lo más, tantas celdas activas 56 | // como las que posee el menor de los dos elementos operados. 57 | 58 | ulong numBitsByLevelA, numBitsByLevelB; 59 | uint i; 60 | for(i = 0; i <= maximalLevel; i++){ 61 | // printf("%d/%d\t", i,maximalLevel); 62 | if(i==repA->maxLevel){ 63 | // printf("a \t"); 64 | numBitsByLevelA = repA->btl_len - pRepA[i]; 65 | numBitsByLevelB = repB->btl_len - pRepB[i]; 66 | // printf("b \n"); 67 | }else{ 68 | // printf("A \t"); 69 | numBitsByLevelA = pRepA[i+1] - pRepA[i]; 70 | numBitsByLevelB = pRepB[i+1] - pRepB[i]; 71 | // printf("B \n"); 72 | } 73 | // printf("X \t"); 74 | // printf("minBitsA: %d\t\tminBitsB: %d\t\t", numBitsByLevelA, numBitsByLevelB); 75 | minBits[i] = (numBitsByLevelA > numBitsByLevelB)?numBitsByLevelB:numBitsByLevelA; 76 | // printf("X \t"); 77 | // printf("minBits[%d] = %d\n", i, minBits[i]); 78 | // printf("-------\n"); 79 | } 80 | 81 | // printf("nuevoBitMap inicio\n"); 82 | misBits * C = nuevoBitMap(maximalLevel+1, minBits); 83 | if(C == NULL){ 84 | printf("Error en la reserva de memoria.\n"); 85 | return (-1); 86 | } 87 | intersectionOperation(0u, repA, repB, pRepA, pRepB, C); 88 | ulong vinculolos = concatenar(C); 89 | ulong numNodos = repA->numberOfNodes; 90 | 91 | destroyRepresentation(repA); 92 | destroyRepresentation(repB); 93 | 94 | saveOperation(C, maximalLevel, argv[3], numNodos, vinculolos); 95 | return 0; 96 | } 97 | */ -------------------------------------------------------------------------------- /implementations/sdk2tree/kt_setop_symmdiff.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "kt_setOperations.h" 3 | 4 | int main(int argc, char * argv[]){ 5 | if(argc < 4){ 6 | fprintf(stderr,"USAGE: %s \n", argv[0]); 7 | return(-1); 8 | } 9 | 10 | MREP * repA = loadRepresentation(argv[1]); 11 | MREP * repB = loadRepresentation(argv[2]); 12 | 13 | MREP * result = k2tree_symmetricdifference(repA, repB); 14 | 15 | if(result == NULL){ 16 | printf("Fallo en la operación.\n"); 17 | return -1; 18 | } 19 | 20 | destroyRepresentation(repA); 21 | destroyRepresentation(repB); 22 | saveRepresentation(result, argv[3]); 23 | return 0; 24 | } 25 | 26 | /* 27 | RESPALDO... PREVIO A LA IMPLEMENTACIÓN DE LAS FUNCIONES CON DOS/UN PARAMETROS Y RETORNAN MREP 28 | 29 | int main(int argc, char * argv[]){ 30 | if(argc < 4){ 31 | fprintf(stderr,"USAGE: %s \n", argv[0]); 32 | return(-1); 33 | } 34 | 35 | MREP * repA = loadRepresentation(argv[1]); 36 | MREP * repB = loadRepresentation(argv[2]); 37 | 38 | //uint maximalNodes; 39 | uint maximalLevel = repA->maxLevel; 40 | 41 | ulong * pRepA = posByLevel(repA); 42 | ulong * pRepB = posByLevel(repB); 43 | 44 | ulong * minBits = (ulong *) malloc(sizeof(ulong)*(maximalLevel+1)); 45 | if(minBits == NULL){ 46 | printf("Error en la reserva de memoria.\n"); 47 | return (-1); 48 | } 49 | // En el peor de los casos (en términos de espacio), la diferencia simétrica podría 50 | // generar una representación completa de un grafo de k niveles, por lo que 51 | // se reserva todos los bits posibles en base a la cantidad de niveles. 52 | 53 | uint i; 54 | ulong auxNodes = K*K; 55 | for(i=0; i<=maximalLevel; i++){ 56 | minBits[i] = auxNodes; 57 | //maximalNodes+=minBits[i]; 58 | auxNodes = auxNodes * (K*K); 59 | } 60 | 61 | misBits * C = nuevoBitMap(maximalLevel+1, minBits); 62 | if(C == NULL){ 63 | printf("Error en la reserva de memoria.\n"); 64 | return (-1); 65 | } 66 | 67 | symmetricDifferenceOperation(0u, repA, repB, pRepA, pRepB, C); 68 | ulong vinculolos = concatenar(C); 69 | ulong numNodos = repA->numberOfNodes; 70 | 71 | destroyRepresentation(repA); 72 | destroyRepresentation(repB); 73 | 74 | saveOperation(C, maximalLevel, argv[3], numNodos, vinculolos); 75 | return 0; 76 | } 77 | */ -------------------------------------------------------------------------------- /implementations/sdk2tree/kt_setop_union.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "kt_setOperations.h" 3 | 4 | int main(int argc, char * argv[]){ 5 | if(argc < 4){ 6 | fprintf(stderr,"USAGE: %s \n", argv[0]); 7 | return(-1); 8 | } 9 | 10 | MREP * repA = loadRepresentation(argv[1]); 11 | MREP * repB = loadRepresentation(argv[2]); 12 | MREP * result = k2tree_union(repA, repB); 13 | 14 | if(result == NULL){ 15 | printf("Operación de unión finalizada..\n"); 16 | return -1; 17 | } 18 | 19 | saveRepresentation(result, argv[3]); 20 | destroyRepresentation(repA); 21 | destroyRepresentation(repB); 22 | destroyRepresentation(result); 23 | return 0; 24 | } 25 | 26 | 27 | /* 28 | RESPALDO... PREVIO A LA IMPLEMENTACIÓN DE LAS FUNCIONES CON DOS/UN PARAMETROS Y RETORNAN MREP 29 | 30 | int main(int argc, char * argv[]){ 31 | if(argc < 4){ 32 | fprintf(stderr,"USAGE: %s \n", argv[0]); 33 | return(-1); 34 | } 35 | 36 | MREP * repA = loadRepresentation(argv[1]); 37 | MREP * repB = loadRepresentation(argv[2]); 38 | 39 | uint maximalLevel = repA->maxLevel; 40 | 41 | ulong i = 0, maximalBits = 0, calculador = 1; 42 | 43 | for(i = 0; i <= maximalLevel; i++){ 44 | calculador *= (K*K); 45 | maximalBits += calculador; 46 | } 47 | 48 | ulong minBits[] = {maximalBits}; 49 | // En la unión, el peor de los casos corresponde a generar una 50 | // representación completa de un k2-tree, sin sectores en 0. 51 | 52 | misBits * C = nuevoBitMap(1u, minBits); 53 | if(C == NULL){ 54 | printf("Error en la reserva de memoria.\n"); 55 | return (-1); 56 | } 57 | 58 | ulong numEdges = unionOperation(repA, repB, C); 59 | concatenar(C); 60 | ulong numNodos = repA->numberOfNodes; 61 | 62 | destroyRepresentation(repA); 63 | destroyRepresentation(repB); 64 | 65 | saveOperation(C, maximalLevel, argv[3], numNodos, numEdges); 66 | return 0; 67 | } 68 | */ -------------------------------------------------------------------------------- /implementations/sdk2tree/kt_toList.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "kTree.h" 3 | #include "adylist.h" 4 | 5 | 6 | 7 | int main(int argc, char* argv[]){ 8 | if(argc<3){ 9 | fprintf(stderr,"USAGE: %s \n",argv[0]); 10 | return(-1); 11 | } 12 | 13 | MREP * rep = loadRepresentation(argv[1]); 14 | int * listady; 15 | listady = (int *) compactFullDecompression(rep); 16 | 17 | ALREP * adyList = (ALREP *) malloc(sizeof(struct adyList)); 18 | adyList->numNodes = rep->numberOfNodes; 19 | adyList->numEdges = rep->numberOfEdges; 20 | adyList->listady = listady; 21 | 22 | saveAdyacencyList(adyList, argv[2]); 23 | 24 | destroyAdyacencyList(adyList); 25 | destroyRepresentation(rep); 26 | return 0; 27 | } -------------------------------------------------------------------------------- /implementations/sdk2tree/misBits.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include "basic.h" 3 | 4 | /* 5 | ** Esta estructura permite crear un bitmap segmentado que puede ser completado 6 | ** de manera independiente según nivel/segmento. 7 | ** La concatenación reúne todos segmentos de bits en uno solo segmento, transformandolo a un nivel. 8 | ** Esto evita crear un bitmap por nivel y posteriormente otro 9 | ** capaz de contener los bits de todos los niveles. (Lo que duplicaría la información.) 10 | */ 11 | 12 | typedef struct MISBITS{ 13 | ulong * pos; // Posiciones de inicio para cada nivel del bitmap 14 | ulong * n; // Número de elementos de cada nivel del bitmap 15 | uint niveles; // Cantidad de niveles del bitmap 16 | ulong tam; // Tamaño del bitmap (Capacidad) 17 | ulong cant; // Número de elementos totales del bitmap 18 | ulong numEdges; // Número de 1s al último nivel del bitmap 19 | uint * bitsm; 20 | } misBits; 21 | 22 | misBits* nuevoBitMap(uint levels, ulong * cants); 23 | // Crea una nueva instancia de misBits con niveles y cantidad de elementos por nivel 24 | 25 | void setBit(misBits* bitses, uint level, uint cont); 26 | // Inserta el bit al final de la cadena según el nivel en . 27 | 28 | void bitSeter(misBits* bitses, uint level, ulong i); 29 | // Asigna un valor 1 al i-ésimo bit en el nivel sin manipular cant de 30 | // ni tampoco manipula n. 31 | 32 | uint isBitSeted(misBits* bitses, uint level, ulong i); 33 | // Retorna el contenido del i-ésimo bit (0 o 1) en el nivel . 34 | 35 | void destruirBitMap(misBits* bitses); 36 | // Destruye la estructura A EXCEPCIÓN DE bitses->bitsm que se deja para construir bitmaps. 37 | 38 | void destruirTodoBitmap(misBits* bitses); 39 | // Destruyte TODA la estructura. 40 | 41 | ulong concatenar(misBits* bitses); 42 | // Concatena los bits de todos los niveles en un bitmap de un nivel y lo retorna. 43 | // Modifica los valores de level y tam. 44 | // Libera pos y n 45 | 46 | void prepararBitmap(misBits* bitses, int objectsBRWT,uint numNodes); 47 | // Ordena el bitmap de un BRWTREP desplazando los elementos de los nodos hacia la izquierda 48 | // Esto debido a que la CONSTRUCCIÓN genera los vínculos dejando espacios en el bitmap 49 | // Esta función se DEBE invocar previo a la concatenación cuando se construye el bitmap. -------------------------------------------------------------------------------- /implementations/sdk2tree/pair.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "pair.h" 3 | 4 | PAIR newPair(uint a, uint b){ 5 | PAIR pair; 6 | pair.a = a; 7 | pair.b = b; 8 | return pair; 9 | } -------------------------------------------------------------------------------- /implementations/sdk2tree/pair.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include "basic.h" 3 | 4 | typedef struct Pair{ 5 | char a; 6 | char b; 7 | }PAIR; 8 | 9 | PAIR newPair(uint a, uint b); -------------------------------------------------------------------------------- /python/__pycache__/matplotlib_config.cpython-37.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aplf/sdk2tree/c86a1df6b0a8ea3d40bc9799472da3db201ba53a/python/__pycache__/matplotlib_config.cpython-37.pyc --------------------------------------------------------------------------------