-
Notifications
You must be signed in to change notification settings - Fork 526
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* implement RamTable (#49) * implement RamTable * plugin ramtable to StandardHugeGrap.edges(query) * plugin ramtable to GraphTransaction.queryEdgesFromBackend(Query query) * allow config vertices/edges capacity of ramtable * support concurrent loading Change-Id: I4e1a5c06bd331dc29a92dcb76843990863dfe6ca * add Consumers class to util package Change-Id: I8765582ba4e9b5fe8de4300719612a84bfce89a3 * support load from file and export to file Change-Id: Iecfb5bad535e4954a325eb45b1d9def53fdb31c0 usage: graph.reloadRamtable(true)
- Loading branch information
Showing
17 changed files
with
2,247 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/ram/IntIntMap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright 2017 HugeGraph Authors | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with this | ||
* work for additional information regarding copyright ownership. The ASF | ||
* licenses this file to You under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package com.baidu.hugegraph.backend.store.ram; | ||
|
||
import java.io.DataInputStream; | ||
import java.io.DataOutputStream; | ||
import java.io.IOException; | ||
import java.util.Arrays; | ||
|
||
import com.baidu.hugegraph.HugeException; | ||
|
||
public final class IntIntMap implements RamMap { | ||
|
||
// TODO: use com.carrotsearch.hppc.IntIntHashMap instead | ||
private final int[] array; | ||
|
||
public IntIntMap(int capacity) { | ||
this.array = new int[capacity]; | ||
} | ||
|
||
public void put(long key, int value) { | ||
assert 0 <= key && key < Integer.MAX_VALUE; | ||
this.array[(int) key] = value; | ||
} | ||
|
||
public int get(long key) { | ||
assert 0 <= key && key < Integer.MAX_VALUE; | ||
return this.array[(int) key]; | ||
} | ||
|
||
@Override | ||
public void clear() { | ||
Arrays.fill(this.array, 0); | ||
} | ||
|
||
@Override | ||
public long size() { | ||
return this.array.length; | ||
} | ||
|
||
@Override | ||
public void writeTo(DataOutputStream buffer) throws IOException { | ||
buffer.writeInt(this.array.length); | ||
for (int value : this.array) { | ||
buffer.writeInt(value); | ||
} | ||
} | ||
|
||
@Override | ||
public void readFrom(DataInputStream buffer) throws IOException { | ||
int size = buffer.readInt(); | ||
if (size > this.array.length) { | ||
throw new HugeException("Invalid size %s, expect < %s", | ||
size, this.array.length); | ||
} | ||
for (int i = 0; i < size; i++) { | ||
int value = buffer.readInt(); | ||
this.array[i] = value; | ||
} | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/ram/IntLongMap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Copyright 2017 HugeGraph Authors | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with this | ||
* work for additional information regarding copyright ownership. The ASF | ||
* licenses this file to You under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package com.baidu.hugegraph.backend.store.ram; | ||
|
||
import java.io.DataInputStream; | ||
import java.io.DataOutputStream; | ||
import java.io.IOException; | ||
import java.util.Arrays; | ||
|
||
import com.baidu.hugegraph.HugeException; | ||
|
||
public final class IntLongMap implements RamMap { | ||
|
||
// TODO: use com.carrotsearch.hppc.IntLongHashMap instead | ||
private final long[] array; | ||
private int size; | ||
|
||
public IntLongMap(int capacity) { | ||
this.array = new long[capacity]; | ||
this.size = 0; | ||
} | ||
|
||
public void put(int key, long value) { | ||
if (key >= this.size || key < 0) { | ||
throw new HugeException("Invalid key %s", key); | ||
} | ||
this.array[key] = value; | ||
} | ||
|
||
public int add(long value) { | ||
if (this.size == Integer.MAX_VALUE) { | ||
throw new HugeException("Too many edges %s", this.size); | ||
} | ||
int index = this.size; | ||
this.array[index] = value; | ||
this.size++; | ||
return index; | ||
} | ||
|
||
public long get(int key) { | ||
if (key >= this.size || key < 0) { | ||
throw new HugeException("Invalid key %s", key); | ||
} | ||
return this.array[key]; | ||
} | ||
|
||
@Override | ||
public void clear() { | ||
Arrays.fill(this.array, 0L); | ||
} | ||
|
||
@Override | ||
public long size() { | ||
return this.size; | ||
} | ||
|
||
@Override | ||
public void writeTo(DataOutputStream buffer) throws IOException { | ||
buffer.writeInt(this.array.length); | ||
for (long value : this.array) { | ||
buffer.writeLong(value); | ||
} | ||
} | ||
|
||
@Override | ||
public void readFrom(DataInputStream buffer) throws IOException { | ||
int size = buffer.readInt(); | ||
if (size > this.array.length) { | ||
throw new HugeException("Invalid size %s, expect < %s", | ||
size, this.array.length); | ||
} | ||
for (int i = 0; i < size; i++) { | ||
long value = buffer.readLong(); | ||
this.array[i] = value; | ||
} | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/ram/IntObjectMap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright 2017 HugeGraph Authors | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with this | ||
* work for additional information regarding copyright ownership. The ASF | ||
* licenses this file to You under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package com.baidu.hugegraph.backend.store.ram; | ||
|
||
import java.io.DataInputStream; | ||
import java.io.DataOutputStream; | ||
import java.io.IOException; | ||
import java.util.Arrays; | ||
|
||
import com.baidu.hugegraph.exception.NotSupportException; | ||
|
||
public final class IntObjectMap<V> implements RamMap { | ||
|
||
private final Object[] array; | ||
|
||
public IntObjectMap(int size) { | ||
this.array = new Object[size]; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public V get(int key) { | ||
return (V) this.array[key]; | ||
} | ||
|
||
public void set(int key, V value) { | ||
this.array[key] = value; | ||
} | ||
|
||
@Override | ||
public void clear() { | ||
Arrays.fill(this.array, null); | ||
} | ||
|
||
@Override | ||
public long size() { | ||
return this.array.length; | ||
} | ||
|
||
@Override | ||
public void writeTo(DataOutputStream buffer) throws IOException { | ||
throw new NotSupportException("IntObjectMap.writeTo"); | ||
} | ||
|
||
@Override | ||
public void readFrom(DataInputStream buffer) throws IOException { | ||
throw new NotSupportException("IntObjectMap.readFrom"); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
hugegraph-core/src/main/java/com/baidu/hugegraph/backend/store/ram/RamMap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2017 HugeGraph Authors | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with this | ||
* work for additional information regarding copyright ownership. The ASF | ||
* licenses this file to You under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package com.baidu.hugegraph.backend.store.ram; | ||
|
||
import java.io.DataInputStream; | ||
import java.io.DataOutputStream; | ||
import java.io.IOException; | ||
|
||
public interface RamMap { | ||
|
||
public void clear(); | ||
|
||
public long size(); | ||
|
||
public void writeTo(DataOutputStream buffer) throws IOException; | ||
|
||
public void readFrom(DataInputStream buffer) throws IOException; | ||
} |
Oops, something went wrong.