Skip to content

Commit 6bf3635

Browse files
committed
Fix bug
The number of links is now stored in an atomic long in the database.
1 parent ea124f9 commit 6bf3635

1 file changed

Lines changed: 6 additions & 12 deletions

File tree

nodes/src/main/java/org/nodes/DiskDGraph.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555
* The db file can be stored and re-used later. Make sure to close the graph with
5656
* close().
5757
*
58+
* The graph supports more than Integer.MAX_VALUE links in total, however, the
59+
* in- and outdegrees of each node need to be below that value.
60+
*
5861
* @author Peter
5962
*
6063
* @param <L>
@@ -63,7 +66,6 @@ public class DiskDGraph implements DGraph<String>, FastWalkable<String, DNode<St
6366
{
6467
// * the initial capacity reserved for neighbors
6568
public static final int NEIGHBOR_CAPACITY = 5;
66-
private int id = Global.random().nextInt(10000000);
6769

6870
private DB db;
6971

@@ -113,7 +115,7 @@ public DiskDGraph(File dbFile, boolean nullLabels)
113115
throw new IllegalStateException("labels list has size "+ labels.size() + ", should be " + in.size() + ".");
114116

115117
if(db.exists("numLinks"))
116-
numLinks = db.atomicInteger("numLinks").createOrOpen().get();
118+
numLinks = db.atomicLong("numLinks").createOrOpen().get();
117119
else
118120
for(List<Integer> list : in)
119121
numLinks += list.size();
@@ -827,23 +829,14 @@ public List<? extends DNode<String>> nodes()
827829
return new NodeList(Series.series(size()));
828830
}
829831

830-
/**
831-
* NOTE: If hasLongNumLinks is true and the graph has more links than
832-
* Integer.MAX_VALUE, the {size()} of the returned collection
833-
* will be -1.
834-
*
835-
* @return
836-
*/
837832
@Override
838833
public Iterable<? extends DLink<String>> links()
839834
{
840835
return new LinkCollection();
841836
}
842837

843838
/**
844-
* A collection of all links in this graph.
845-
* The iterator it returns can be safely used.
846-
*
839+
* A collection of all links in this graph.
847840
* @author Peter
848841
*
849842
*/
@@ -1217,6 +1210,7 @@ public static DiskDGraph fromFile(File file, File dir)
12171210

12181211
return fromFile(file, dir, new File("graph."+id+".db"));
12191212
}
1213+
12201214
public static DiskDGraph fromFile(File file, File tmpDir, File dbFile)
12211215
throws IOException
12221216
{

0 commit comments

Comments
 (0)