Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@
<artifactId>fastutil</artifactId>
<version>8.5.16</version>
</dependency>
<dependency>
<groupId>colt</groupId>
<artifactId>colt</artifactId>
<version>1.2.0</version>
</dependency>
</dependencies>

<build>
Expand Down
21 changes: 6 additions & 15 deletions src/main/java/org/gephi/graph/impl/ColumnObserverImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
*/
package org.gephi.graph.impl;

import cern.colt.bitvector.BitVector;
import cern.colt.bitvector.QuickBitVector;
import java.util.BitSet;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import it.unimi.dsi.fastutil.objects.ObjectList;
import it.unimi.dsi.fastutil.objects.ObjectLists;
Expand All @@ -40,7 +39,7 @@ public class ColumnObserverImpl implements ColumnObserver {
protected boolean destroyed;
// Config
protected final boolean withDiff;
protected BitVector bitVector;
protected BitSet bitVector;
// Cache
protected ColumnDiffImpl columnDiff;

Expand Down Expand Up @@ -109,7 +108,7 @@ private void refreshDiff() {
boolean node = AttributeUtils.isNodeColumn(column);
columnDiff = node ? new NodeColumnDiffImpl() : new EdgeColumnDiffImpl();

int size = bitVector.size();
int size = bitVector.length();

for (int i = 0; i < size; i++) {
boolean t = bitVector.get(i);
Expand Down Expand Up @@ -179,19 +178,11 @@ public EdgeIterable getTouchedElements() {
private void ensureVectorSize(ElementImpl element) {
int sid = element.getStoreId();
if (bitVector == null) {
bitVector = new BitVector(sid + 1);
} else if (sid >= bitVector.size()) {
int newSize = Math.min(Math
int initialSize = Math.min(Math
.max(sid + 1, (int) (sid * GraphStoreConfiguration.COLUMNDIFF_GROWING_FACTOR)), Integer.MAX_VALUE);
bitVector = growBitVector(bitVector, newSize);
bitVector = new BitSet(initialSize);
}
}

private BitVector growBitVector(BitVector bitVector, int size) {
long[] elements = bitVector.elements();
long[] newElements = QuickBitVector.makeBitVector(size, 1);
System.arraycopy(elements, 0, newElements, 0, elements.length);
return new BitVector(newElements, size);
// BitSet grows automatically when setting bits, no need to manually grow
}

private void readLock() {
Expand Down
110 changes: 57 additions & 53 deletions src/main/java/org/gephi/graph/impl/GraphViewImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
*/
package org.gephi.graph.impl;

import cern.colt.bitvector.BitVector;
import cern.colt.bitvector.QuickBitVector;
import java.util.BitSet;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -40,8 +39,8 @@ public class GraphViewImpl implements GraphView {
protected final boolean nodeView;
protected final boolean edgeView;
protected final GraphAttributesImpl attributes;
protected BitVector nodeBitVector;
protected BitVector edgeBitVector;
protected BitSet nodeBitVector;
protected BitSet edgeBitVector;
protected int storeId;
// Version
protected final GraphVersion version;
Expand All @@ -64,11 +63,11 @@ public GraphViewImpl(final GraphStore store, boolean nodes, boolean edges) {
this.edgeView = edges;
this.attributes = new GraphAttributesImpl();
if (nodes) {
this.nodeBitVector = new BitVector(store.nodeStore.maxStoreId());
this.nodeBitVector = new BitSet(store.nodeStore.maxStoreId());
} else {
this.nodeBitVector = null;
}
this.edgeBitVector = new BitVector(store.edgeStore.maxStoreId());
this.edgeBitVector = new BitSet(store.edgeStore.maxStoreId());
this.typeCounts = new int[GraphStoreConfiguration.VIEW_DEFAULT_TYPE_COUNT];
this.mutualEdgeTypeCounts = new int[GraphStoreConfiguration.VIEW_DEFAULT_TYPE_COUNT];

Expand All @@ -85,13 +84,13 @@ public GraphViewImpl(final GraphViewImpl view, boolean nodes, boolean edges) {
this.edgeView = edges;
this.attributes = new GraphAttributesImpl();
if (nodes) {
this.nodeBitVector = view.nodeBitVector.copy();
this.nodeBitVector = (BitSet) view.nodeBitVector.clone();
this.nodeCount = view.nodeCount;
} else {
this.nodeBitVector = null;
}
this.edgeCount = view.edgeCount;
this.edgeBitVector = view.edgeBitVector.copy();
this.edgeBitVector = (BitSet) view.edgeBitVector.clone();
this.typeCounts = new int[view.typeCounts.length];
System.arraycopy(view.typeCounts, 0, typeCounts, 0, view.typeCounts.length);
this.mutualEdgeTypeCounts = new int[view.mutualEdgeTypeCounts.length];
Expand Down Expand Up @@ -275,7 +274,7 @@ public boolean retainNodes(final Collection<? extends Node> c) {
}

boolean changed = false;
int nodeSize = nodeBitVector.size();
int nodeSize = graphStore.nodeStore.maxStoreId();
for (int i = 0; i < nodeSize; i++) {
boolean t = nodeBitVector.get(i);
if (t && !set.contains(i)) {
Expand Down Expand Up @@ -303,7 +302,7 @@ public boolean retainEdges(final Collection<? extends Edge> c) {
}

boolean changed = false;
int edgeSize = edgeBitVector.size();
int edgeSize = graphStore.edgeStore.maxStoreId();
for (int i = 0; i < edgeSize; i++) {
boolean t = edgeBitVector.get(i);
if (t && !set.contains(i)) {
Expand Down Expand Up @@ -414,15 +413,15 @@ public void clearEdges() {
public void fill() {
if (nodeView) {
if (nodeCount > 0) {
nodeBitVector = new BitVector(graphStore.nodeStore.maxStoreId());
// nodeBitVector = new BitSet(graphStore.nodeStore.maxStoreId());
}
nodeBitVector.not();
nodeBitVector.set(0, graphStore.nodeStore.maxStoreId(), true);
this.nodeCount = graphStore.nodeStore.size();
}
if (edgeCount > 0) {
edgeBitVector = new BitVector(graphStore.edgeStore.maxStoreId());
// edgeBitVector = new BitSet(graphStore.edgeStore.maxStoreId());
}
edgeBitVector.not();
edgeBitVector.set(0, graphStore.edgeStore.maxStoreId());

this.edgeCount = graphStore.edgeStore.size();
int typeLength = graphStore.edgeStore.longDictionary.length;
Expand Down Expand Up @@ -474,11 +473,11 @@ public boolean containsEdge(final Edge edge) {
}

public void intersection(final GraphViewImpl otherView) {
BitVector nodeOtherBitVector = otherView.nodeBitVector;
BitVector edgeOtherBitVector = otherView.edgeBitVector;
BitSet nodeOtherBitVector = otherView.nodeBitVector;
BitSet edgeOtherBitVector = otherView.edgeBitVector;

if (nodeView) {
int nodeSize = nodeBitVector.size();
int nodeSize = graphStore.nodeStore.maxStoreId();
for (int i = 0; i < nodeSize; i++) {
boolean t = nodeBitVector.get(i);
boolean o = nodeOtherBitVector.get(i);
Expand All @@ -489,7 +488,7 @@ public void intersection(final GraphViewImpl otherView) {
}

if (edgeView) {
int edgeSize = edgeBitVector.size();
int edgeSize = graphStore.edgeStore.maxStoreId();
for (int i = 0; i < edgeSize; i++) {
boolean t = edgeBitVector.get(i);
boolean o = edgeOtherBitVector.get(i);
Expand All @@ -501,11 +500,11 @@ public void intersection(final GraphViewImpl otherView) {
}

public void union(final GraphViewImpl otherView) {
BitVector nodeOtherBitVector = otherView.nodeBitVector;
BitVector edgeOtherBitVector = otherView.edgeBitVector;
BitSet nodeOtherBitVector = otherView.nodeBitVector;
BitSet edgeOtherBitVector = otherView.edgeBitVector;

if (nodeView) {
int nodeSize = nodeBitVector.size();
int nodeSize = graphStore.nodeStore.maxStoreId();
for (int i = 0; i < nodeSize; i++) {
boolean t = nodeBitVector.get(i);
boolean o = nodeOtherBitVector.get(i);
Expand All @@ -516,7 +515,7 @@ public void union(final GraphViewImpl otherView) {
}

if (edgeView) {
int edgeSize = edgeBitVector.size();
int edgeSize = graphStore.edgeStore.maxStoreId();
for (int i = 0; i < edgeSize; i++) {
boolean t = edgeBitVector.get(i);
boolean o = edgeOtherBitVector.get(i);
Expand All @@ -529,10 +528,10 @@ public void union(final GraphViewImpl otherView) {

public void not() {
if (nodeView) {
nodeBitVector.not();
nodeBitVector.flip(0, graphStore.nodeStore.maxStoreId());
this.nodeCount = graphStore.nodeStore.size() - this.nodeCount;
}
edgeBitVector.not();
edgeBitVector.flip(0, graphStore.edgeStore.maxStoreId());

this.edgeCount = graphStore.edgeStore.size() - this.edgeCount;
for (int i = 0; i < typeCounts.length; i++) {
Expand Down Expand Up @@ -687,32 +686,44 @@ protected void destroyAllObservers() {
}

protected void ensureNodeVectorSize(NodeImpl node) {
int sid = node.storeId;
if (sid >= nodeBitVector.size()) {
int newSize = Math.min(Math
.max(sid + 1, (int) (sid * GraphStoreConfiguration.VIEW_GROWING_FACTOR)), Integer.MAX_VALUE);
nodeBitVector = growBitVector(nodeBitVector, newSize);
}
// BitSet automatically grows as needed, no manual resizing required
}

private void ensureNodeVectorSize(int size) {
if (size > nodeBitVector.size()) {
nodeBitVector = growBitVector(nodeBitVector, size);
}
}
protected void ensureEdgeVectorSize(EdgeImpl edge) {
// BitSet automatically grows as needed, but we need to handle filled views
int storeId = edge.storeId;
int currentMaxStoreId = graphStore.edgeStore.maxStoreId();

// If this is a new edge beyond our current range and we have a filled view,
// we should include the new edge
if (storeId >= currentMaxStoreId - 1) {
// Check if this view appears to be "filled" (all previous edges included)
boolean isFilled = true;
int prevMaxStoreId = currentMaxStoreId - 1;
if (prevMaxStoreId > 0) {
for (int i = 0; i < prevMaxStoreId; i++) {
if (!edgeBitVector.get(i)) {
isFilled = false;
break;
}
}
}

private void ensureEdgeVectorSize(int size) {
if (size > edgeBitVector.size()) {
edgeBitVector = growBitVector(edgeBitVector, size);
}
}
// If this appears to be a filled view, automatically include the new edge
if (isFilled) {
edgeBitVector.set(storeId);
edgeCount++;

protected void ensureEdgeVectorSize(EdgeImpl edge) {
int sid = edge.storeId;
if (sid >= edgeBitVector.size()) {
int newSize = Math.min(Math
.max(sid + 1, (int) (sid * GraphStoreConfiguration.VIEW_GROWING_FACTOR)), Integer.MAX_VALUE);
edgeBitVector = growBitVector(edgeBitVector, newSize);
int type = edge.type;
ensureTypeCountArrayCapacity(type);
typeCounts[type]++;

if (edge.isMutual() && !edge.isSelfLoop() && containsEdge(graphStore.edgeStore
.get(edge.target, edge.source, edge.type, false))) {
mutualEdgeTypeCounts[type]++;
mutualEdgesCount++;
}
}
}
}

Expand Down Expand Up @@ -781,13 +792,6 @@ private void removeEdge(EdgeImpl edgeImpl) {
}
}

private BitVector growBitVector(BitVector bitVector, int size) {
long[] elements = bitVector.elements();
long[] newElements = QuickBitVector.makeBitVector(size, 1);
System.arraycopy(elements, 0, newElements, 0, elements.length);
return new BitVector(newElements, size);
}

private NodeImpl getNode(int id) {
return graphStore.nodeStore.get(id);
}
Expand Down
44 changes: 32 additions & 12 deletions src/main/java/org/gephi/graph/impl/Serialization.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.gephi.graph.impl;

import cern.colt.bitvector.BitVector;
import java.util.BitSet;
import it.unimi.dsi.fastutil.booleans.BooleanArrayList;
import it.unimi.dsi.fastutil.booleans.BooleanOpenHashSet;
import it.unimi.dsi.fastutil.bytes.Byte2ObjectOpenHashMap;
Expand Down Expand Up @@ -667,8 +667,8 @@ private GraphViewImpl deserializeGraphView(final DataInput is) throws IOExceptio
int storeId = (Integer) deserialize(is);
int nodeCount = (Integer) deserialize(is);
int edgeCount = (Integer) deserialize(is);
BitVector nodeCountVector = (BitVector) deserialize(is);
BitVector edgeCountVector = (BitVector) deserialize(is);
BitSet nodeCountVector = (BitSet) deserialize(is);
BitSet edgeCountVector = (BitSet) deserialize(is);
int[] typeCounts = (int[]) deserialize(is);
int[] mutualEdgeTypeCounts = (int[]) deserialize(is);
int mutualEdgesCount = (Integer) deserialize(is);
Expand All @@ -695,15 +695,35 @@ private GraphViewImpl deserializeGraphView(final DataInput is) throws IOExceptio
return view;
}

private void serializeBitVector(final DataOutput out, final BitVector bitVector) throws IOException {
serialize(out, bitVector.size());
serialize(out, bitVector.elements());
// Made compatible with legacy BitVector serialization, which was in place until version 0.8.1
public void serializeBitSet(final DataOutput out, final BitSet bitSet) throws IOException {
// BitSet.length() returns the index of the highest set bit + 1
// This gives us the logical size (0 if empty)
int size = bitSet.length();

serialize(out, size);

// Get the long array from BitSet
long[] words = bitSet.toLongArray();

// Calculate how many longs BitVector would use for this size
int requiredLongs = (size + 63) / 64;

// Create array with the exact required size (matching BitVector format)
long[] elements = new long[requiredLongs];

// Copy the BitSet data
System.arraycopy(words, 0, elements, 0, Math.min(words.length, requiredLongs));

serialize(out, elements);
}

private BitVector deserializeBitVector(final DataInput is) throws IOException, ClassNotFoundException {
public BitSet deserializeBitSet(final DataInput is) throws IOException, ClassNotFoundException {
int size = (Integer) deserialize(is);
long[] elements = (long[]) deserialize(is);
return new BitVector(elements, size);

// BitSet.valueOf() handles the long array correctly
return BitSet.valueOf(elements);
}

private void serializeGraphStoreConfiguration(final DataOutput out) throws IOException {
Expand Down Expand Up @@ -1558,10 +1578,10 @@ protected void serialize(final DataOutput out, final Object obj) throws IOExcept
GraphViewImpl b = (GraphViewImpl) obj;
out.write(GRAPH_VIEW);
serializeGraphView(out, b);
} else if (obj instanceof BitVector) {
BitVector bv = (BitVector) obj;
} else if (obj instanceof BitSet) {
BitSet bs = (BitSet) obj;
out.write(BIT_VECTOR);
serializeBitVector(out, bv);
serializeBitSet(out, bs);
} else if (obj instanceof GraphVersion) {
GraphVersion b = (GraphVersion) obj;
out.write(GRAPH_VERSION);
Expand Down Expand Up @@ -2122,7 +2142,7 @@ protected Object deserialize(DataInput is) throws IOException, ClassNotFoundExce
ret = deserializeGraphView(is);
break;
case BIT_VECTOR:
ret = deserializeBitVector(is);
ret = deserializeBitSet(is);
break;
case GRAPH_STORE_CONFIGURATION:
ret = deserializeGraphStoreConfiguration(is);
Expand Down
Loading