-
Notifications
You must be signed in to change notification settings - Fork 521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Collection optimize for OLTP algorithm and HugeElement #1409
Conversation
@@ -84,6 +84,7 @@ public String get(@Context GraphManager manager, | |||
HugeTraverser.PathSet paths = traverser.paths(sourceId, dir, targetId, | |||
dir, edgeLabel, depth, | |||
degree, capacity, limit); | |||
return manager.serializer(g).writePaths("crosspoints", paths, true); | |||
return manager.serializer(g).writePaths("crosspoints", | |||
paths.paths(),true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space
@@ -225,6 +225,12 @@ public long asLong() { | |||
return 0L; | |||
} | |||
|
|||
@Override | |||
public int asInt() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't add this method, just force convert it
HugeGraph graph = ownerVertex.graph(); | ||
VertexLabel srcLabel = graph.vertexLabelOrNone(edgeLabel.sourceLabel()); | ||
VertexLabel tgtLabel = graph.vertexLabelOrNone(edgeLabel.targetLabel()); | ||
|
||
VertexLabel otherVertexLabel; | ||
if (isOutEdge) { | ||
ownerVertex.correctVertexLabel(srcLabel); | ||
// ownerVertex.correctVertexLabel(srcLabel); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep the origin
otherVertexLabel = tgtLabel; | ||
} else { | ||
ownerVertex.correctVertexLabel(tgtLabel); | ||
// ownerVertex.correctVertexLabel(tgtLabel); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
@@ -98,7 +100,7 @@ protected void updateToDefaultValueIfNone() { | |||
this.defaultValueUpdated = true; | |||
// Set default value if needed | |||
for (Id pkeyId : this.schemaLabel().properties()) { | |||
if (this.properties.containsKey(pkeyId)) { | |||
if (this.properties.containsKey(pkeyId.asInt())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a static method numberFromId(id)
@@ -55,7 +55,7 @@ public void traverseOneLayer(Map<Id, List<Node>> vertices, | |||
|
|||
@Override | |||
public Set<Path> newPathSet() { | |||
return new HugeTraverser.PathSet(); | |||
return new HugeTraverser.PathSet().paths(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return HugeTraverser.PathSet()?
case 1: | ||
return JCF; | ||
case 2: | ||
return EC; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add case 3 for FastUtil
|
||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; | ||
|
||
public class IdSet extends HashSet<Id> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set final and implement Set<Id>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
implement Set need to implements toArray(), containsAll(), retainAll()... methods. which will be same as implemented in AbstractSet and HashSet. extends HashSet can reduce these duplicated work
|
||
private static class EcLongIterator implements Iterator<Long> { | ||
|
||
private MutableLongIterator iterator; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set final
ExtendableIterator<Id> iterator = new ExtendableIterator<>(); | ||
iterator.extend(this.nonNumberIds.iterator()); | ||
EcLongIterator iter = new EcLongIterator(this.numberIds.longIterator()); | ||
iterator.extend(new MapperIterator<>(iter, IdGenerator::of)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let EcLongIterator return Id
97d3f65
to
cdc64f4
Compare
@@ -50,6 +45,11 @@ | |||
import com.codahale.metrics.annotation.Timed; | |||
import com.fasterxml.jackson.annotation.JsonProperty; | |||
|
|||
import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_CAPACITY; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep origin place
@@ -47,6 +44,9 @@ | |||
import com.baidu.hugegraph.util.Log; | |||
import com.codahale.metrics.annotation.Timed; | |||
|
|||
import static com.baidu.hugegraph.traversal.algorithm.HugeTraverser.DEFAULT_DEGREE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.QueryParam; | ||
import javax.ws.rs.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't use *
private int accessed; | ||
|
||
public ArrayPathsRecord(Id sourceV, Id targetV) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove empty line
} | ||
} | ||
|
||
public static void main(String[] args) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move to unit test
return (Id) this.idMapping.code2Object(code); | ||
} | ||
|
||
public static class Int2IntsMap { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move out as an independent file
private static final int CHUNK_SIZE = 10; | ||
|
||
private IntIntHashMap offsetMap; | ||
private int[] intsTable; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add some comments
private IntIntHashMap offsetMap; | ||
private int[] intsTable; | ||
|
||
private int nextBlock; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
intsTableAlloc
this.intsTable[position] = this.nextBlock; | ||
|
||
this.intsTable[this.nextBlock] = value; | ||
this.intsTable[positionIndex] = this.nextBlock + 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why +1, prefer define const
|
||
} else { | ||
intsTable[position] = value; | ||
this.intsTable[positionIndex]++; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
++this.intsTable[firstBlockPointer + SIZE_OFFSET]
// Update next block | ||
this.nextBlock += CHUNK_SIZE; | ||
|
||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
swap if-statement and the else code block
this.offsetMap.put(key, this.nextBlock); | ||
|
||
// Init first chunk | ||
this.intsTable[this.nextBlock] = this.nextBlock + 3; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
define const var for all the const values
} | ||
|
||
private boolean endOfChunk(int position) { | ||
return (position + 1) % CHUNK_SIZE == 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
@@ -266,17 +277,18 @@ public int sizeOfSubProperties() { | |||
@Watched(prefix = "element") | |||
public <V> HugeProperty<?> setProperty(HugeProperty<V> prop) { | |||
if (this.properties == EMPTY_MAP) { | |||
this.properties = new HashMap<>(); | |||
this.properties = new IntObjectHashMap<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we extends IntObjectHashMap and implement Map interface
@@ -266,17 +277,18 @@ public int sizeOfSubProperties() { | |||
@Watched(prefix = "element") | |||
public <V> HugeProperty<?> setProperty(HugeProperty<V> prop) { | |||
if (this.properties == EMPTY_MAP) { | |||
this.properties = new HashMap<>(); | |||
this.properties = new IntObjectHashMap<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also call CollectionFactory.newIntObjectMap()
} | ||
|
||
public void resetEdges() { | ||
this.edges = InsertionOrderUtil.newSet(); | ||
this.edges = new FastList<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
call CollectionFactory
if (this.edges == EMPTY_SET) { | ||
this.edges = InsertionOrderUtil.newSet(); | ||
if (this.edges == EMPTY_LIST) { | ||
this.edges = new FastList<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
call CollectionFactory
this.edges = newSet(); | ||
} | ||
|
||
public void removeEdge(HugeEdge edge) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seem unused, remove this method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
used in HugeEdge.remove()
private boolean foundPath; | ||
|
||
public ShortestPathRecord(Id sourceV, Id targetV) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove empty line
import com.baidu.hugegraph.util.collection.ObjectIntMapping; | ||
import com.google.common.collect.Lists; | ||
|
||
public class PathsRecord implements Record { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it the same function as ArrayPathsRecord
import com.baidu.hugegraph.backend.id.Id; | ||
import com.baidu.hugegraph.traversal.algorithm.HugeTraverser.PathSet; | ||
|
||
public interface Record { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer Records
this.targetLayers.peek().keySet().intIterator(); | ||
} | ||
|
||
public void finishOneLayer() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seem all the subclass are the same mode, abstract it
this.sourceLayers = new Stack<>(); | ||
this.targetLayers = new Stack<>(); | ||
this.sourceLayers.push(firstSourceLayer); | ||
this.targetLayers.push(firstTargetLayer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer to split into two layers: fanout and source-target, and abstract source-target layer to the top of all record implement
private PathSet getTargetPath(int target) { | ||
return this.concatPath(this.targetLayers, target, | ||
this.targetLayers.size() - 1); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move these 2 methods to line 152
return results; | ||
} | ||
|
||
private PathSet concatPath(Stack<Int2IntsMap> all, int id, int layerIndex) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to linkPath
return results; | ||
} | ||
|
||
private PathSet getSourcePath(int source) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to linkSourcePath
private static final int CHUNK_SIZE = 10; | ||
private static final int POSITION_OFFSET = 0; | ||
private static final int SIZE_OFFSET = 1; | ||
private static final int FIRST_CHUNK_DATA_OFFSET = 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer prefix with OFFSET_XX
* | ||
*/ | ||
|
||
private IntIntHashMap firstChunkMap; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chunkMap is ok
IntIntHashMap layer = this.targetLayers.elementAt(i); | ||
value = layer.get(value); | ||
ids.add(this.id(value)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also split linkSourcePath() and linkTargetPath()
this.currentLayer.put(target, source); | ||
} | ||
|
||
private Path getPath(int source, int target) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also rename to concatPath()
import org.eclipse.collections.api.iterator.IntIterator; | ||
import org.eclipse.collections.impl.map.mutable.primitive.IntIntHashMap; | ||
|
||
public class Int2IntsMap { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move to collection package
import com.baidu.hugegraph.util.collection.ObjectIntMapping; | ||
import com.google.common.collect.Lists; | ||
|
||
public class ArrayPathsRecords implements Records { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MultiPathsPerVertexRecords or MultiPathsRecords
import com.baidu.hugegraph.util.collection.ObjectIntMapping; | ||
import com.google.common.collect.Lists; | ||
|
||
public class PathsRecords implements Records { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MultiPathsBySetRecords
|
||
public class IntArrayIterator implements IntIterator { | ||
|
||
private int[] array; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set final
|
||
public class IntArrayRecord implements Record { | ||
|
||
private Int2IntsMap layer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set final
|
||
public class IntIntRecord implements Record { | ||
|
||
private IntIntHashMap layer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set final
|
||
public class IntSetRecord implements Record { | ||
|
||
private IntObjectHashMap<IntHashSet> layer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set final
|
||
import org.eclipse.collections.api.iterator.IntIterator; | ||
|
||
public interface Record { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not addressed: prefer Records
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there already exists Records for multi layers. Record means one layer paths here
hugegraph-test/src/main/java/com/baidu/hugegraph/unit/util/JsonUtilTest.java
Show resolved
Hide resolved
hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/CollectionFactory.java
Show resolved
Hide resolved
|
||
package com.baidu.hugegraph.type.define; | ||
|
||
public enum CollectionImplType implements SerialEnum { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add unit test
this.sourceRecords = new Stack<>(); | ||
this.targetRecords = new Stack<>(); | ||
this.sourceRecords.push(firstSourceRecord); | ||
this.targetRecords.push(firstTargetRecord); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can abstract source and target code as 2 instances(of one class)?
public void add(int key, int value) { | ||
if (this.chunkMap.containsKey(key)) { | ||
int firstChunk = this.chunkMap.get(key); | ||
int nextPosition = this.chunkTable[firstChunk + OFFSET_POSITION]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the meaning of position is generic, improve the variable naming to nextXxPointer.
also address other comments:
https://github.com/hugegraph/hugegraph/pull/1409/files/75b2ef6c4de64306b75d7b91d1672c32e057360b..7248e77a062d8e375f2ef85e06ec16d5b5373337#diff-c6fe21c746e89abdbac5015ba5d5b3ec346aef2dd756922bac904958cd2aabea
7456243
to
5b56077
Compare
return this.customizedKneighbor(source, step, maxDepth, | ||
limit, single); | ||
Traverser traverser = new Traverser(source, step, maxDepth, limit, | ||
single); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to singleThread
|
||
List<HugeTraverser.Path> paths = new ArrayList<>(); | ||
PathSet paths = new PathSet(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also keep HugeTraverser.PathSet
all.add(sourceV); | ||
private final EdgeStep step; | ||
private final long limit; | ||
private final boolean single; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to concurrent
long limit, boolean single) { | ||
Set<Node> latest = newSet(single); | ||
Set<Node> all = newSet(single); | ||
private class Traverser { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems unneeded to add this class, just add a method?
} | ||
|
||
protected long traverseIds(Iterator<Id> ids, Consumer<Id> consumer, | ||
boolean single, boolean stop) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename single to concurrent
default: | ||
throw new AssertionError("Unsupported record type: " + type); | ||
} | ||
if (!single) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
...ph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/records/record/SyncRecord.java
Show resolved
Hide resolved
|
||
@Override | ||
public int size() { | ||
return this.record.size(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also synchronized
@@ -31,12 +31,12 @@ | |||
private final IntObjectHashMap<V> int2IdMap; | |||
|
|||
public ObjectIntMapping() { | |||
this.int2IdMap = new IntObjectHashMap<>(1000000); | |||
this.int2IdMap = new IntObjectHashMap<>(10000000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
define const var
} | ||
|
||
@Watched | ||
@SuppressWarnings("unchecked") | ||
public int object2Code(Object object) { | ||
public synchronized int object2Code(Object object) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
always synchronized?
Codecov Report
@@ Coverage Diff @@
## master #1409 +/- ##
============================================
- Coverage 64.05% 63.54% -0.52%
- Complexity 5882 5975 +93
============================================
Files 381 402 +21
Lines 32190 32733 +543
Branches 4506 4558 +52
============================================
+ Hits 20620 20800 +180
- Misses 9463 9810 +347
- Partials 2107 2123 +16
Continue to review full report at Codecov.
|
@@ -34,8 +34,8 @@ | |||
|
|||
public KoutRecords(Id source, | |||
RecordType type, | |||
boolean nearest, boolean single) { | |||
super(source, type, nearest, single); | |||
boolean nearest, boolean concurrent) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move "RecordType type" to the first line?
@@ -68,8 +68,8 @@ public SingleWayMultiPathsRecords(Id source, RecordType type, | |||
this.records = new Stack<>(); | |||
this.records.push(firstRecord); | |||
|
|||
this.accessedVertices = single ? new HashSet() : | |||
ConcurrentHashMap.newKeySet(); | |||
this.accessedVertices = concurrent ? ConcurrentHashMap.newKeySet() : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also use primitive map
} | ||
|
||
@Watched | ||
@PerfUtil.Watched |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove "PerfUtil."
@@ -55,7 +55,7 @@ public synchronized int object2Code(Object object) { | |||
throw new HugeException("Failed to get code for id: %s", object); | |||
} | |||
|
|||
@Watched | |||
@PerfUtil.Watched |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
...re/src/main/java/com/baidu/hugegraph/util/collection/mapping/ConcurrentObjectIntMapping.java
Outdated
Show resolved
Hide resolved
...h-core/src/main/java/com/baidu/hugegraph/util/collection/mapping/SingleObjectIntMapping.java
Outdated
Show resolved
Hide resolved
3a51a42
to
be0eaea
Compare
cache tick()
output when tick() run:
|
TODO:
|
1ae39a7
to
4889059
Compare
hugegraph-core/src/main/java/com/baidu/hugegraph/structure/HugeVertex.java
Show resolved
Hide resolved
...-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/FusiformSimilarityTraverser.java
Show resolved
Hide resolved
...-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/FusiformSimilarityTraverser.java
Show resolved
Hide resolved
@@ -96,14 +103,19 @@ protected int concurrentDepth() { | |||
return this.graph.option(CoreOptions.OLTP_CONCURRENT_DEPTH); | |||
} | |||
|
|||
private CollectionImplType collectionImplType() { | |||
return CollectionImplType.valueOf(this.graph.option( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use ConfigConvOption
query.limit(limit); | ||
result = new LimitIterator<>(iterators, e -> { | ||
long count = query.goOffset(1L); | ||
return query.reachLimit(count - 1L); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rebase master
Iterator<Edge> edges = this.edgesOfVertex(source.id(), step); | ||
while (edges.hasNext()) { | ||
Id target = ((HugeEdge) edges.next()).id().otherVertexId(); | ||
KNode kNode = new KNode(target, (KNode) source); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can use layer collection?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this method will be deleted.
...rc/main/java/com/baidu/hugegraph/traversal/algorithm/records/DoubleWayMultiPathsRecords.java
Show resolved
Hide resolved
|
||
public class CollectionFactory { | ||
|
||
private CollectionImplType type; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to CollectionType
@@ -664,5 +679,9 @@ protected GraphTransaction tx() { | |||
} | |||
return null; | |||
} | |||
|
|||
private static <V> Set<V> newSet() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move to outer class, also add newList() for HugeVertex.resetEdges()
} | ||
|
||
public int size() { | ||
return 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ensure "return 0" is expected?
4889059
to
224d26b
Compare
hugegraph-core/src/main/java/com/baidu/hugegraph/config/CoreOptions.java
Show resolved
Hide resolved
@@ -624,12 +625,13 @@ public static synchronized CoreOptions instance() { | |||
10 | |||
); | |||
|
|||
public static final ConfigOption<String> OLTP_COLLECTION_IMPL_TYPE = | |||
new ConfigOption<>( | |||
public static final ConfigConvOption<String, CollectionType> OLTP_COLLECTION_IMPL_TYPE = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OLTP_COLLECTION_TYPE
@@ -232,7 +236,7 @@ public void removeEdge(HugeEdge edge) { | |||
|
|||
public void addEdge(HugeEdge edge) { | |||
if (this.edges == EMPTY_LIST) { | |||
this.edges = CollectionFactory.newList(CollectionImplType.EC); | |||
this.edges = CollectionFactory.newList(CollectionType.EC); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
call newList();
private CollectionImplType collectionImplType() { | ||
return CollectionImplType.valueOf(this.graph.option( | ||
CoreOptions.OLTP_COLLECTION_IMPL_TYPE).toUpperCase()); | ||
private CollectionType collectionImplType() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
collectionType
|
||
List<HugeTraverser.Path> paths = new ArrayList<>(); | ||
PathSet paths = new PathSet(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also use HugeTraverser.PathSet
...ph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/records/record/SyncRecord.java
Show resolved
Hide resolved
(int) age.id().asLong(), | ||
new HugeVertexProperty<>(vertex, age, 29), | ||
(int) city.id().asLong(), | ||
new HugeVertexProperty<>(vertex, city, "Beijing") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let newIntObjectMap accept <Id,Property>
(int) date.id().asLong(), | ||
new HugeEdgeProperty<>(edge, date, Utils.date("2019-03-12")), | ||
(int) weight.id().asLong(), | ||
new HugeEdgeProperty<>(edge, weight, 0.8) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
224d26b
to
b3969e4
Compare
E.checkArgument(objects.length % 2 == 0, | ||
"Must provide even arguments for " + | ||
"CollectionFactory.newIntObjectMap"); | ||
for (int i = 0; i < objects.length; i+=2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i += 2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not addressed: i += 2
hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/CollectionFactory.java
Show resolved
Hide resolved
|
||
|
||
/* | ||
* chunkMap chunkTable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add some spaces before chunkTable to align with the following table
hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/Int2IntsMap.java
Show resolved
Hide resolved
hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/Int2IntsMap.java
Show resolved
Hide resolved
hugegraph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/records/Records.java
Show resolved
Hide resolved
|
||
import com.baidu.hugegraph.util.collection.Int2IntsMap; | ||
|
||
public class IntArrayRecord implements Record { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Int2ArrayRecord
|
||
import org.eclipse.collections.impl.map.mutable.primitive.IntIntHashMap; | ||
|
||
public class IntIntRecord implements Record { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Int2IntRecord
import org.eclipse.collections.impl.map.mutable.primitive.IntObjectHashMap; | ||
import org.eclipse.collections.impl.set.mutable.primitive.IntHashSet; | ||
|
||
public class IntSetRecord implements Record { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Int2SetRecord
import com.baidu.hugegraph.traversal.algorithm.records.record.RecordType; | ||
import com.google.common.collect.Lists; | ||
|
||
public class DoubleWayMultiPathsRecords extends AbstractRecords { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set abstract?
@@ -46,7 +46,7 @@ | |||
protected final Stack<Record> records; | |||
|
|||
private final boolean nearest; | |||
private final MutableIntSet accessedVertices; | |||
protected final MutableIntSet accessedVertices; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep k-out and k-neighbor consistent
hugegraph-core/src/main/java/com/baidu/hugegraph/util/collection/CollectionFactory.java
Show resolved
Hide resolved
@@ -107,6 +108,7 @@ | |||
PageStateTest.class, | |||
Int2IntsMapTest.class, | |||
ObjectIntMappingTest.class, | |||
IdSet.class, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IdSetTest
E.checkArgument(objects.length % 2 == 0, | ||
"Must provide even arguments for " + | ||
"CollectionFactory.newIntObjectMap"); | ||
for (int i = 0; i < objects.length; i+=2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not addressed: i += 2
(int) key2.asLong(), value2); | ||
} | ||
|
||
public static <V> MutableIntObjectMap<V> newIntObjectMap( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can remove this version method
protected Record currentRecord; | ||
private IntIterator lastRecordKeys; | ||
protected int current; | ||
protected boolean forward; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set fields to private as possible
private IntIterator lastRecordKeys; | ||
protected int current; | ||
protected boolean forward; | ||
private int current; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
means what
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mean int code of currently accessed vertex's Id
...aph-core/src/main/java/com/baidu/hugegraph/traversal/algorithm/records/KneighborRecords.java
Show resolved
Hide resolved
f400213
to
4392dcb
Compare
|
||
public abstract class HugeElement implements Element, GraphType, Idfiable { | ||
|
||
private static final Map<Id, HugeProperty<?>> EMPTY_MAP = ImmutableMap.of(); | ||
private static final MutableIntObjectMap<HugeProperty<?>> EMPTY_MAP = | ||
new IntObjectHashMap<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
= CollectionFactory.newIntObjectMap();
@Watched | ||
@SuppressWarnings("unchecked") | ||
public int object2Code(Object object) { | ||
int key = object.hashCode(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
key -> code
...aph-core/src/main/java/com/baidu/hugegraph/util/collection/SingleThreadObjectIntMapping.java
Show resolved
Hide resolved
263,264,265,266,267,268,269}; | ||
results[4] = new int[]{270,271,272,273,274,275,276,277,278,279, | ||
280,281,282,283,284,285,286,287,288,289, | ||
290, 291,292,293,294,295,296,297,298,299}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
290, 291 -> 290,291
|
||
for (int ii = 0; ii < 5; ii++) { | ||
int[] result = map.getValues(ii + 1); | ||
Assert.assertTrue(Arrays.equals(results[ii], result)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assert.assertArrayEquals(results[ii], result);
...aph-core/src/main/java/com/baidu/hugegraph/util/collection/SingleThreadObjectIntMapping.java
Show resolved
Hide resolved
4392dcb
to
8427bdf
Compare
...aph-core/src/main/java/com/baidu/hugegraph/util/collection/SingleThreadObjectIntMapping.java
Outdated
Show resolved
Hide resolved
...aph-core/src/main/java/com/baidu/hugegraph/util/collection/SingleThreadObjectIntMapping.java
Show resolved
Hide resolved
...aph-core/src/main/java/com/baidu/hugegraph/util/collection/SingleThreadObjectIntMapping.java
Outdated
Show resolved
Hide resolved
...aph-core/src/main/java/com/baidu/hugegraph/util/collection/SingleThreadObjectIntMapping.java
Outdated
Show resolved
Hide resolved
Change-Id: I4b79d0987f1eebcfb952bc4627a2f4fc8d2dcaf3
Change-Id: Iffad898d0ff04f8b8937eb774352c853bae87aef
Change-Id: I0791e3d307f2cff51ccc4760ea63c52468a4b8d8
Change-Id: Ib653623d5cc79696f58ec50ccadca8ac7039c2f1
Change-Id: Ia6a8e3316c40ecf44f6f36c4cfee50db2f7d11fe
Change-Id: I9588f2df9a6db197dcd0d35c98b7d99993a9aabf
Change-Id: I1358fb9216dd2a8d04be0e8772cd715c79c61b1e
Change-Id: I580df88f57302dfe474108a93108759e33e083e2
8427bdf
to
8b8be47
Compare
* add Eclipse Collection dependency * use primitive map for properties of HugeElement * from Map<Id, HugeProperty<?>> to MutableIntObjectMap<HugeProperty<?>> * allow config oltp collections(JCF or EC) * add fastutil choice for collection * change Set<HugeEdge> of HugeVertex to List<HugeEdge> * use IntObjectMap and IntIntMap to improve shortest path * improve paths api by remove redundant sourcesAll and targetsAll * improve paths api performance by using IntObjectHashMap<IntHashSet> * extract shortestpath and paths record to hold traversed paths * implement Int2IntsMap for array paths record * extract Record and Records for paths and shortest path * adapt primitive collection for kout/kneighbor * add objectintmapping unit test * add UT for CollectionFactory and IdSet Change-Id: I501a18a70054fad3c40bd6b9e852a82a5c185949
No description provided.