├── .blaze ├── blaze.conf ├── blaze.java └── pom.xml ├── .github └── workflows │ ├── java11.yaml │ ├── java17.yaml │ ├── java21.yaml │ ├── java8.yaml │ ├── macos-arm64.yaml │ └── windows-x64.yaml ├── .gitignore ├── CHANGELOG.md ├── README.md ├── bigmap-bom └── pom.xml ├── bigmap-core ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── fizzed │ │ └── bigmap │ │ ├── BigMap.java │ │ ├── BigMapDataException.java │ │ ├── BigMapNonScalableException.java │ │ ├── BigObject.java │ │ ├── BigObjectCloser.java │ │ ├── BigObjectListener.java │ │ ├── BigObjectRegistry.java │ │ ├── BigSet.java │ │ ├── BigSortedMap.java │ │ ├── BigSortedSet.java │ │ ├── ByteCodec.java │ │ ├── ByteCodecs.java │ │ ├── Bytes.java │ │ ├── Comparators.java │ │ ├── MutableValue.java │ │ ├── SerializableByteCodec.java │ │ └── impl │ │ ├── AbstractBigLinkedMap.java │ │ ├── AbstractBigMap.java │ │ ├── AbstractBigMapBuilder.java │ │ ├── AbstractBigObjectBuilder.java │ │ ├── AbstractBigObjectCloser.java │ │ ├── AbstractBigSet.java │ │ ├── AbstractBigSetBuilder.java │ │ ├── BigLinkedMapCloser.java │ │ ├── BigMapEntrySet.java │ │ ├── BigMapHelper.java │ │ ├── BigMapKeySet.java │ │ ├── BigMapValueCollection.java │ │ ├── BigObjectWeakReference.java │ │ ├── ByteArrayBigMap.java │ │ ├── KeyValueBytes.java │ │ ├── MapMutableValue.java │ │ └── None.java │ └── test │ └── java │ └── com │ └── fizzed │ └── bigmap │ ├── ByteCodecsTest.java │ ├── BytesTest.java │ └── ComparatorsTest.java ├── bigmap-demo ├── pom.xml └── src │ └── test │ ├── java │ └── com │ │ └── fizzed │ │ └── bigmap │ │ ├── AbstractPerf.java │ │ ├── MapDemo.java │ │ ├── OffheapMap.java │ │ ├── PerfManyMaps.java │ │ └── PerfThroughput.java │ └── resources │ └── logback.xml ├── bigmap-integration-tests ├── pom.xml └── src │ └── test │ └── java │ └── com │ └── fizzed │ └── bigmap │ ├── AbstractBigLinkedMapTest.java │ ├── AbstractBigLinkedSetTest.java │ ├── AbstractBigMapTest.java │ ├── AbstractBigSetTest.java │ ├── JavaHashMapTest.java │ ├── JavaHashSetTest.java │ ├── JavaLinkedHashMapTest.java │ ├── JavaTreeMapTest.java │ ├── JavaTreeSetTest.java │ ├── LevelBigLinkedMapTest.java │ ├── LevelBigLinkedSetTest.java │ ├── LevelBigMapTest.java │ ├── LevelBigSetTest.java │ ├── RocksBigLinkedMapTest.java │ ├── RocksBigLinkedSetTest.java │ ├── RocksBigMapTest.java │ ├── RocksBigSetTest.java │ ├── TestIdentifier.java │ ├── TkrzwBigLinkedMapTest.java │ ├── TkrzwBigLinkedSetTest.java │ ├── TkrzwBigMapTest.java │ ├── TkrzwBigSetTest.java │ ├── TokyoBigLinkedMapTest.java │ ├── TokyoBigLinkedSetTest.java │ ├── TokyoBigMapTest.java │ └── TokyoBigSetTest.java ├── bigmap-jackson ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── fizzed │ │ └── bigmap │ │ └── jackson │ │ └── JacksonByteCodec.java │ └── test │ └── java │ └── com │ └── fizzed │ └── bigmap │ └── jackson │ └── JacksonByteCodecTest.java ├── bigmap-kryo ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── fizzed │ │ └── bigmap │ │ └── kryo │ │ └── KryoByteCodec.java │ └── test │ └── java │ └── com │ └── fizzed │ └── bigmap │ └── kryo │ └── KryoByteCodecTest.java ├── bigmap-leveldb ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── fizzed │ │ └── bigmap │ │ └── leveldb │ │ ├── LevelBigLinkedMap.java │ │ ├── LevelBigLinkedMapBuilder.java │ │ ├── LevelBigLinkedSet.java │ │ ├── LevelBigLinkedSetBuilder.java │ │ ├── LevelBigMap.java │ │ ├── LevelBigMapBuilder.java │ │ ├── LevelBigObjectCloser.java │ │ ├── LevelBigSet.java │ │ ├── LevelBigSetBuilder.java │ │ ├── LevelForwardIterator.java │ │ └── LevelJavaComparator.java │ └── test │ └── java │ └── com │ └── fizzed │ └── bigmap │ └── leveldb │ └── LevelBigMapTest.java ├── bigmap-rocksdb ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── fizzed │ │ └── bigmap │ │ └── rocksdb │ │ ├── RocksBigLinkedMap.java │ │ ├── RocksBigLinkedMapBuilder.java │ │ ├── RocksBigLinkedSet.java │ │ ├── RocksBigLinkedSetBuilder.java │ │ ├── RocksBigMap.java │ │ ├── RocksBigMapBuilder.java │ │ ├── RocksBigObjectCloser.java │ │ ├── RocksBigSet.java │ │ ├── RocksBigSetBuilder.java │ │ ├── RocksForwardIterator.java │ │ └── RocksJavaComparator.java │ └── test │ └── java │ └── com │ └── fizzed │ └── bigmap │ └── rocksdb │ └── RocksBigMapTest.java ├── bigmap-tkrzw ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── fizzed │ │ └── bigmap │ │ └── tkrzw │ │ ├── TkrzwBigLinkedMap.java │ │ ├── TkrzwBigLinkedMapBuilder.java │ │ ├── TkrzwBigLinkedSet.java │ │ ├── TkrzwBigLinkedSetBuilder.java │ │ ├── TkrzwBigMap.java │ │ ├── TkrzwBigMapBuilder.java │ │ ├── TkrzwBigObjectCloser.java │ │ ├── TkrzwBigSet.java │ │ ├── TkrzwBigSetBuilder.java │ │ └── TkrzwForwardIterator.java │ └── test │ └── java │ └── com │ └── fizzed │ └── bigmap │ └── tkrzw │ ├── TkrzwBigMapTest.java │ └── TkrzwBigSetTest.java ├── bigmap-tokyocabinet ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── fizzed │ │ └── bigmap │ │ └── tokyocabinet │ │ ├── TokyoBigLinkedMap.java │ │ ├── TokyoBigLinkedMapBuilder.java │ │ ├── TokyoBigLinkedSet.java │ │ ├── TokyoBigLinkedSetBuilder.java │ │ ├── TokyoBigMap.java │ │ ├── TokyoBigMapBuilder.java │ │ ├── TokyoBigObjectCloser.java │ │ ├── TokyoBigSet.java │ │ ├── TokyoBigSetBuilder.java │ │ └── TokyoForwardIterator.java │ └── test │ └── java │ └── com │ └── fizzed │ └── bigmap │ └── tokyocabinet │ ├── TokyoBigMapTest.java │ └── TokyoBigSetTest.java ├── blaze.jar ├── buildx-results.txt └── pom.xml /.blaze/blaze.conf: -------------------------------------------------------------------------------- 1 | blaze.dependencies = [ 2 | "com.fizzed:blaze-ssh" 3 | "com.fizzed:blaze-public-project:1.0.1" 4 | ] 5 | 6 | java.source.version = 8 -------------------------------------------------------------------------------- /.blaze/blaze.java: -------------------------------------------------------------------------------- 1 | import com.fizzed.blaze.project.PublicBlaze; 2 | 3 | public class blaze extends PublicBlaze { 4 | 5 | // all public blaze methods 6 | 7 | } -------------------------------------------------------------------------------- /.blaze/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | blaze 4 | bigmap-blaze 5 | 0.0.1 6 | 7 | 12 | 13 | 14 | 8 15 | 8 16 | true 17 | true 18 | 19 | 20 | ${project.basedir} 21 | 22 | 23 | 24 | org.apache.ivy 25 | ivy 26 | 2.5.2 27 | 28 | 29 | com.fizzed 30 | blaze-core 31 | 1.8.0 32 | 33 | 34 | commons-io 35 | commons-io 36 | 2.16.1 37 | 38 | 39 | com.typesafe 40 | config 41 | 1.4.3 42 | 43 | 44 | com.fizzed 45 | blaze-ivy 46 | 1.8.0 47 | 48 | 49 | org.slf4j 50 | slf4j-simple 51 | 2.0.13 52 | 53 | 54 | org.slf4j 55 | slf4j-api 56 | 2.0.13 57 | 58 | 59 | org.zeroturnaround 60 | zt-exec 61 | 1.12 62 | 63 | 64 | com.fizzed 65 | blaze-ssh 66 | 1.8.0 67 | 68 | 69 | com.fizzed 70 | blaze-public-project 71 | 1.0.0 72 | 73 | 74 | -------------------------------------------------------------------------------- /.github/workflows/java11.yaml: -------------------------------------------------------------------------------- 1 | name: Java 11 2 | on: 3 | - push 4 | - workflow_dispatch 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v3 10 | - name: Set up Azul JDK 11 11 | uses: actions/setup-java@v3 12 | with: 13 | java-version: 11 14 | distribution: 'zulu' 15 | cache: 'maven' 16 | - name: Test in Maven 17 | run: mvn --no-transfer-progress -B test -------------------------------------------------------------------------------- /.github/workflows/java17.yaml: -------------------------------------------------------------------------------- 1 | name: Java 17 2 | on: 3 | - push 4 | - workflow_dispatch 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v3 10 | - name: Set up Azul JDK 17 11 | uses: actions/setup-java@v3 12 | with: 13 | java-version: 17 14 | distribution: 'zulu' 15 | cache: 'maven' 16 | - name: Test in Maven 17 | run: mvn --no-transfer-progress -B test -------------------------------------------------------------------------------- /.github/workflows/java21.yaml: -------------------------------------------------------------------------------- 1 | name: Java 21 2 | on: 3 | - push 4 | - workflow_dispatch 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v3 10 | - name: Set up Azul JDK 21 11 | uses: actions/setup-java@v3 12 | with: 13 | java-version: 21 14 | distribution: 'zulu' 15 | cache: 'maven' 16 | - name: Test in Maven 17 | run: mvn --no-transfer-progress -B test -------------------------------------------------------------------------------- /.github/workflows/java8.yaml: -------------------------------------------------------------------------------- 1 | name: Java 8 2 | on: 3 | - push 4 | - workflow_dispatch 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v3 10 | - name: Set up Azul JDK 8 11 | uses: actions/setup-java@v3 12 | with: 13 | java-version: 8 14 | distribution: 'zulu' 15 | cache: 'maven' 16 | - name: Test in Maven 17 | run: mvn --no-transfer-progress -B test -------------------------------------------------------------------------------- /.github/workflows/macos-arm64.yaml: -------------------------------------------------------------------------------- 1 | name: MacOS arm64 2 | on: 3 | - push 4 | - workflow_dispatch 5 | jobs: 6 | build: 7 | runs-on: macos-latest 8 | steps: 9 | - uses: actions/checkout@v3 10 | - name: Set up Azul JDK 11 11 | uses: actions/setup-java@v3 12 | with: 13 | java-version: 11 14 | distribution: 'zulu' 15 | cache: 'maven' 16 | - name: Test in Maven 17 | run: mvn --no-transfer-progress -B test -------------------------------------------------------------------------------- /.github/workflows/windows-x64.yaml: -------------------------------------------------------------------------------- 1 | name: Windows x64 2 | on: 3 | - push 4 | - workflow_dispatch 5 | jobs: 6 | build: 7 | runs-on: windows-latest 8 | steps: 9 | - uses: actions/checkout@v3 10 | - name: Set up Azul JDK 11 11 | uses: actions/setup-java@v3 12 | with: 13 | java-version: 11 14 | distribution: 'zulu' 15 | cache: 'maven' 16 | - name: Test in Maven 17 | run: mvn --no-transfer-progress -B test -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | *.iml 3 | nb-configuration.xml 4 | .idea 5 | .buildx 6 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Bigmap for Java 2 | 3 | ## 1.1.0 - 2025-01-22 4 | - Bump tokyocabinet v0.0.16 (new support for freebsd/openbsd) 5 | - Bump tkrzw v0.0.9 (new support for freebsd/openbsd) 6 | - Bump rocksdb v9.8.4 7 | - Bump kryo v5.6.2 8 | 9 | ## 1.0.16 - 2023-11-04 10 | - Improved build system for cross testing different JDK versions 11 | - Bump tokyocabinet v0.0.15 12 | - Bump tkrzw v0.0.8 13 | - Bump rocksdb v8.3.2 14 | - CI workflows for Java 21 15 | 16 | ## 1.0.15 - 2023-01-18 17 | - Many releases before this one, starting changelog -------------------------------------------------------------------------------- /bigmap-bom/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | bigmap-bom 5 | bigmap-bom 6 | pom 7 | 8 | 9 | com.fizzed 10 | bigmap 11 | 1.1.1-SNAPSHOT 12 | 13 | 14 | 15 | 16 | 17 | 18 | com.fizzed 19 | bigmap-core 20 | ${project.version} 21 | 22 | 23 | 24 | com.fizzed 25 | bigmap-kryo 26 | ${project.version} 27 | 28 | 29 | 30 | com.fizzed 31 | bigmap-jackson 32 | ${project.version} 33 | 34 | 35 | 36 | com.fizzed 37 | bigmap-leveldb 38 | ${project.version} 39 | 40 | 41 | 42 | com.fizzed 43 | bigmap-rocksdb 44 | ${project.version} 45 | 46 | 47 | 48 | com.fizzed 49 | bigmap-tokyocabinet 50 | ${project.version} 51 | 52 | 53 | 54 | com.fizzed 55 | bigmap-tkrzw 56 | ${project.version} 57 | 58 | 59 | 60 | 61 | com.fizzed 62 | tokyocabinet-bom 63 | ${tokyocabinet.version} 64 | pom 65 | import 66 | 67 | 68 | 69 | 70 | com.fizzed 71 | tkrzw-bom 72 | ${tkrzw.version} 73 | pom 74 | import 75 | 76 | 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /bigmap-core/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | bigmap-core 5 | bigmap-core 6 | jar 7 | 8 | 9 | com.fizzed 10 | bigmap 11 | 1.1.1-SNAPSHOT 12 | 13 | 14 | 15 | 16 | 17 | org.slf4j 18 | slf4j-api 19 | 20 | 21 | 22 | 23 | 24 | com.fizzed 25 | crux-util 26 | test 27 | 28 | 29 | 30 | com.google.guava 31 | guava 32 | 29.0-jre 33 | test 34 | 35 | 36 | 37 | org.mockito 38 | mockito-core 39 | test 40 | 41 | 42 | 43 | org.hamcrest 44 | java-hamcrest 45 | test 46 | 47 | 48 | 49 | org.junit.jupiter 50 | junit-jupiter 51 | test 52 | 53 | 54 | 55 | ch.qos.logback 56 | logback-classic 57 | test 58 | 59 | 60 | 61 | commons-io 62 | commons-io 63 | 2.7 64 | test 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /bigmap-core/src/main/java/com/fizzed/bigmap/BigMapDataException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap; 17 | 18 | public class BigMapDataException extends RuntimeException { 19 | 20 | public BigMapDataException(String msg) { 21 | super(msg); 22 | } 23 | 24 | public BigMapDataException(Throwable cause) { 25 | super(cause); 26 | } 27 | 28 | public BigMapDataException(String msg, Throwable cause) { 29 | super(msg, cause); 30 | } 31 | 32 | } -------------------------------------------------------------------------------- /bigmap-core/src/main/java/com/fizzed/bigmap/BigMapNonScalableException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap; 17 | 18 | public class BigMapNonScalableException extends RuntimeException { 19 | 20 | public BigMapNonScalableException(String msg) { 21 | super(msg); 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /bigmap-core/src/main/java/com/fizzed/bigmap/BigObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap; 17 | 18 | import java.io.Closeable; 19 | import java.nio.file.Path; 20 | import java.util.*; 21 | 22 | public interface BigObject extends Closeable { 23 | 24 | UUID getId(); 25 | 26 | Path getPath(); 27 | 28 | void setListener(BigObjectListener listener); 29 | 30 | BigObjectListener getListener(); 31 | 32 | void open(); 33 | 34 | BigObjectCloser getCloser(); 35 | 36 | default void checkIfClosed() { 37 | if (this.isClosed()) { 38 | throw new IllegalStateException("Underlying database is closed. Unable to perform any operations."); 39 | } 40 | } 41 | 42 | boolean isClosed(); 43 | 44 | boolean isPersistent(); 45 | 46 | } -------------------------------------------------------------------------------- /bigmap-core/src/main/java/com/fizzed/bigmap/BigObjectCloser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap; 17 | 18 | import java.io.Closeable; 19 | import java.nio.file.Path; 20 | import java.util.UUID; 21 | 22 | public interface BigObjectCloser extends Closeable { 23 | 24 | UUID getId(); 25 | 26 | boolean isPersistent(); 27 | 28 | Path getPath(); 29 | 30 | boolean isClosed(); 31 | 32 | } -------------------------------------------------------------------------------- /bigmap-core/src/main/java/com/fizzed/bigmap/BigObjectListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap; 17 | 18 | import java.io.Closeable; 19 | import java.nio.file.Path; 20 | import java.util.UUID; 21 | 22 | public interface BigObjectListener { 23 | 24 | void onOpened(BigObject bigObject); 25 | 26 | void onClosed(BigObject bigObject); 27 | 28 | } -------------------------------------------------------------------------------- /bigmap-core/src/main/java/com/fizzed/bigmap/BigSet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap; 17 | 18 | import java.io.Closeable; 19 | import java.nio.file.Path; 20 | import java.util.Collection; 21 | import java.util.Comparator; 22 | import java.util.Set; 23 | 24 | public interface BigSet extends Set, BigObject { 25 | 26 | ByteCodec getValueCodec(); 27 | 28 | Comparator getValueComparator(); 29 | 30 | /** 31 | * IF YOU DO NOT NEED TO KNOW IF IT WAS REMOVED, PLEASE USE {@link #delete(Object)} 32 | * 33 | * With most implementations of a bigset, its two operations to remove a value AND return back if it existed. In 34 | * most cases, you ignore the returned value and it just costs more time/effort than is needed. 35 | * 36 | * Otherwise, this method works identical to a standard Map implementation. 37 | */ 38 | @Override 39 | boolean remove(Object value); 40 | 41 | /** 42 | * Typically, this is more efficient than a {@link #remove(Object)} since the value is deleted and no check is 43 | * performed if it exists first. 44 | * @param value 45 | */ 46 | void delete(V value); 47 | 48 | @Override 49 | default boolean containsAll(Collection c) { 50 | if (c != null) { 51 | for (Object v : c) { 52 | if (!this.contains(v)) { 53 | return false; 54 | } 55 | } 56 | } 57 | return true; 58 | } 59 | 60 | @Override 61 | default boolean addAll(Collection c) { 62 | if (c != null) { 63 | for (V v : c) { 64 | this.add(v); 65 | } 66 | } 67 | return true; 68 | } 69 | 70 | @Override 71 | default boolean retainAll(Collection c) { 72 | throw new BigMapNonScalableException("Not scalable to bulk retain values"); 73 | } 74 | 75 | @Override 76 | default boolean removeAll(Collection c) { 77 | if (c != null) { 78 | for (Object v : c) { 79 | this.remove(v); 80 | } 81 | } 82 | return true; 83 | } 84 | 85 | } -------------------------------------------------------------------------------- /bigmap-core/src/main/java/com/fizzed/bigmap/BigSortedMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap; 17 | 18 | import java.util.*; 19 | 20 | public interface BigSortedMap extends BigMap, SortedMap { 21 | 22 | @Override 23 | default Comparator comparator() { 24 | return this.getKeyComparator(); 25 | } 26 | 27 | @Override 28 | default Set keySet() { 29 | return BigMap.super.keySet(); 30 | } 31 | 32 | @Override 33 | default Set> entrySet() { 34 | return BigMap.super.entrySet(); 35 | } 36 | 37 | @Override 38 | default Collection values() { 39 | return BigMap.super.values(); 40 | } 41 | 42 | @Override 43 | default SortedMap subMap(K fromKey, K toKey) { 44 | throw new UnsupportedOperationException(); 45 | } 46 | 47 | @Override 48 | default SortedMap headMap(K toKey) { 49 | throw new UnsupportedOperationException(); 50 | } 51 | 52 | @Override 53 | default SortedMap tailMap(K fromKey) { 54 | throw new UnsupportedOperationException(); 55 | } 56 | 57 | @Override 58 | default K firstKey() { 59 | return this.keySet().iterator().next(); 60 | } 61 | 62 | @Override 63 | default K lastKey() { 64 | throw new UnsupportedOperationException(); 65 | } 66 | 67 | } -------------------------------------------------------------------------------- /bigmap-core/src/main/java/com/fizzed/bigmap/BigSortedSet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap; 17 | 18 | import java.util.*; 19 | 20 | public interface BigSortedSet extends BigSet, SortedSet { 21 | 22 | @Override 23 | default Comparator comparator() { 24 | return this.getValueComparator(); 25 | } 26 | 27 | @Override 28 | default SortedSet subSet(V fromElement, V toElement) { 29 | throw new UnsupportedOperationException(); 30 | } 31 | 32 | @Override 33 | default SortedSet headSet(V toElement) { 34 | throw new UnsupportedOperationException(); 35 | } 36 | 37 | @Override 38 | default SortedSet tailSet(V fromElement) { 39 | throw new UnsupportedOperationException(); 40 | } 41 | 42 | @Override 43 | default V first() { 44 | return this.iterator().next(); 45 | } 46 | 47 | @Override 48 | default V last() { 49 | throw new UnsupportedOperationException(); 50 | } 51 | 52 | } -------------------------------------------------------------------------------- /bigmap-core/src/main/java/com/fizzed/bigmap/ByteCodec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap; 17 | 18 | public interface ByteCodec { 19 | 20 | byte[] serialize(V value); 21 | 22 | V deserialize(byte[] bytes); 23 | 24 | } -------------------------------------------------------------------------------- /bigmap-core/src/main/java/com/fizzed/bigmap/Bytes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap; 17 | 18 | public class Bytes { 19 | 20 | static public boolean startsWith( 21 | byte[] bytes, 22 | byte[] prefix) { 23 | 24 | return startsWith(bytes, prefix, null); 25 | } 26 | 27 | /** 28 | * Verifies if the bytes start with the provided prefix. Optionally, a 29 | * wildcard byte can be provided, where if the prefix contains that byte 30 | * that position will be considered a match. 31 | * @param bytes 32 | * @param prefix 33 | * @param wildcardMarker 34 | * @return 35 | */ 36 | static public boolean startsWith( 37 | byte[] bytes, 38 | byte[] prefix, 39 | Byte wildcardMarker) { 40 | 41 | if (bytes == null && prefix == null) { 42 | return true; 43 | } 44 | if (bytes == null || prefix == null) { 45 | return false; 46 | } 47 | if (prefix.length > bytes.length) { 48 | return false; 49 | } 50 | for (int i = 0; i < prefix.length; i++) { 51 | if (bytes[i] != prefix[i] 52 | && (wildcardMarker == null || prefix[i] != wildcardMarker)) { 53 | return false; 54 | } 55 | } 56 | return true; 57 | } 58 | 59 | static public boolean endsWith( 60 | byte[] bytes, 61 | byte[] suffix) { 62 | 63 | if (bytes == null && suffix == null) { 64 | return true; 65 | } 66 | if (bytes == null || suffix == null) { 67 | return false; 68 | } 69 | if (suffix.length > bytes.length) { 70 | return false; 71 | } 72 | int offset = bytes.length - suffix.length; 73 | for (int i = 0; i < suffix.length; i++) { 74 | if (bytes[offset+i] != suffix[i]) { 75 | return false; 76 | } 77 | } 78 | return true; 79 | } 80 | 81 | static public boolean endsWith( 82 | byte[] bytes, 83 | byte[] suffix, 84 | Byte wildcardMarker) { 85 | 86 | if (bytes == null && suffix == null) { 87 | return true; 88 | } 89 | if (bytes == null || suffix == null) { 90 | return false; 91 | } 92 | if (suffix.length > bytes.length) { 93 | return false; 94 | } 95 | int offset = bytes.length - suffix.length; 96 | for (int i = 0; i < suffix.length; i++) { 97 | if (bytes[offset+i] != suffix[i] 98 | && (wildcardMarker == null || suffix[i] != wildcardMarker)) { 99 | return false; 100 | } 101 | } 102 | return true; 103 | } 104 | 105 | } -------------------------------------------------------------------------------- /bigmap-core/src/main/java/com/fizzed/bigmap/Comparators.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap; 17 | 18 | import java.util.Comparator; 19 | 20 | public class Comparators { 21 | 22 | static public Comparator autoComparator(Class type) { 23 | if (Comparable.class.isAssignableFrom(type)) { 24 | return (T o1, T o2) -> { 25 | Comparable c1 = (Comparable)o1; 26 | Comparable c2 = (Comparable)o2; 27 | if (c1 == null && c2 != null) { 28 | return 1; 29 | } 30 | else if (c2 == null && c1 != null) { 31 | return -1; 32 | } 33 | else { 34 | return c1.compareTo(c2); 35 | } 36 | }; 37 | } 38 | return null; 39 | // throw new IllegalArgumentException("Only classes that implement Comparable are valid. " 40 | // + "Either supply a custom comparator or implement Comparable on your class!"); 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /bigmap-core/src/main/java/com/fizzed/bigmap/MutableValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap; 17 | 18 | public interface MutableValue extends AutoCloseable { 19 | 20 | boolean isPresent(); 21 | 22 | V get(); 23 | 24 | void set(V value); 25 | 26 | public void close() throws RuntimeException; 27 | 28 | } -------------------------------------------------------------------------------- /bigmap-core/src/main/java/com/fizzed/bigmap/SerializableByteCodec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap; 17 | 18 | import java.io.*; 19 | 20 | public class SerializableByteCodec implements ByteCodec { 21 | 22 | @Override 23 | public byte[] serialize(K value) { 24 | try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) { 25 | ObjectOutputStream out = new ObjectOutputStream(bos); 26 | out.writeObject(value); 27 | out.flush(); 28 | return bos.toByteArray(); 29 | } 30 | catch (IOException e) { 31 | throw new UncheckedIOException(e); 32 | } 33 | } 34 | 35 | @Override 36 | public K deserialize(byte[] bytes) { 37 | if (bytes == null || bytes.length == 0) { 38 | return null; 39 | } 40 | try (ByteArrayInputStream bis = new ByteArrayInputStream(bytes)) { 41 | ObjectInputStream in = new ObjectInputStream(bis); 42 | return (K)in.readObject(); 43 | } 44 | catch (IOException e) { 45 | throw new UncheckedIOException(e); 46 | } 47 | catch (ClassNotFoundException e) { 48 | throw new RuntimeException(e); 49 | } 50 | } 51 | 52 | } -------------------------------------------------------------------------------- /bigmap-core/src/main/java/com/fizzed/bigmap/impl/AbstractBigMapBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.impl; 17 | 18 | import com.fizzed.bigmap.BigObjectRegistry; 19 | import com.fizzed.bigmap.ByteCodec; 20 | 21 | import java.nio.file.Path; 22 | import java.util.Comparator; 23 | import java.util.Objects; 24 | 25 | import static com.fizzed.bigmap.ByteCodecs.resolveCodec; 26 | import static com.fizzed.bigmap.Comparators.autoComparator; 27 | 28 | abstract public class AbstractBigMapBuilder extends AbstractBigObjectBuilder { 29 | 30 | protected Class keyClass; 31 | protected Class valueClass; 32 | protected ByteCodec keyCodec; 33 | protected Comparator keyComparator; 34 | protected ByteCodec valueCodec; 35 | 36 | public T setKeyType(Class keyType) { 37 | this.setKeyType(keyType, resolveCodec(keyType)); 38 | return (T)this; 39 | } 40 | 41 | public T setKeyType(Class keyType, Comparator keyComparator) { 42 | this.setKeyType(keyType, resolveCodec(keyType), keyComparator); 43 | return (T)this; 44 | } 45 | 46 | public T setKeyType(Class keyType, ByteCodec keyCodec) { 47 | this.setKeyType(keyType, keyCodec, autoComparator(keyType)); 48 | return (T)this; 49 | } 50 | 51 | public T setKeyType(Class keyType, ByteCodec keyCodec, Comparator keyComparator) { 52 | Objects.requireNonNull(keyType, "keyType was null"); 53 | Objects.requireNonNull(keyCodec, "keyCodec was null"); 54 | // keyComparator is optional 55 | this.keyClass = keyType; 56 | this.keyCodec = keyCodec; 57 | this.keyComparator = keyComparator; 58 | return (T)this; 59 | } 60 | 61 | public T setValueType(Class valueType) { 62 | this.setValueType(valueType, resolveCodec(valueType)); 63 | return (T)this; 64 | } 65 | 66 | public T setValueType(Class valueType, ByteCodec valueCodec) { 67 | this.valueClass = valueType; 68 | this.valueCodec = valueCodec; 69 | return (T)this; 70 | } 71 | 72 | } -------------------------------------------------------------------------------- /bigmap-core/src/main/java/com/fizzed/bigmap/impl/AbstractBigObjectBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.impl; 17 | 18 | import com.fizzed.bigmap.BigObjectRegistry; 19 | 20 | import java.nio.file.Path; 21 | 22 | import static com.fizzed.bigmap.ByteCodecs.resolveCodec; 23 | 24 | abstract public class AbstractBigObjectBuilder { 25 | 26 | protected Path scratchDirectory; 27 | protected String name; 28 | protected BigObjectRegistry registry; 29 | 30 | public AbstractBigObjectBuilder() { 31 | this.scratchDirectory = BigMapHelper.resolveTempDirectory().resolve("bigobjects"); 32 | } 33 | 34 | public T autoCloseObjects() { 35 | this.autoCloseObjects(BigObjectRegistry.getDefault()); 36 | return (T)this; 37 | } 38 | 39 | public T autoCloseObjects(BigObjectRegistry registry) { 40 | this.registry = registry; 41 | return (T)this; 42 | } 43 | 44 | public T setScratchDirectory(Path scratchDirectory) { 45 | this.scratchDirectory = scratchDirectory; 46 | return (T)this; 47 | } 48 | 49 | public T setName(String name) { 50 | this.name = name; 51 | return (T)this; 52 | } 53 | 54 | } -------------------------------------------------------------------------------- /bigmap-core/src/main/java/com/fizzed/bigmap/impl/AbstractBigObjectCloser.java: -------------------------------------------------------------------------------- 1 | package com.fizzed.bigmap.impl; 2 | 3 | import com.fizzed.bigmap.BigObjectCloser; 4 | 5 | import java.io.IOException; 6 | import java.nio.file.Path; 7 | import java.util.UUID; 8 | 9 | abstract public class AbstractBigObjectCloser implements BigObjectCloser { 10 | 11 | private final UUID id; 12 | private final boolean persistent; 13 | private final Path directory; 14 | private boolean closed; 15 | 16 | public AbstractBigObjectCloser(UUID id, boolean persistent, Path directory) { 17 | this.id = id; 18 | this.persistent = persistent; 19 | this.directory = directory; 20 | } 21 | 22 | @Override 23 | public UUID getId() { 24 | return this.id; 25 | } 26 | 27 | @Override 28 | public boolean isPersistent() { 29 | return persistent; 30 | } 31 | 32 | @Override 33 | public Path getPath() { 34 | return directory; 35 | } 36 | 37 | @Override 38 | public boolean isClosed() { 39 | return this.closed; 40 | } 41 | 42 | @Override 43 | synchronized public void close() throws IOException { 44 | // do nothing on multiple closes 45 | if (this.closed) { 46 | return; 47 | } 48 | 49 | this.doClose(); 50 | 51 | if (!this.persistent) { 52 | // remove the scratch directory 53 | BigMapHelper.recursivelyDelete(this.directory); 54 | } 55 | 56 | this.closed = true; 57 | } 58 | 59 | abstract public void doClose() throws IOException; 60 | 61 | } -------------------------------------------------------------------------------- /bigmap-core/src/main/java/com/fizzed/bigmap/impl/AbstractBigSetBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.impl; 17 | 18 | import com.fizzed.bigmap.ByteCodec; 19 | 20 | import java.util.Comparator; 21 | import java.util.Objects; 22 | 23 | import static com.fizzed.bigmap.ByteCodecs.resolveCodec; 24 | import static com.fizzed.bigmap.Comparators.autoComparator; 25 | 26 | abstract public class AbstractBigSetBuilder extends AbstractBigObjectBuilder { 27 | 28 | protected Class valueClass; 29 | protected ByteCodec valueCodec; 30 | protected Comparator valueComparator; 31 | 32 | public T setValueType(Class valueType) { 33 | this.setValueType(valueType, resolveCodec(valueType)); 34 | return (T)this; 35 | } 36 | 37 | public T setValueType(Class valueType, Comparator valueComparator) { 38 | this.setValueType(valueType, resolveCodec(valueType), valueComparator); 39 | return (T)this; 40 | } 41 | 42 | public T setValueType(Class valueType, ByteCodec valueCodec) { 43 | this.setValueType(valueType, valueCodec, autoComparator(valueType)); 44 | return (T)this; 45 | } 46 | 47 | public T setValueType(Class valueType, ByteCodec valueCodec, Comparator valueComparator) { 48 | Objects.requireNonNull(valueType, "valueType was null"); 49 | Objects.requireNonNull(valueCodec, "valueCodec was null"); 50 | // valueComparator is optional 51 | this.valueClass = valueType; 52 | this.valueCodec = valueCodec; 53 | this.valueComparator = valueComparator; 54 | return (T)this; 55 | } 56 | 57 | } -------------------------------------------------------------------------------- /bigmap-core/src/main/java/com/fizzed/bigmap/impl/BigLinkedMapCloser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.impl; 17 | 18 | import com.fizzed.bigmap.BigMap; 19 | 20 | import java.io.IOException; 21 | import java.nio.file.Path; 22 | import java.util.UUID; 23 | 24 | public class BigLinkedMapCloser extends AbstractBigObjectCloser { 25 | 26 | private final BigMap dataMap; 27 | private final BigMap insertOrderToKeyMap; 28 | private final BigMap keyToInsertOrderMap; 29 | 30 | public BigLinkedMapCloser( 31 | UUID id, 32 | boolean persistent, 33 | Path directory, 34 | BigMap dataMap, 35 | BigMap insertOrderToKeyMap, 36 | BigMap keyToInsertOrderMap) { 37 | 38 | super(id, persistent, directory); 39 | this.dataMap = dataMap; 40 | this.insertOrderToKeyMap = insertOrderToKeyMap; 41 | this.keyToInsertOrderMap = keyToInsertOrderMap; 42 | } 43 | 44 | @Override 45 | public void doClose() throws IOException { 46 | this.dataMap.close(); 47 | this.insertOrderToKeyMap.close(); 48 | this.keyToInsertOrderMap.close(); 49 | } 50 | 51 | } -------------------------------------------------------------------------------- /bigmap-core/src/main/java/com/fizzed/bigmap/impl/BigMapEntrySet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.impl; 17 | 18 | import com.fizzed.bigmap.BigMap; 19 | 20 | import javax.print.attribute.UnmodifiableSetException; 21 | import java.util.Collection; 22 | import java.util.Iterator; 23 | import java.util.Map.Entry; 24 | import java.util.Set; 25 | 26 | public class BigMapEntrySet implements Set> { 27 | 28 | private final BigMap map; 29 | 30 | public BigMapEntrySet(BigMap map) { 31 | this.map = map; 32 | } 33 | 34 | @Override 35 | public int size() { 36 | return this.map.size(); 37 | } 38 | 39 | @Override 40 | public boolean isEmpty() { 41 | return this.map.isEmpty(); 42 | } 43 | 44 | @Override 45 | public boolean contains(Object o) { 46 | throw new UnsupportedOperationException(); 47 | } 48 | 49 | @Override 50 | public void clear() { 51 | this.map.clear(); 52 | } 53 | 54 | public Iterator> iterator() { 55 | final Iterator> iterator = this.map.forwardIterator(); 56 | 57 | return new Iterator>() { 58 | @Override 59 | public boolean hasNext() { 60 | return iterator.hasNext(); 61 | } 62 | 63 | @Override 64 | public Entry next() { 65 | return iterator.next(); 66 | } 67 | }; 68 | } 69 | 70 | @Override 71 | public Object[] toArray() { 72 | throw new UnsupportedOperationException(); 73 | } 74 | 75 | @Override 76 | public T[] toArray(T[] a) { 77 | throw new UnsupportedOperationException(); 78 | } 79 | 80 | @Override 81 | public boolean add(Entry e) { 82 | throw new UnmodifiableSetException(); 83 | } 84 | 85 | @Override 86 | public boolean remove(Object o) { 87 | throw new UnmodifiableSetException(); 88 | } 89 | 90 | @Override 91 | public boolean containsAll(Collection c) { 92 | throw new UnsupportedOperationException(); 93 | } 94 | 95 | @Override 96 | public boolean addAll(Collection> c) { 97 | throw new UnmodifiableSetException(); 98 | } 99 | 100 | @Override 101 | public boolean retainAll(Collection c) { 102 | throw new UnmodifiableSetException(); 103 | } 104 | 105 | @Override 106 | public boolean removeAll(Collection c) { 107 | throw new UnmodifiableSetException(); 108 | } 109 | 110 | } -------------------------------------------------------------------------------- /bigmap-core/src/main/java/com/fizzed/bigmap/impl/BigMapKeySet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.impl; 17 | 18 | import com.fizzed.bigmap.BigMap; 19 | 20 | import javax.print.attribute.UnmodifiableSetException; 21 | import java.util.Collection; 22 | import java.util.Iterator; 23 | import java.util.Set; 24 | import java.util.Map.Entry; 25 | 26 | public class BigMapKeySet implements Set { 27 | 28 | private final BigMap map; 29 | 30 | public BigMapKeySet(BigMap map) { 31 | this.map = map; 32 | } 33 | 34 | @Override 35 | public int size() { 36 | return this.map.size(); 37 | } 38 | 39 | @Override 40 | public boolean isEmpty() { 41 | return this.map.isEmpty(); 42 | } 43 | 44 | @Override 45 | public boolean remove(Object key) { 46 | return this.map.remove(key) != null; 47 | } 48 | 49 | @Override 50 | public boolean contains(Object key) { 51 | return this.map.containsKey(key); 52 | } 53 | 54 | @Override 55 | public void clear() { 56 | this.map.clear(); 57 | } 58 | 59 | public Iterator iterator() { 60 | final Iterator> iterator = this.map.forwardIterator(); 61 | 62 | return new Iterator() { 63 | @Override 64 | public boolean hasNext() { 65 | return iterator.hasNext(); 66 | } 67 | 68 | @Override 69 | public K next() { 70 | final Entry entry = iterator.next(); 71 | 72 | return entry.getKey(); 73 | } 74 | }; 75 | } 76 | 77 | @Override 78 | public Object[] toArray() { 79 | throw new UnsupportedOperationException(); 80 | } 81 | 82 | @Override 83 | public T[] toArray(T[] a) { 84 | throw new UnsupportedOperationException(); 85 | } 86 | 87 | @Override 88 | public boolean add(K e) { 89 | throw new UnmodifiableSetException(); 90 | } 91 | 92 | @Override 93 | public boolean containsAll(Collection c) { 94 | throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. 95 | } 96 | 97 | @Override 98 | public boolean addAll(Collection c) { 99 | throw new UnmodifiableSetException(); 100 | } 101 | 102 | @Override 103 | public boolean retainAll(Collection c) { 104 | throw new UnmodifiableSetException(); 105 | } 106 | 107 | @Override 108 | public boolean removeAll(Collection c) { 109 | throw new UnmodifiableSetException(); 110 | } 111 | 112 | } -------------------------------------------------------------------------------- /bigmap-core/src/main/java/com/fizzed/bigmap/impl/BigMapValueCollection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.impl; 17 | 18 | import com.fizzed.bigmap.BigMap; 19 | import com.fizzed.bigmap.BigMapNonScalableException; 20 | 21 | import java.util.Collection; 22 | import java.util.Iterator; 23 | import java.util.Map.Entry; 24 | 25 | public class BigMapValueCollection implements Collection { 26 | 27 | private final BigMap map; 28 | 29 | public BigMapValueCollection(BigMap map) { 30 | this.map = map; 31 | } 32 | 33 | @Override 34 | public int size() { 35 | return this.map.size(); 36 | } 37 | 38 | @Override 39 | public boolean isEmpty() { 40 | return this.map.isEmpty(); 41 | } 42 | 43 | @Override 44 | public boolean contains(Object o) { 45 | throw new BigMapNonScalableException("Checking if a value exists is a bad performance decision"); 46 | } 47 | 48 | @Override 49 | public void clear() { 50 | this.map.clear(); 51 | } 52 | 53 | public Iterator iterator() { 54 | final Iterator> iterator = this.map.forwardIterator(); 55 | 56 | return new Iterator() { 57 | @Override 58 | public boolean hasNext() { 59 | return iterator.hasNext(); 60 | } 61 | 62 | @Override 63 | public V next() { 64 | final Entry entry = iterator.next(); 65 | 66 | return entry.getValue(); 67 | } 68 | }; 69 | } 70 | 71 | @Override 72 | public Object[] toArray() { 73 | throw new UnsupportedOperationException(); 74 | } 75 | 76 | @Override 77 | public T[] toArray(T[] a) { 78 | throw new UnsupportedOperationException(); 79 | } 80 | 81 | @Override 82 | public boolean add(V e) { 83 | throw new UnsupportedOperationException(); 84 | } 85 | 86 | @Override 87 | public boolean remove(Object o) { 88 | throw new UnsupportedOperationException(); 89 | } 90 | 91 | @Override 92 | public boolean containsAll(Collection c) { 93 | throw new BigMapNonScalableException("Checking if a value exists is a bad performance decision"); 94 | } 95 | 96 | @Override 97 | public boolean addAll(Collection c) { 98 | throw new UnsupportedOperationException(); 99 | } 100 | 101 | @Override 102 | public boolean removeAll(Collection c) { 103 | throw new UnsupportedOperationException(); 104 | } 105 | 106 | @Override 107 | public boolean retainAll(Collection c) { 108 | throw new UnsupportedOperationException(); 109 | } 110 | 111 | } -------------------------------------------------------------------------------- /bigmap-core/src/main/java/com/fizzed/bigmap/impl/BigObjectWeakReference.java: -------------------------------------------------------------------------------- 1 | package com.fizzed.bigmap.impl; 2 | 3 | import com.fizzed.bigmap.BigObject; 4 | 5 | import java.lang.ref.ReferenceQueue; 6 | import java.lang.ref.WeakReference; 7 | import java.nio.file.Path; 8 | import java.util.UUID; 9 | import java.util.concurrent.ConcurrentHashMap; 10 | 11 | public class BigObjectWeakReference extends WeakReference { 12 | 13 | private final UUID id; 14 | 15 | public BigObjectWeakReference(BigObject bigObject, ReferenceQueue referenceQueue) { 16 | super (bigObject, referenceQueue); 17 | this.id = bigObject.getId(); 18 | } 19 | 20 | public UUID getId() { 21 | return id; 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /bigmap-core/src/main/java/com/fizzed/bigmap/impl/KeyValueBytes.java: -------------------------------------------------------------------------------- 1 | package com.fizzed.bigmap.impl; 2 | 3 | public class KeyValueBytes { 4 | 5 | private final byte[] key; 6 | private final byte[] value; 7 | 8 | public KeyValueBytes(byte[] key, byte[] value) { 9 | this.key = key; 10 | this.value = value; 11 | } 12 | 13 | public byte[] getKey() { 14 | return key; 15 | } 16 | 17 | public byte[] getValue() { 18 | return value; 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /bigmap-core/src/main/java/com/fizzed/bigmap/impl/MapMutableValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.impl; 17 | 18 | import com.fizzed.bigmap.MutableValue; 19 | 20 | import java.io.IOException; 21 | import java.util.Map; 22 | 23 | public class MapMutableValue implements MutableValue { 24 | 25 | private final Map map; 26 | private final K key; 27 | private V value; 28 | private final boolean wasInitiallyNull; 29 | private boolean closed; 30 | 31 | public MapMutableValue(Map map, K key, V value) { 32 | this.map = map; 33 | this.key = key; 34 | this.value = value; 35 | this.wasInitiallyNull = value == null; 36 | } 37 | 38 | @Override 39 | protected void finalize() { 40 | if (!this.closed) { 41 | System.err.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); 42 | System.err.println("MutableValue was not closed! Please check your code for improper usage!"); 43 | System.err.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); 44 | } 45 | } 46 | 47 | @Override 48 | public boolean isPresent() { 49 | return this.value != null; 50 | } 51 | 52 | @Override 53 | public V get() { 54 | return this.value; 55 | } 56 | 57 | @Override 58 | public void set(V value) { 59 | this.value = value; 60 | } 61 | 62 | @Override 63 | public void close() throws RuntimeException { 64 | this.closed = true; 65 | 66 | // now, if the value is/was null 67 | if (this.wasInitiallyNull && value == null) { 68 | // there's nothing to actually do 69 | } else if (value == null) { 70 | // this is essentially a delete of the key, since null values cannot be placed into BigMaps 71 | this.map.remove(this.key); 72 | } else { 73 | // otherwise, put the value back in 74 | this.map.put(this.key, this.value); 75 | } 76 | } 77 | 78 | } -------------------------------------------------------------------------------- /bigmap-core/src/main/java/com/fizzed/bigmap/impl/None.java: -------------------------------------------------------------------------------- 1 | package com.fizzed.bigmap.impl; 2 | 3 | public class None { 4 | 5 | static public final None NONE = new None(); 6 | 7 | private None() {} 8 | 9 | } -------------------------------------------------------------------------------- /bigmap-core/src/test/java/com/fizzed/bigmap/BytesTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap; 17 | 18 | import com.fizzed.crux.util.Base16; 19 | import org.junit.jupiter.api.Test; 20 | 21 | import static org.hamcrest.MatcherAssert.assertThat; 22 | import static org.hamcrest.Matchers.is; 23 | 24 | public class BytesTest { 25 | 26 | @Test 27 | public void startsWith() { 28 | byte[] a = Base16.decode("01"); 29 | byte[] b = Base16.decode("0102030405060708"); 30 | 31 | assertThat(Bytes.startsWith(null, null), is(true)); 32 | assertThat(Bytes.startsWith(a, null), is(false)); 33 | assertThat(Bytes.startsWith(a, Base16.decode("00")), is(false)); 34 | assertThat(Bytes.startsWith(a, Base16.decode("01")), is(true)); 35 | assertThat(Bytes.startsWith(a, Base16.decode("0102")), is(false)); 36 | assertThat(Bytes.startsWith(b, Base16.decode("0102")), is(true)); 37 | assertThat(Bytes.startsWith(Base16.decode("0FF0FF"), Base16.decode("0FF0FF")), is(true)); 38 | } 39 | 40 | @Test 41 | public void startsWithWildcard() { 42 | byte[] a = Base16.decode("01"); 43 | byte[] b = Base16.decode("0102030405060708"); 44 | 45 | assertThat(Bytes.startsWith(a, Base16.decode("00"), (byte)1), is(false)); 46 | assertThat(Bytes.startsWith(a, Base16.decode("01"), (byte)1), is(true)); 47 | assertThat(Bytes.startsWith(a, Base16.decode("01"), null), is(true)); 48 | assertThat(Bytes.startsWith(a, Base16.decode("0102"), (byte)0), is(false)); 49 | assertThat(Bytes.startsWith(b, Base16.decode("010003"), (byte)1), is(false)); 50 | assertThat(Bytes.startsWith(b, Base16.decode("010003"), (byte)0), is(true)); 51 | assertThat(Bytes.startsWith(b, Base16.decode("010203"), (byte)0), is(true)); 52 | } 53 | 54 | @Test 55 | public void endsWith() { 56 | byte[] a = Base16.decode("01"); 57 | byte[] b = Base16.decode("0102030405060708"); 58 | 59 | assertThat(Bytes.endsWith(null, null), is(true)); 60 | assertThat(Bytes.endsWith(a, null), is(false)); 61 | assertThat(Bytes.endsWith(a, Base16.decode("00")), is(false)); 62 | assertThat(Bytes.endsWith(a, Base16.decode("01")), is(true)); 63 | assertThat(Bytes.endsWith(a, Base16.decode("0001")), is(false)); 64 | assertThat(Bytes.endsWith(b, Base16.decode("0708")), is(true)); 65 | assertThat(Bytes.endsWith(Base16.decode("0FF0FF"), Base16.decode("0FF0FF")), is(true)); 66 | } 67 | 68 | @Test 69 | public void endsWithWildcard() { 70 | byte[] a = Base16.decode("01"); 71 | byte[] b = Base16.decode("0102030405060708"); 72 | 73 | assertThat(Bytes.endsWith(null, null), is(true)); 74 | assertThat(Bytes.endsWith(a, null), is(false)); 75 | assertThat(Bytes.endsWith(a, Base16.decode("00")), is(false)); 76 | assertThat(Bytes.endsWith(a, Base16.decode("01")), is(true)); 77 | assertThat(Bytes.endsWith(a, Base16.decode("0001")), is(false)); 78 | assertThat(Bytes.endsWith(b, Base16.decode("0707"), (byte)0), is(false)); 79 | assertThat(Bytes.endsWith(b, Base16.decode("0707"), (byte)7), is(true)); 80 | assertThat(Bytes.endsWith(b, Base16.decode("0708"), (byte)2), is(true)); 81 | assertThat(Bytes.endsWith(Base16.decode("0FF0FF"), Base16.decode("0FFFFF"), (byte)0xFF), is(true)); 82 | } 83 | 84 | } -------------------------------------------------------------------------------- /bigmap-core/src/test/java/com/fizzed/bigmap/ComparatorsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap; 17 | 18 | import org.junit.jupiter.api.Test; 19 | 20 | import static org.hamcrest.MatcherAssert.assertThat; 21 | import static org.hamcrest.Matchers.is; 22 | import static org.hamcrest.Matchers.not; 23 | import static org.hamcrest.Matchers.nullValue; 24 | 25 | public class ComparatorsTest { 26 | 27 | @Test 28 | public void autoComparator() { 29 | 30 | assertThat(Comparators.autoComparator(Long.class), is(not(nullValue()))); 31 | 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /bigmap-demo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | bigmap-demo 5 | bigmap-demo 6 | jar 7 | 8 | 9 | com.fizzed 10 | bigmap 11 | 1.1.1-SNAPSHOT 12 | 13 | 14 | 15 | true 16 | 17 | 18 | 19 | 20 | 21 | com.fizzed 22 | bigmap-core 23 | 24 | 25 | 26 | com.fizzed 27 | bigmap-kryo 28 | 29 | 30 | 31 | com.fizzed 32 | bigmap-tokyocabinet 33 | 34 | 35 | 36 | com.fizzed 37 | bigmap-leveldb 38 | 39 | 40 | 41 | com.fizzed 42 | bigmap-rocksdb 43 | 44 | 45 | 46 | 47 | 48 | org.hamcrest 49 | java-hamcrest 50 | test 51 | 52 | 53 | 54 | ch.qos.logback 55 | logback-classic 56 | test 57 | 58 | 59 | 60 | com.fizzed 61 | crux-util 62 | test 63 | 64 | 65 | 66 | com.github.oshi 67 | oshi-core 68 | 6.4.0 69 | test 70 | 71 | 72 | 73 | 74 | com.h2database 75 | h2-mvstore 76 | 2.1.214 77 | test 78 | 79 | 80 | 81 | 82 | com.fizzed 83 | tkrzw-linux-x64 84 | 0.0.2 85 | test 86 | 87 | 88 | 89 | 90 | org.mapdb 91 | mapdb 92 | 3.0.9 93 | 94 | 95 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /bigmap-demo/src/test/java/com/fizzed/bigmap/MapDemo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap; 17 | 18 | import com.fizzed.crux.util.StopWatch; 19 | 20 | import java.io.Serializable; 21 | import java.nio.file.Paths; 22 | import java.util.SortedMap; 23 | import java.util.TreeMap; 24 | 25 | public class MapDemo { 26 | 27 | static public void main(String[] args) throws Exception { 28 | final SortedMap map = new TreeMap<>(); 29 | 30 | map.firstKey(); 31 | } 32 | 33 | } -------------------------------------------------------------------------------- /bigmap-demo/src/test/java/com/fizzed/bigmap/OffheapMap.java: -------------------------------------------------------------------------------- 1 | package com.fizzed.bigmap; 2 | 3 | import java.nio.file.Path; 4 | import java.util.Collection; 5 | import java.util.Map; 6 | import java.util.Set; 7 | 8 | public class OffheapMap implements Map { 9 | 10 | private final Path directory; 11 | private final Map wrapped; 12 | 13 | public OffheapMap(Path directory, Map wrapped) { 14 | this.directory = directory; 15 | this.wrapped = wrapped; 16 | } 17 | 18 | public Path getDirectory() { 19 | return directory; 20 | } 21 | 22 | @Override 23 | public int size() { 24 | return this.wrapped.size(); 25 | } 26 | 27 | @Override 28 | public boolean isEmpty() { 29 | return this.wrapped.isEmpty(); 30 | } 31 | 32 | @Override 33 | public boolean containsKey(Object key) { 34 | return this.wrapped.containsKey(key); 35 | } 36 | 37 | @Override 38 | public boolean containsValue(Object value) { 39 | return this.wrapped.containsValue(value); 40 | } 41 | 42 | @Override 43 | public V get(Object key) { 44 | return this.wrapped.get(key); 45 | } 46 | 47 | @Override 48 | public V put(K key, V value) { 49 | return this.wrapped.put(key, value); 50 | } 51 | 52 | @Override 53 | public V remove(Object key) { 54 | return this.wrapped.remove(key); 55 | } 56 | 57 | @Override 58 | public void putAll(Map m) { 59 | this.wrapped.putAll(m); 60 | } 61 | 62 | @Override 63 | public void clear() { 64 | this.wrapped.clear(); 65 | } 66 | 67 | @Override 68 | public Set keySet() { 69 | return this.wrapped.keySet(); 70 | } 71 | 72 | @Override 73 | public Collection values() { 74 | return this.wrapped.values(); 75 | } 76 | 77 | @Override 78 | public Set> entrySet() { 79 | return this.wrapped.entrySet(); 80 | } 81 | } -------------------------------------------------------------------------------- /bigmap-demo/src/test/java/com/fizzed/bigmap/PerfManyMaps.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap; 17 | 18 | import com.fizzed.bigmap.kryo.KryoByteCodec; 19 | import com.fizzed.bigmap.leveldb.LevelBigMapBuilder; 20 | import com.fizzed.bigmap.rocksdb.RocksBigLinkedMapBuilder; 21 | import com.fizzed.bigmap.rocksdb.RocksBigMapBuilder; 22 | import com.fizzed.bigmap.tokyocabinet.TokyoBigMapBuilder; 23 | import com.fizzed.crux.util.StopWatch; 24 | import oshi.SystemInfo; 25 | import oshi.software.os.OSProcess; 26 | import oshi.software.os.OperatingSystem; 27 | 28 | import java.io.IOException; 29 | import java.io.Serializable; 30 | import java.io.UncheckedIOException; 31 | import java.nio.file.Files; 32 | import java.nio.file.Path; 33 | import java.nio.file.Paths; 34 | import java.util.*; 35 | 36 | public class PerfManyMaps extends AbstractPerf { 37 | 38 | static public void main(String[] args) throws Exception { 39 | new PerfManyMaps().run(); 40 | } 41 | 42 | public void run() throws Exception { 43 | // 44 | // config options 45 | // 46 | 47 | String type = "TokyoBigMap"; 48 | // String type = "LevelBigMap"; 49 | // String type = "RocksBigLinkedMap"; 50 | // String type = "RocksBigMap"; 51 | // String type = "MVStoreMap"; 52 | // String type = "TokyoCabinetMap"; 53 | // String type = "KyotoCabinetMap"; 54 | // String type = "TkrzwCabinetMap"; 55 | int mapCount = 20000; 56 | int entryCountPerMap = 3000; 57 | 58 | logMemory("At startup"); 59 | 60 | for (int j = 0; j < mapCount; j++) { 61 | final Map map = buildMap(type, j); 62 | 63 | if (j % 500 == 0) { 64 | logMemory("Map #" + j); 65 | } else if (j % 25 == 0) { 66 | log.info("Processed map #{}", j); 67 | } 68 | 69 | // add some entries 70 | for (int i = 0; i < entryCountPerMap; i++) { 71 | Item item = new Item(); 72 | item.a = (long) i; 73 | item.b = "This is sooooo cool dude! " + i; 74 | item.c = "Look mom no hands " + i; 75 | item.d = "Woooo baby! " + i; 76 | item.e = "Woza! " + i; 77 | item.g = "Blah blah aljlfjalfrjsd;lfjsdlfjsdlafjsdlfjsdlfjsdlfjsldafjlsdfjsdlfjsdlfjsdalfjsdlfjsdlfjdsjf" + i; 78 | item.h = i; 79 | map.put(i+"", item); 80 | } 81 | 82 | // get some entries 83 | for (int i = 0; i < entryCountPerMap; i += 200) { 84 | map.get(i+""); 85 | } 86 | 87 | // try a bunch of iterator's 88 | for (int i = 0; i < 1000; i++) { 89 | Collection values = map.values(); 90 | } 91 | 92 | // close map (does it clean up its resources) 93 | ((BigMap)map).close(); 94 | } 95 | 96 | logMemory("After " + mapCount + " maps created & closed"); 97 | } 98 | 99 | } -------------------------------------------------------------------------------- /bigmap-demo/src/test/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /bigmap-integration-tests/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | bigmap-integration-tests 5 | bigmap-integration-tests 6 | jar 7 | 8 | 9 | com.fizzed 10 | bigmap 11 | 1.1.1-SNAPSHOT 12 | 13 | 14 | 15 | true 16 | 17 | 18 | 19 | 20 | 21 | com.fizzed 22 | bigmap-core 23 | 24 | 25 | 26 | com.fizzed 27 | bigmap-kryo 28 | 29 | 30 | 31 | com.fizzed 32 | bigmap-leveldb 33 | 34 | 35 | 36 | com.fizzed 37 | bigmap-rocksdb 38 | 39 | 40 | 41 | com.fizzed 42 | bigmap-tokyocabinet 43 | 44 | 45 | 46 | 47 | com.fizzed 48 | tokyocabinet-all-natives 49 | provided 50 | 51 | 52 | 53 | com.fizzed 54 | bigmap-tkrzw 55 | 56 | 57 | 58 | 59 | com.fizzed 60 | tkrzw-all-natives 61 | provided 62 | 63 | 64 | 65 | 66 | 67 | org.hamcrest 68 | java-hamcrest 69 | test 70 | 71 | 72 | 73 | org.junit.jupiter 74 | junit-jupiter 75 | test 76 | 77 | 78 | 79 | ch.qos.logback 80 | logback-classic 81 | test 82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /bigmap-integration-tests/src/test/java/com/fizzed/bigmap/AbstractBigLinkedSetTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap; 17 | 18 | import org.junit.jupiter.api.Disabled; 19 | import org.junit.jupiter.api.Test; 20 | import java.io.IOException; 21 | import java.util.*; 22 | import static com.fizzed.bigmap.impl.BigMapHelper.*; 23 | import static org.hamcrest.CoreMatchers.hasItems; 24 | import static org.hamcrest.MatcherAssert.assertThat; 25 | import static org.hamcrest.Matchers.*; 26 | 27 | abstract public class AbstractBigLinkedSetTest extends AbstractBigSetTest { 28 | 29 | @Test @Disabled 30 | public void byteSizeTracking() { 31 | // we want to just ignore this 32 | } 33 | 34 | @Test 35 | public void addOrdered() { 36 | final Set set = this.newSet(Long.class); 37 | 38 | set.add(5L); 39 | set.add(1L); 40 | set.add(3L); 41 | set.add(2L); 42 | 43 | assertThat(toValueList(set), hasItems(5L, 1L, 3L, 2L)); 44 | 45 | // adding a value does not change its insert ordering 46 | set.add(5L); 47 | 48 | assertThat(toValueList(set), hasItems(5L, 1L, 3L, 2L)); 49 | } 50 | 51 | @Test 52 | public void removeOrdered() throws IOException { 53 | final Set set = this.newSet(String.class); 54 | 55 | set.add("4"); 56 | set.add("1"); 57 | set.add("3"); 58 | set.add("2"); 59 | 60 | assertThat(set, hasSize(4)); 61 | assertThat(toValueList(set), hasItems("4", "1", "3", "2")); 62 | 63 | boolean removed; 64 | 65 | removed = set.remove("1"); 66 | 67 | assertThat(removed, is(true)); 68 | assertThat(toValueList(set), hasItems("4", "3", "2")); 69 | 70 | // try to remove it again 71 | removed = set.remove("1"); 72 | 73 | assertThat(removed, is(false)); 74 | assertThat(toValueList(set), hasItems("4", "3", "2")); 75 | 76 | removed = set.remove("4"); 77 | 78 | assertThat(removed, is(true)); 79 | assertThat(toValueList(set), hasItems("3", "2")); 80 | } 81 | 82 | } -------------------------------------------------------------------------------- /bigmap-integration-tests/src/test/java/com/fizzed/bigmap/JavaHashMapTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap; 17 | 18 | import org.junit.jupiter.api.Disabled; 19 | import org.junit.jupiter.api.Test; 20 | import java.util.HashMap; 21 | import java.util.Map; 22 | 23 | public class JavaHashMapTest extends AbstractBigMapTest { 24 | 25 | @Override 26 | public Map newMap(Class keyType, Class valueType) { 27 | return new HashMap<>(); 28 | } 29 | 30 | @Test @Disabled("nulls are technically allowed with a java hashmap") 31 | public void putNullKey() { 32 | super.putNullKey(); 33 | } 34 | 35 | @Test @Disabled("nulls are technically allowed with a java hashmap") 36 | public void putNullValue() { 37 | super.putNullKey(); 38 | } 39 | 40 | @Test @Disabled 41 | public void putAndGetWithComplexObject() {} 42 | 43 | } -------------------------------------------------------------------------------- /bigmap-integration-tests/src/test/java/com/fizzed/bigmap/JavaHashSetTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap; 17 | 18 | import org.junit.jupiter.api.Disabled; 19 | import org.junit.jupiter.api.Test; 20 | 21 | import java.util.HashSet; 22 | import java.util.Set; 23 | 24 | public class JavaHashSetTest extends AbstractBigSetTest { 25 | 26 | @Override 27 | public Set newSet(Class valueType) { 28 | return new HashSet<>(); 29 | } 30 | 31 | @Test 32 | @Disabled 33 | public void addAndContainsWithComplexObject() { } 34 | 35 | } -------------------------------------------------------------------------------- /bigmap-integration-tests/src/test/java/com/fizzed/bigmap/JavaLinkedHashMapTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap; 17 | 18 | import org.junit.jupiter.api.Disabled; 19 | import org.junit.jupiter.api.Test; 20 | 21 | import java.util.LinkedHashMap; 22 | import java.util.Map; 23 | 24 | public class JavaLinkedHashMapTest extends AbstractBigLinkedMapTest { 25 | 26 | @Override 27 | public Map newMap(Class keyType, Class valueType) { 28 | return new LinkedHashMap<>(); 29 | } 30 | 31 | @Test 32 | @Disabled("nulls are technically allowed with a java hashmap") 33 | public void putNullKey() { 34 | super.putNullKey(); 35 | } 36 | 37 | @Test @Disabled("nulls are technically allowed with a java hashmap") 38 | public void putNullValue() { 39 | super.putNullKey(); 40 | } 41 | 42 | @Test @Disabled 43 | public void putAndGetWithComplexObject() {} 44 | 45 | } -------------------------------------------------------------------------------- /bigmap-integration-tests/src/test/java/com/fizzed/bigmap/JavaTreeMapTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap; 17 | 18 | import org.junit.jupiter.api.Disabled; 19 | import org.junit.jupiter.api.Test; 20 | 21 | import java.util.Map; 22 | import java.util.TreeMap; 23 | 24 | public class JavaTreeMapTest extends AbstractBigMapTest { 25 | 26 | @Override 27 | public Map newMap(Class keyType, Class valueType) { 28 | return new TreeMap<>(); 29 | } 30 | 31 | @Test 32 | @Disabled("nulls are technically allowed with a java hashmap") 33 | public void putNullValue() { 34 | super.putNullKey(); 35 | } 36 | 37 | @Test @Disabled("nulls are technically NOT allowed with a java treemap") 38 | public void containsKeyWithNull() { 39 | super.containsKeyWithNull(); 40 | } 41 | 42 | @Test @Disabled 43 | public void putAndGetWithComplexObject() {} 44 | 45 | } -------------------------------------------------------------------------------- /bigmap-integration-tests/src/test/java/com/fizzed/bigmap/JavaTreeSetTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap; 17 | 18 | import org.junit.jupiter.api.Disabled; 19 | import org.junit.jupiter.api.Test; 20 | 21 | import java.util.Set; 22 | import java.util.TreeSet; 23 | 24 | public class JavaTreeSetTest extends AbstractBigSetTest { 25 | 26 | @Override 27 | public Set newSet(Class valueType) { 28 | return new TreeSet<>(); 29 | } 30 | 31 | @Test 32 | @Disabled 33 | public void addAndContainsWithComplexObject() { } 34 | 35 | } -------------------------------------------------------------------------------- /bigmap-integration-tests/src/test/java/com/fizzed/bigmap/LevelBigLinkedMapTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap; 17 | 18 | import com.fizzed.bigmap.leveldb.LevelBigLinkedMapBuilder; 19 | 20 | import java.nio.file.Paths; 21 | import java.util.Map; 22 | 23 | public class LevelBigLinkedMapTest extends AbstractBigLinkedMapTest { 24 | 25 | @Override 26 | public Map newMap(Class keyType, Class valueType) { 27 | return new LevelBigLinkedMapBuilder() 28 | .setScratchDirectory(Paths.get("target")) 29 | .setKeyType(keyType) 30 | .setValueType(valueType) 31 | .autoCloseObjects() 32 | .build(); 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /bigmap-integration-tests/src/test/java/com/fizzed/bigmap/LevelBigLinkedSetTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap; 17 | 18 | import com.fizzed.bigmap.leveldb.LevelBigLinkedSetBuilder; 19 | 20 | import java.nio.file.Paths; 21 | import java.util.Set; 22 | 23 | public class LevelBigLinkedSetTest extends AbstractBigLinkedSetTest { 24 | 25 | @Override 26 | public Set newSet(Class valueType) { 27 | return new LevelBigLinkedSetBuilder() 28 | .setScratchDirectory(Paths.get("target")) 29 | .setValueType(valueType) 30 | .autoCloseObjects() 31 | .build(); 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /bigmap-integration-tests/src/test/java/com/fizzed/bigmap/LevelBigMapTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap; 17 | 18 | import com.fizzed.bigmap.leveldb.LevelBigMapBuilder; 19 | 20 | import java.nio.file.Paths; 21 | import java.util.Map; 22 | 23 | public class LevelBigMapTest extends AbstractBigMapTest { 24 | 25 | @Override 26 | public Map newMap(Class keyType, Class valueType) { 27 | return new LevelBigMapBuilder() 28 | .setScratchDirectory(Paths.get("target")) 29 | .setKeyType(keyType) 30 | .setValueType(valueType) 31 | .autoCloseObjects() 32 | .build(); 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /bigmap-integration-tests/src/test/java/com/fizzed/bigmap/LevelBigSetTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap; 17 | 18 | import com.fizzed.bigmap.leveldb.LevelBigSetBuilder; 19 | 20 | import java.nio.file.Paths; 21 | import java.util.Set; 22 | 23 | public class LevelBigSetTest extends AbstractBigSetTest { 24 | 25 | @Override 26 | public Set newSet(Class valueType) { 27 | return new LevelBigSetBuilder() 28 | .setScratchDirectory(Paths.get("target")) 29 | .setValueType(valueType) 30 | .autoCloseObjects() 31 | .build(); 32 | } 33 | 34 | } -------------------------------------------------------------------------------- /bigmap-integration-tests/src/test/java/com/fizzed/bigmap/RocksBigLinkedMapTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap; 17 | 18 | import com.fizzed.bigmap.rocksdb.RocksBigLinkedMapBuilder; 19 | import com.fizzed.jne.HardwareArchitecture; 20 | import com.fizzed.jne.NativeTarget; 21 | import com.fizzed.jne.OperatingSystem; 22 | import org.junit.jupiter.api.condition.DisabledIf; 23 | 24 | import java.nio.file.Paths; 25 | import java.util.Map; 26 | 27 | @DisabledIf("isUnsupportedOs") 28 | public class RocksBigLinkedMapTest extends AbstractBigLinkedMapTest { 29 | 30 | static public boolean isUnsupportedOs() { 31 | final NativeTarget current = NativeTarget.detect(); 32 | return current.getOperatingSystem() == OperatingSystem.FREEBSD 33 | || current.getOperatingSystem() == OperatingSystem.OPENBSD 34 | || (current.getOperatingSystem() == OperatingSystem.WINDOWS && current.getHardwareArchitecture() == HardwareArchitecture.ARM64) 35 | || (current.getOperatingSystem() == OperatingSystem.LINUX && current.getHardwareArchitecture() == HardwareArchitecture.RISCV64); 36 | } 37 | 38 | @Override 39 | public Map newMap(Class keyType, Class valueType) { 40 | return new RocksBigLinkedMapBuilder() 41 | .setScratchDirectory(Paths.get("target")) 42 | .setKeyType(keyType) 43 | .setValueType(valueType) 44 | .autoCloseObjects() 45 | .build(); 46 | } 47 | 48 | } -------------------------------------------------------------------------------- /bigmap-integration-tests/src/test/java/com/fizzed/bigmap/RocksBigLinkedSetTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap; 17 | 18 | import com.fizzed.bigmap.rocksdb.RocksBigLinkedSetBuilder; 19 | import com.fizzed.jne.HardwareArchitecture; 20 | import com.fizzed.jne.NativeTarget; 21 | import com.fizzed.jne.OperatingSystem; 22 | import org.junit.jupiter.api.condition.DisabledIf; 23 | 24 | import java.nio.file.Paths; 25 | import java.util.Set; 26 | 27 | @DisabledIf("isUnsupportedOs") 28 | public class RocksBigLinkedSetTest extends AbstractBigLinkedSetTest { 29 | 30 | static public boolean isUnsupportedOs() { 31 | final NativeTarget current = NativeTarget.detect(); 32 | return current.getOperatingSystem() == OperatingSystem.FREEBSD 33 | || current.getOperatingSystem() == OperatingSystem.OPENBSD 34 | || (current.getOperatingSystem() == OperatingSystem.WINDOWS && current.getHardwareArchitecture() == HardwareArchitecture.ARM64) 35 | || (current.getOperatingSystem() == OperatingSystem.LINUX && current.getHardwareArchitecture() == HardwareArchitecture.RISCV64); 36 | } 37 | 38 | @Override 39 | public Set newSet(Class valueType) { 40 | return new RocksBigLinkedSetBuilder() 41 | .setScratchDirectory(Paths.get("target")) 42 | .setValueType(valueType) 43 | .autoCloseObjects() 44 | .build(); 45 | } 46 | 47 | } -------------------------------------------------------------------------------- /bigmap-integration-tests/src/test/java/com/fizzed/bigmap/RocksBigMapTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap; 17 | 18 | import com.fizzed.bigmap.rocksdb.RocksBigMapBuilder; 19 | import com.fizzed.jne.HardwareArchitecture; 20 | import com.fizzed.jne.NativeTarget; 21 | import com.fizzed.jne.OperatingSystem; 22 | import org.junit.jupiter.api.condition.DisabledIf; 23 | 24 | import java.nio.file.Paths; 25 | import java.util.Map; 26 | 27 | @DisabledIf("isUnsupportedOs") 28 | public class RocksBigMapTest extends AbstractBigMapTest { 29 | 30 | static public boolean isUnsupportedOs() { 31 | final NativeTarget current = NativeTarget.detect(); 32 | return current.getOperatingSystem() == OperatingSystem.FREEBSD 33 | || current.getOperatingSystem() == OperatingSystem.OPENBSD 34 | || (current.getOperatingSystem() == OperatingSystem.WINDOWS && current.getHardwareArchitecture() == HardwareArchitecture.ARM64) 35 | || (current.getOperatingSystem() == OperatingSystem.LINUX && current.getHardwareArchitecture() == HardwareArchitecture.RISCV64); 36 | } 37 | 38 | @Override 39 | public Map newMap(Class keyType, Class valueType) { 40 | return new RocksBigMapBuilder() 41 | .setScratchDirectory(Paths.get("target")) 42 | .setKeyType(keyType) 43 | .setValueType(valueType) 44 | .autoCloseObjects() 45 | .build(); 46 | } 47 | 48 | } -------------------------------------------------------------------------------- /bigmap-integration-tests/src/test/java/com/fizzed/bigmap/RocksBigSetTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap; 17 | 18 | import com.fizzed.bigmap.rocksdb.RocksBigSetBuilder; 19 | import com.fizzed.jne.HardwareArchitecture; 20 | import com.fizzed.jne.NativeTarget; 21 | import com.fizzed.jne.OperatingSystem; 22 | import org.junit.jupiter.api.condition.DisabledIf; 23 | 24 | import java.nio.file.Paths; 25 | import java.util.Set; 26 | 27 | @DisabledIf("isUnsupportedOs") 28 | public class RocksBigSetTest extends AbstractBigSetTest { 29 | 30 | static public boolean isUnsupportedOs() { 31 | final NativeTarget current = NativeTarget.detect(); 32 | return current.getOperatingSystem() == OperatingSystem.FREEBSD 33 | || current.getOperatingSystem() == OperatingSystem.OPENBSD 34 | || (current.getOperatingSystem() == OperatingSystem.WINDOWS && current.getHardwareArchitecture() == HardwareArchitecture.ARM64) 35 | || (current.getOperatingSystem() == OperatingSystem.LINUX && current.getHardwareArchitecture() == HardwareArchitecture.RISCV64); 36 | } 37 | 38 | @Override 39 | public Set newSet(Class valueType) { 40 | return new RocksBigSetBuilder() 41 | .setScratchDirectory(Paths.get("target")) 42 | .setValueType(valueType) 43 | .autoCloseObjects() 44 | .build(); 45 | } 46 | 47 | } -------------------------------------------------------------------------------- /bigmap-integration-tests/src/test/java/com/fizzed/bigmap/TestIdentifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap; 17 | 18 | import java.io.Serializable; 19 | 20 | public class TestIdentifier implements Serializable { 21 | 22 | private String domain; 23 | private String name; 24 | 25 | public TestIdentifier(String domain, String name) { 26 | this.domain = domain; 27 | this.name = name; 28 | } 29 | 30 | public String getDomain() { 31 | return domain; 32 | } 33 | 34 | public TestIdentifier setDomain(String domain) { 35 | this.domain = domain; 36 | return this; 37 | } 38 | 39 | public String getName() { 40 | return name; 41 | } 42 | 43 | public TestIdentifier setName(String name) { 44 | this.name = name; 45 | return this; 46 | } 47 | 48 | } -------------------------------------------------------------------------------- /bigmap-integration-tests/src/test/java/com/fizzed/bigmap/TkrzwBigLinkedMapTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap; 17 | 18 | import com.fizzed.bigmap.tkrzw.TkrzwBigLinkedMapBuilder; 19 | import org.junit.jupiter.api.condition.DisabledOnOs; 20 | import org.junit.jupiter.api.condition.OS; 21 | 22 | import java.nio.file.Paths; 23 | import java.util.Map; 24 | 25 | //@DisabledOnOs({ OS.FREEBSD, OS.OPENBSD }) 26 | public class TkrzwBigLinkedMapTest extends AbstractBigLinkedMapTest { 27 | 28 | @Override 29 | public Map newMap(Class keyType, Class valueType) { 30 | return new TkrzwBigLinkedMapBuilder() 31 | .setScratchDirectory(Paths.get("target")) 32 | .setKeyType(keyType) 33 | .setValueType(valueType) 34 | .autoCloseObjects() 35 | .build(); 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /bigmap-integration-tests/src/test/java/com/fizzed/bigmap/TkrzwBigLinkedSetTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap; 17 | 18 | import com.fizzed.bigmap.tkrzw.TkrzwBigLinkedSetBuilder; 19 | import org.junit.jupiter.api.condition.DisabledOnOs; 20 | import org.junit.jupiter.api.condition.OS; 21 | 22 | import java.nio.file.Paths; 23 | import java.util.Set; 24 | 25 | //@DisabledOnOs({ OS.FREEBSD, OS.OPENBSD }) 26 | public class TkrzwBigLinkedSetTest extends AbstractBigLinkedSetTest { 27 | 28 | @Override 29 | public Set newSet(Class valueType) { 30 | return new TkrzwBigLinkedSetBuilder() 31 | .setScratchDirectory(Paths.get("target")) 32 | .setValueType(valueType) 33 | .autoCloseObjects() 34 | .build(); 35 | } 36 | 37 | } -------------------------------------------------------------------------------- /bigmap-integration-tests/src/test/java/com/fizzed/bigmap/TkrzwBigMapTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap; 17 | 18 | import com.fizzed.bigmap.tkrzw.TkrzwBigMapBuilder; 19 | import org.junit.jupiter.api.condition.DisabledOnOs; 20 | import org.junit.jupiter.api.condition.OS; 21 | 22 | import java.nio.file.Paths; 23 | import java.util.Map; 24 | 25 | //@DisabledOnOs({ OS.FREEBSD, OS.OPENBSD }) 26 | public class TkrzwBigMapTest extends AbstractBigMapTest { 27 | 28 | @Override 29 | public Map newMap(Class keyType, Class valueType) { 30 | return new TkrzwBigMapBuilder() 31 | .setScratchDirectory(Paths.get("target")) 32 | .setKeyType(keyType) 33 | .setValueType(valueType) 34 | .autoCloseObjects() 35 | .build(); 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /bigmap-integration-tests/src/test/java/com/fizzed/bigmap/TkrzwBigSetTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap; 17 | 18 | import com.fizzed.bigmap.tkrzw.TkrzwBigSetBuilder; 19 | import org.junit.jupiter.api.condition.DisabledOnOs; 20 | import org.junit.jupiter.api.condition.OS; 21 | 22 | import java.nio.file.Paths; 23 | import java.util.Set; 24 | 25 | //@DisabledOnOs({ OS.FREEBSD, OS.OPENBSD }) 26 | public class TkrzwBigSetTest extends AbstractBigSetTest { 27 | 28 | @Override 29 | public Set newSet(Class valueType) { 30 | return new TkrzwBigSetBuilder() 31 | .setScratchDirectory(Paths.get("target")) 32 | .setValueType(valueType) 33 | .autoCloseObjects() 34 | .build(); 35 | } 36 | 37 | } -------------------------------------------------------------------------------- /bigmap-integration-tests/src/test/java/com/fizzed/bigmap/TokyoBigLinkedMapTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap; 17 | 18 | import com.fizzed.bigmap.tokyocabinet.TokyoBigLinkedMapBuilder; 19 | import org.junit.jupiter.api.condition.DisabledOnOs; 20 | import org.junit.jupiter.api.condition.OS; 21 | 22 | import java.nio.file.Paths; 23 | import java.util.Map; 24 | 25 | @DisabledOnOs({ OS.WINDOWS }) 26 | public class TokyoBigLinkedMapTest extends AbstractBigLinkedMapTest { 27 | 28 | @Override 29 | public Map newMap(Class keyType, Class valueType) { 30 | return new TokyoBigLinkedMapBuilder() 31 | .setScratchDirectory(Paths.get("target")) 32 | .setKeyType(keyType) 33 | .setValueType(valueType) 34 | .autoCloseObjects() 35 | .build(); 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /bigmap-integration-tests/src/test/java/com/fizzed/bigmap/TokyoBigLinkedSetTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap; 17 | 18 | import com.fizzed.bigmap.tokyocabinet.TokyoBigLinkedSetBuilder; 19 | import org.junit.jupiter.api.condition.DisabledOnOs; 20 | import org.junit.jupiter.api.condition.OS; 21 | 22 | import java.nio.file.Paths; 23 | import java.util.Set; 24 | 25 | @DisabledOnOs({ OS.WINDOWS }) 26 | public class TokyoBigLinkedSetTest extends AbstractBigLinkedSetTest { 27 | 28 | @Override 29 | public Set newSet(Class valueType) { 30 | return new TokyoBigLinkedSetBuilder() 31 | .setScratchDirectory(Paths.get("target")) 32 | .setValueType(valueType) 33 | .autoCloseObjects() 34 | .build(); 35 | } 36 | 37 | } -------------------------------------------------------------------------------- /bigmap-integration-tests/src/test/java/com/fizzed/bigmap/TokyoBigMapTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap; 17 | 18 | import com.fizzed.bigmap.tokyocabinet.TokyoBigMapBuilder; 19 | import org.junit.jupiter.api.condition.DisabledOnOs; 20 | import org.junit.jupiter.api.condition.OS; 21 | 22 | import java.nio.file.Paths; 23 | import java.util.Map; 24 | 25 | @DisabledOnOs({ OS.WINDOWS }) 26 | public class TokyoBigMapTest extends AbstractBigMapTest { 27 | 28 | @Override 29 | public Map newMap(Class keyType, Class valueType) { 30 | return new TokyoBigMapBuilder() 31 | .setScratchDirectory(Paths.get("target")) 32 | .setKeyType(keyType) 33 | .setValueType(valueType) 34 | .autoCloseObjects() 35 | .build(); 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /bigmap-integration-tests/src/test/java/com/fizzed/bigmap/TokyoBigSetTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap; 17 | 18 | import com.fizzed.bigmap.tokyocabinet.TokyoBigSetBuilder; 19 | import org.junit.jupiter.api.condition.DisabledOnOs; 20 | import org.junit.jupiter.api.condition.OS; 21 | 22 | import java.nio.file.Paths; 23 | import java.util.Set; 24 | 25 | @DisabledOnOs({ OS.WINDOWS }) 26 | public class TokyoBigSetTest extends AbstractBigSetTest { 27 | 28 | @Override 29 | public Set newSet(Class valueType) { 30 | return new TokyoBigSetBuilder() 31 | .setScratchDirectory(Paths.get("target")) 32 | .setValueType(valueType) 33 | .autoCloseObjects() 34 | .build(); 35 | } 36 | 37 | } -------------------------------------------------------------------------------- /bigmap-jackson/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | bigmap-jackson 5 | bigmap-jackson 6 | jar 7 | 8 | 9 | com.fizzed 10 | bigmap 11 | 1.1.1-SNAPSHOT 12 | 13 | 14 | 15 | 16 | 17 | com.fizzed 18 | bigmap-core 19 | 20 | 21 | 22 | com.fasterxml.jackson.core 23 | jackson-databind 24 | 2.9.2 25 | provided 26 | 27 | 28 | 29 | 30 | 31 | com.fizzed 32 | crux-util 33 | test 34 | 35 | 36 | 37 | org.hamcrest 38 | java-hamcrest 39 | test 40 | 41 | 42 | 43 | org.junit.jupiter 44 | junit-jupiter 45 | test 46 | 47 | 48 | 49 | ch.qos.logback 50 | logback-classic 51 | test 52 | 53 | 54 | 55 | com.fizzed 56 | crux-jackson 57 | 1.0.41 58 | test 59 | 60 | 61 | 62 | joda-time 63 | joda-time 64 | 2.10.9 65 | test 66 | 67 | 68 | 69 | org.joda 70 | joda-money 71 | 0.11 72 | test 73 | 74 | 75 | 76 | com.fasterxml.jackson.datatype 77 | jackson-datatype-joda 78 | 2.9.2 79 | test 80 | 81 | 82 | 83 | com.fasterxml.jackson.module 84 | jackson-module-parameter-names 85 | 2.9.2 86 | test 87 | 88 | 89 | 90 | com.fasterxml.jackson.datatype 91 | jackson-datatype-jdk8 92 | 2.9.2 93 | test 94 | 95 | 96 | 97 | com.fasterxml.jackson.datatype 98 | jackson-datatype-jsr310 99 | 2.9.2 100 | test 101 | 102 | 103 | 104 | 105 | 106 | -------------------------------------------------------------------------------- /bigmap-jackson/src/main/java/com/fizzed/bigmap/jackson/JacksonByteCodec.java: -------------------------------------------------------------------------------- 1 | package com.fizzed.bigmap.jackson; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import com.fizzed.bigmap.ByteCodec; 5 | 6 | import java.io.IOException; 7 | import java.io.UncheckedIOException; 8 | 9 | import static com.fizzed.bigmap.ByteCodecs.ZERO_BYTES; 10 | 11 | public class JacksonByteCodec implements ByteCodec { 12 | 13 | private final ObjectMapper objectMapper; 14 | private final Class type; 15 | 16 | public JacksonByteCodec(Class type) { 17 | this(type, new ObjectMapper()); 18 | } 19 | 20 | public JacksonByteCodec(Class type, ObjectMapper objectMapper) { 21 | this.objectMapper = objectMapper; 22 | this.type = type; 23 | } 24 | 25 | @Override 26 | public byte[] serialize(K value) { 27 | if (value == null) { 28 | return ZERO_BYTES; 29 | } 30 | try { 31 | return this.objectMapper.writeValueAsBytes(value); 32 | } catch (IOException e) { 33 | throw new UncheckedIOException(e); 34 | } 35 | } 36 | 37 | @Override 38 | public K deserialize(byte[] bytes) { 39 | if (bytes == null || bytes.length == 0) { 40 | return null; 41 | } 42 | try { 43 | return this.objectMapper.readValue(bytes, type); 44 | } catch (IOException e) { 45 | throw new UncheckedIOException(e); 46 | } 47 | } 48 | 49 | } -------------------------------------------------------------------------------- /bigmap-kryo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | bigmap-kryo 5 | bigmap-kryo 6 | jar 7 | 8 | 9 | com.fizzed 10 | bigmap 11 | 1.1.1-SNAPSHOT 12 | 13 | 14 | 15 | 16 | 17 | com.fizzed 18 | bigmap-core 19 | 20 | 21 | 22 | com.esotericsoftware 23 | kryo 24 | 5.6.2 25 | 26 | 27 | 28 | 29 | 30 | com.fizzed 31 | crux-util 32 | test 33 | 34 | 35 | 36 | org.hamcrest 37 | java-hamcrest 38 | test 39 | 40 | 41 | 42 | org.junit.jupiter 43 | junit-jupiter 44 | test 45 | 46 | 47 | 48 | ch.qos.logback 49 | logback-classic 50 | test 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /bigmap-kryo/src/main/java/com/fizzed/bigmap/kryo/KryoByteCodec.java: -------------------------------------------------------------------------------- 1 | package com.fizzed.bigmap.kryo; 2 | 3 | import com.esotericsoftware.kryo.Kryo; 4 | import com.esotericsoftware.kryo.io.Input; 5 | import com.esotericsoftware.kryo.io.Output; 6 | import com.fizzed.bigmap.ByteCodec; 7 | 8 | import static com.fizzed.bigmap.ByteCodecs.ZERO_BYTES; 9 | 10 | public class KryoByteCodec implements ByteCodec { 11 | 12 | private final Kryo kryo; 13 | private final Class type; 14 | 15 | static public Kryo buildDefaultKryo() { 16 | Kryo kryo = new Kryo(); 17 | kryo.setRegistrationRequired(false); 18 | return kryo; 19 | } 20 | 21 | public KryoByteCodec(Class type) { 22 | this(type, buildDefaultKryo()); 23 | } 24 | 25 | public KryoByteCodec(Class type, Kryo kryo) { 26 | this.kryo = kryo; 27 | this.type = type; 28 | } 29 | 30 | @Override 31 | public byte[] serialize(K value) { 32 | if (value == null) { 33 | return ZERO_BYTES; 34 | } 35 | final Output output = new Output(1024, -1); 36 | this.kryo.writeObjectOrNull(output, value, this.type); 37 | return output.toBytes(); 38 | } 39 | 40 | @Override 41 | public K deserialize(byte[] bytes) { 42 | // kryo does not allow zero byte arrays to be deserialized, so its null 43 | if (bytes == null || bytes.length == 0) { 44 | return null; 45 | } 46 | final Input input = new Input(bytes); 47 | return this.kryo.readObjectOrNull(input, this.type); 48 | } 49 | 50 | } -------------------------------------------------------------------------------- /bigmap-kryo/src/test/java/com/fizzed/bigmap/kryo/KryoByteCodecTest.java: -------------------------------------------------------------------------------- 1 | package com.fizzed.bigmap.kryo; 2 | 3 | import com.fizzed.bigmap.ByteCodecs; 4 | import com.fizzed.crux.util.Base16; 5 | import org.junit.jupiter.api.Test; 6 | 7 | import java.time.Instant; 8 | import java.util.Objects; 9 | 10 | import static org.hamcrest.CoreMatchers.is; 11 | import static org.hamcrest.CoreMatchers.nullValue; 12 | import static org.hamcrest.MatcherAssert.assertThat; 13 | 14 | public class KryoByteCodecTest { 15 | 16 | @Test 17 | public void nullsAndEmptyStrings() { 18 | final KryoByteCodec byteCodec = new KryoByteCodec<>(String.class); 19 | 20 | assertThat(byteCodec.serialize(null), is(ByteCodecs.ZERO_BYTES)); 21 | assertThat(byteCodec.serialize(""), is(new byte[] {(byte)-127})); 22 | 23 | assertThat(byteCodec.deserialize(null), is(nullValue())); 24 | assertThat(byteCodec.deserialize(ByteCodecs.ZERO_BYTES), is(nullValue())); 25 | assertThat(byteCodec.deserialize(new byte[] {(byte)-127}), is("")); 26 | } 27 | 28 | @Test 29 | public void serializableObjects() { 30 | final KryoByteCodec byteCodec = new KryoByteCodec<>(Instant.class); 31 | 32 | final Instant i1 = Instant.parse("2022-11-05T01:02:03.456Z"); 33 | 34 | //System.out.println(Base16.encode(byteCodec.serialize(i1))); 35 | 36 | assertThat(byteCodec.serialize(i1), is(Base16.decode("018bec969b068084b8d901"))); 37 | assertThat(byteCodec.deserialize(Base16.decode("018bec969b068084b8d901")), is(i1)); 38 | } 39 | 40 | @Test 41 | public void nonSerializableObjects() { 42 | final KryoByteCodec byteCodec = new KryoByteCodec<>(Widget.class); 43 | 44 | final Widget w1 = new Widget() 45 | .setS("a") 46 | .setI(5) 47 | .setType(WidgetType.A) 48 | .setCreatedAt(Instant.parse("2022-11-12T01:02:03.456Z")); 49 | 50 | //System.out.println(Base16.encode(byteCodec.serialize(w1))); 51 | 52 | assertThat(byteCodec.serialize(w1), is(Base16.decode("01018be1bb9b068084b8d901010a826101"))); 53 | assertThat(byteCodec.deserialize(Base16.decode("01018be1bb9b068084b8d901010a826101")), is(w1)); 54 | } 55 | 56 | static public enum WidgetType { 57 | A, 58 | B, 59 | C; 60 | } 61 | 62 | static public class Widget { 63 | 64 | private String s; 65 | private Integer i; 66 | private WidgetType type; 67 | private Instant createdAt; 68 | 69 | public String getS() { 70 | return s; 71 | } 72 | 73 | public Widget setS(String s) { 74 | this.s = s; 75 | return this; 76 | } 77 | 78 | public Integer getI() { 79 | return i; 80 | } 81 | 82 | public Widget setI(Integer i) { 83 | this.i = i; 84 | return this; 85 | } 86 | 87 | public WidgetType getType() { 88 | return type; 89 | } 90 | 91 | public Widget setType(WidgetType type) { 92 | this.type = type; 93 | return this; 94 | } 95 | 96 | public Instant getCreatedAt() { 97 | return createdAt; 98 | } 99 | 100 | public Widget setCreatedAt(Instant createdAt) { 101 | this.createdAt = createdAt; 102 | return this; 103 | } 104 | 105 | @Override 106 | public boolean equals(Object o) { 107 | if (this == o) return true; 108 | if (o == null || getClass() != o.getClass()) return false; 109 | Widget widget = (Widget) o; 110 | return Objects.equals(s, widget.s) && Objects.equals(i, widget.i) && type == widget.type && Objects.equals(createdAt, widget.createdAt); 111 | } 112 | 113 | @Override 114 | public int hashCode() { 115 | return Objects.hash(s, i, type, createdAt); 116 | } 117 | } 118 | 119 | } -------------------------------------------------------------------------------- /bigmap-leveldb/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | bigmap-leveldb 5 | bigmap-leveldb 6 | jar 7 | 8 | 9 | com.fizzed 10 | bigmap 11 | 1.1.1-SNAPSHOT 12 | 13 | 14 | 15 | 16 | 17 | com.fizzed 18 | bigmap-core 19 | 20 | 21 | 22 | org.iq80.leveldb 23 | leveldb 24 | 25 | 26 | 33 | 34 | 35 | 36 | 37 | org.hamcrest 38 | java-hamcrest 39 | test 40 | 41 | 42 | 43 | org.junit.jupiter 44 | junit-jupiter 45 | test 46 | 47 | 48 | 49 | ch.qos.logback 50 | logback-classic 51 | test 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /bigmap-leveldb/src/main/java/com/fizzed/bigmap/leveldb/LevelBigLinkedMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.leveldb; 17 | 18 | import com.fizzed.bigmap.impl.AbstractBigLinkedMap; 19 | 20 | import java.nio.file.Path; 21 | import java.util.UUID; 22 | 23 | public class LevelBigLinkedMap extends AbstractBigLinkedMap { 24 | 25 | protected LevelBigLinkedMap( 26 | UUID id, 27 | Path directory, 28 | boolean persistent, 29 | LevelBigMap dataMap, 30 | LevelBigMap insertOrderToKeyMap, 31 | LevelBigMap keyToInsertOrderMap) { 32 | 33 | super(id, directory, persistent, dataMap, insertOrderToKeyMap, keyToInsertOrderMap); 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /bigmap-leveldb/src/main/java/com/fizzed/bigmap/leveldb/LevelBigLinkedMapBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.leveldb; 17 | 18 | import com.fizzed.bigmap.*; 19 | import com.fizzed.bigmap.impl.AbstractBigMapBuilder; 20 | import com.fizzed.bigmap.impl.BigMapHelper; 21 | 22 | import java.nio.file.Path; 23 | import java.util.Comparator; 24 | import java.util.UUID; 25 | 26 | public class LevelBigLinkedMapBuilder extends AbstractBigMapBuilder> { 27 | 28 | public LevelBigLinkedMap build() { 29 | final UUID id = UUID.randomUUID(); 30 | final Path dir = BigMapHelper.resolveScratchPath(this.scratchDirectory, false, id, "biglinkedmap-level"); 31 | 32 | // we need 3 subdir paths 33 | final Path dataDir = dir.resolve("data"); 34 | final Path i2kDir = dir.resolve("i2k"); 35 | final Path k2iDir = dir.resolve("k2i"); 36 | 37 | final ByteCodec integerByteCodec = ByteCodecs.integerCodec(); 38 | final Comparator integerComparator = Comparators.autoComparator(Integer.class); 39 | final LevelBigMap dataMap = new LevelBigMap<>(UUID.randomUUID(), dataDir, this.keyCodec, this.keyComparator, this.valueCodec); 40 | final LevelBigMap insertOrderToKeyMap = new LevelBigMap<>(UUID.randomUUID(), i2kDir, integerByteCodec, integerComparator, this.keyCodec); 41 | final LevelBigMap keyToInsertOrderMap = new LevelBigMap<>(UUID.randomUUID(), k2iDir, this.keyCodec, this.keyComparator, integerByteCodec); 42 | 43 | final LevelBigLinkedMap map = new LevelBigLinkedMap<>(id, dir, false, dataMap, insertOrderToKeyMap, keyToInsertOrderMap); 44 | map.setListener(this.registry); 45 | map.open(); 46 | return map; 47 | } 48 | 49 | } -------------------------------------------------------------------------------- /bigmap-leveldb/src/main/java/com/fizzed/bigmap/leveldb/LevelBigLinkedSet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.leveldb; 17 | 18 | import com.fizzed.bigmap.impl.AbstractBigSet; 19 | import com.fizzed.bigmap.impl.None; 20 | 21 | public class LevelBigLinkedSet extends AbstractBigSet { 22 | 23 | protected LevelBigLinkedSet( 24 | LevelBigLinkedMap map) { 25 | 26 | super(map); 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /bigmap-leveldb/src/main/java/com/fizzed/bigmap/leveldb/LevelBigLinkedSetBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.leveldb; 17 | 18 | import com.fizzed.bigmap.ByteCodec; 19 | import com.fizzed.bigmap.ByteCodecs; 20 | import com.fizzed.bigmap.Comparators; 21 | import com.fizzed.bigmap.impl.AbstractBigSetBuilder; 22 | import com.fizzed.bigmap.impl.BigMapHelper; 23 | import com.fizzed.bigmap.impl.None; 24 | 25 | import java.nio.file.Path; 26 | import java.util.Comparator; 27 | import java.util.UUID; 28 | 29 | public class LevelBigLinkedSetBuilder extends AbstractBigSetBuilder> { 30 | 31 | public LevelBigLinkedSet build() { 32 | final UUID id = UUID.randomUUID(); 33 | final Path dir = BigMapHelper.resolveScratchPath(this.scratchDirectory, false, id, "biglinkedset-level"); 34 | 35 | // we need 3 subdir paths 36 | final Path dataDir = dir.resolve("data"); 37 | final Path i2kDir = dir.resolve("i2k"); 38 | final Path k2iDir = dir.resolve("k2i"); 39 | 40 | final ByteCodec integerByteCodec = ByteCodecs.integerCodec(); 41 | final Comparator integerComparator = Comparators.autoComparator(Integer.class); 42 | final LevelBigMap dataMap = new LevelBigMap<>(UUID.randomUUID(), dataDir, this.valueCodec, this.valueComparator, ByteCodecs.noneCodec()); 43 | final LevelBigMap insertOrderToKeyMap = new LevelBigMap<>(UUID.randomUUID(), i2kDir, integerByteCodec, integerComparator, this.valueCodec); 44 | final LevelBigMap keyToInsertOrderMap = new LevelBigMap<>(UUID.randomUUID(), k2iDir, this.valueCodec, this.valueComparator, integerByteCodec); 45 | 46 | final LevelBigLinkedMap map = new LevelBigLinkedMap<>(id, dir, false, dataMap, insertOrderToKeyMap, keyToInsertOrderMap); 47 | 48 | final LevelBigLinkedSet set = new LevelBigLinkedSet<>(map); 49 | set.setListener(this.registry); 50 | set.open(); 51 | return set; 52 | } 53 | 54 | } -------------------------------------------------------------------------------- /bigmap-leveldb/src/main/java/com/fizzed/bigmap/leveldb/LevelBigMapBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.leveldb; 17 | 18 | import com.fizzed.bigmap.impl.AbstractBigMapBuilder; 19 | import com.fizzed.bigmap.impl.BigMapHelper; 20 | 21 | import java.nio.file.Path; 22 | import java.util.UUID; 23 | 24 | public class LevelBigMapBuilder extends AbstractBigMapBuilder> { 25 | 26 | public LevelBigMap build() { 27 | final UUID id = UUID.randomUUID(); 28 | final Path dir = BigMapHelper.resolveScratchPath(this.scratchDirectory, false, id, "bigmap-level"); 29 | 30 | final LevelBigMap map = new LevelBigMap<>(id, dir, this.keyCodec, this.keyComparator, this.valueCodec); 31 | map.setListener(this.registry); 32 | map.open(); 33 | return map; 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /bigmap-leveldb/src/main/java/com/fizzed/bigmap/leveldb/LevelBigObjectCloser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.leveldb; 17 | 18 | import com.fizzed.bigmap.impl.AbstractBigObjectCloser; 19 | import org.iq80.leveldb.DB; 20 | 21 | import java.io.IOException; 22 | import java.nio.file.Path; 23 | import java.util.UUID; 24 | 25 | public class LevelBigObjectCloser extends AbstractBigObjectCloser { 26 | 27 | private final DB db; 28 | 29 | public LevelBigObjectCloser( 30 | UUID id, 31 | boolean persistent, 32 | Path directory, 33 | DB db) { 34 | 35 | super(id, persistent, directory); 36 | this.db = db; 37 | } 38 | 39 | @Override 40 | public void doClose() throws IOException { 41 | this.db.close(); 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /bigmap-leveldb/src/main/java/com/fizzed/bigmap/leveldb/LevelBigSet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.leveldb; 17 | 18 | import com.fizzed.bigmap.impl.AbstractBigSet; 19 | import com.fizzed.bigmap.BigSortedSet; 20 | import com.fizzed.bigmap.impl.None; 21 | 22 | public class LevelBigSet extends AbstractBigSet implements BigSortedSet { 23 | 24 | protected LevelBigSet( 25 | LevelBigMap map) { 26 | 27 | super(map); 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /bigmap-leveldb/src/main/java/com/fizzed/bigmap/leveldb/LevelBigSetBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.leveldb; 17 | 18 | import com.fizzed.bigmap.ByteCodecs; 19 | import com.fizzed.bigmap.impl.AbstractBigSetBuilder; 20 | import com.fizzed.bigmap.impl.BigMapHelper; 21 | import com.fizzed.bigmap.impl.None; 22 | 23 | import java.nio.file.Path; 24 | import java.util.UUID; 25 | 26 | public class LevelBigSetBuilder extends AbstractBigSetBuilder> { 27 | 28 | public LevelBigSet build() { 29 | final UUID id = UUID.randomUUID(); 30 | final Path dir = BigMapHelper.resolveScratchPath(this.scratchDirectory, false, id, "bigset-level"); 31 | 32 | final LevelBigMap map = new LevelBigMap<>(id, dir, this.valueCodec, this.valueComparator, ByteCodecs.noneCodec()); 33 | 34 | final LevelBigSet set = new LevelBigSet<>(map); 35 | set.setListener(this.registry); 36 | set.open(); 37 | return set; 38 | } 39 | 40 | } -------------------------------------------------------------------------------- /bigmap-leveldb/src/main/java/com/fizzed/bigmap/leveldb/LevelForwardIterator.java: -------------------------------------------------------------------------------- 1 | package com.fizzed.bigmap.leveldb; 2 | 3 | import com.fizzed.bigmap.impl.KeyValueBytes; 4 | import org.iq80.leveldb.DB; 5 | import org.iq80.leveldb.DBIterator; 6 | 7 | import java.util.Iterator; 8 | import java.util.Map; 9 | import java.util.NoSuchElementException; 10 | 11 | public class LevelForwardIterator implements Iterator { 12 | 13 | static public LevelForwardIterator build(DB db) { 14 | final DBIterator iter = db.iterator(); 15 | iter.seekToFirst(); 16 | return new LevelForwardIterator(iter); 17 | } 18 | 19 | private final DBIterator it; 20 | 21 | public LevelForwardIterator(DBIterator it) { 22 | this.it = it; 23 | } 24 | 25 | public boolean hasNext() { 26 | return it.hasNext(); 27 | } 28 | 29 | public KeyValueBytes next() { 30 | // NOTE: this throws a NoSuchElementException is no element exists 31 | if (!it.hasNext()) { 32 | throw new NoSuchElementException(); 33 | } 34 | 35 | // we are already on the item we want 36 | final Map.Entry entry = it.next(); 37 | 38 | final KeyValueBytes kvb = new KeyValueBytes(entry.getKey(), entry.getValue()); 39 | 40 | return kvb; 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /bigmap-leveldb/src/main/java/com/fizzed/bigmap/leveldb/LevelJavaComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.leveldb; 17 | 18 | import org.iq80.leveldb.DBComparator; 19 | import com.fizzed.bigmap.ByteCodec; 20 | import java.util.Comparator; 21 | import java.util.Objects; 22 | 23 | public class LevelJavaComparator implements DBComparator { 24 | 25 | private final ByteCodec codec; 26 | private final Comparator comparator; 27 | 28 | public LevelJavaComparator(ByteCodec codec, Comparator comparator) { 29 | Objects.requireNonNull(codec, "codec was null"); 30 | Objects.requireNonNull(comparator, "comparator was null"); 31 | this.codec = codec; 32 | this.comparator = comparator; 33 | } 34 | 35 | @Override 36 | public String name() { 37 | return "jvm-comparator"; 38 | } 39 | 40 | @Override 41 | public byte[] findShortestSeparator(byte[] start, byte[] limit) { 42 | return start; 43 | } 44 | 45 | @Override 46 | public byte[] findShortSuccessor(byte[] key) { 47 | return key; 48 | } 49 | 50 | @Override 51 | public int compare(byte[] o1, byte[] o2) { 52 | T t1 = this.codec.deserialize(o1); 53 | T t2 = this.codec.deserialize(o2); 54 | return this.comparator.compare(t1, t2); 55 | } 56 | 57 | } -------------------------------------------------------------------------------- /bigmap-leveldb/src/test/java/com/fizzed/bigmap/leveldb/LevelBigMapTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.leveldb; 17 | 18 | import org.junit.jupiter.api.Test; 19 | 20 | import java.nio.file.Paths; 21 | import java.util.Map; 22 | 23 | import static org.hamcrest.MatcherAssert.assertThat; 24 | import static org.hamcrest.Matchers.*; 25 | 26 | public class LevelBigMapTest { 27 | 28 | @Test 29 | public void putGetWithStrings() { 30 | final Map map = new LevelBigMapBuilder() 31 | .setScratchDirectory(Paths.get("target")) 32 | .setKeyType(String.class) 33 | .setValueType(String.class) 34 | .build(); 35 | 36 | map.put("a", "1"); 37 | 38 | assertThat(map, hasKey("a")); 39 | assertThat(map.get("a"), is("1")); 40 | assertThat(map.size(), is(1)); 41 | assertThat(map.isEmpty(), is(false)); 42 | 43 | map.remove("a"); 44 | 45 | assertThat(map.get("a"), is(nullValue())); 46 | assertThat(map.size(), is(0)); 47 | assertThat(map.isEmpty(), is(true)); 48 | 49 | String removed = map.put("b", "2"); 50 | 51 | assertThat(removed, is(nullValue())); 52 | assertThat(map.size(), is(1)); 53 | 54 | String removed1 = map.put("b", "3"); 55 | 56 | assertThat(removed1, is("2")); 57 | assertThat(map.size(), is(1)); 58 | } 59 | 60 | } -------------------------------------------------------------------------------- /bigmap-rocksdb/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | bigmap-rocksdb 5 | bigmap-rocksdb 6 | jar 7 | 8 | 9 | com.fizzed 10 | bigmap 11 | 1.1.1-SNAPSHOT 12 | 13 | 14 | 15 | 16 | 17 | com.fizzed 18 | bigmap-core 19 | 20 | 21 | 22 | org.rocksdb 23 | rocksdbjni 24 | 25 | 26 | 27 | 28 | 29 | com.fizzed 30 | jne 31 | test 32 | 33 | 34 | 35 | org.hamcrest 36 | java-hamcrest 37 | test 38 | 39 | 40 | 41 | org.junit.jupiter 42 | junit-jupiter 43 | test 44 | 45 | 46 | 47 | ch.qos.logback 48 | logback-classic 49 | test 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /bigmap-rocksdb/src/main/java/com/fizzed/bigmap/rocksdb/RocksBigLinkedMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.rocksdb; 17 | 18 | import com.fizzed.bigmap.impl.AbstractBigLinkedMap; 19 | 20 | import java.nio.file.Path; 21 | import java.util.UUID; 22 | 23 | public class RocksBigLinkedMap extends AbstractBigLinkedMap { 24 | 25 | protected RocksBigLinkedMap( 26 | UUID id, 27 | Path directory, 28 | boolean persistent, 29 | RocksBigMap dataMap, 30 | RocksBigMap insertOrderToKeyMap, 31 | RocksBigMap keyToInsertOrderMap) { 32 | 33 | super(id, directory, persistent, dataMap, insertOrderToKeyMap, keyToInsertOrderMap); 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /bigmap-rocksdb/src/main/java/com/fizzed/bigmap/rocksdb/RocksBigLinkedMapBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.rocksdb; 17 | 18 | import com.fizzed.bigmap.ByteCodec; 19 | import com.fizzed.bigmap.ByteCodecs; 20 | import com.fizzed.bigmap.Comparators; 21 | import com.fizzed.bigmap.impl.AbstractBigMapBuilder; 22 | import com.fizzed.bigmap.impl.BigMapHelper; 23 | 24 | import java.nio.file.Path; 25 | import java.util.Comparator; 26 | import java.util.UUID; 27 | 28 | public class RocksBigLinkedMapBuilder extends AbstractBigMapBuilder> { 29 | 30 | public RocksBigLinkedMap build() { 31 | final UUID id = UUID.randomUUID(); 32 | final Path dir = BigMapHelper.resolveScratchPath(this.scratchDirectory, false, id, "biglinkedmap-rocks"); 33 | 34 | // we need 3 subdir paths 35 | final Path dataDir = dir.resolve("data"); 36 | final Path i2kDir = dir.resolve("i2k"); 37 | final Path k2iDir = dir.resolve("k2i"); 38 | 39 | final ByteCodec integerByteCodec = ByteCodecs.integerCodec(); 40 | final Comparator integerComparator = Comparators.autoComparator(Integer.class); 41 | final RocksBigMap dataMap = new RocksBigMap<>(UUID.randomUUID(), dataDir, this.keyCodec, this.keyComparator, this.valueCodec); 42 | final RocksBigMap insertOrderToKeyMap = new RocksBigMap<>(UUID.randomUUID(), i2kDir, integerByteCodec, integerComparator, this.keyCodec); 43 | final RocksBigMap keyToInsertOrderMap = new RocksBigMap<>(UUID.randomUUID(), k2iDir, this.keyCodec, this.keyComparator, integerByteCodec); 44 | 45 | final RocksBigLinkedMap map = new RocksBigLinkedMap<>(id, dir, false, dataMap, insertOrderToKeyMap, keyToInsertOrderMap); 46 | map.setListener(this.registry); 47 | map.open(); 48 | return map; 49 | } 50 | 51 | } -------------------------------------------------------------------------------- /bigmap-rocksdb/src/main/java/com/fizzed/bigmap/rocksdb/RocksBigLinkedSet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.rocksdb; 17 | 18 | import com.fizzed.bigmap.impl.AbstractBigSet; 19 | import com.fizzed.bigmap.impl.None; 20 | 21 | public class RocksBigLinkedSet extends AbstractBigSet { 22 | 23 | protected RocksBigLinkedSet( 24 | RocksBigLinkedMap map) { 25 | 26 | super(map); 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /bigmap-rocksdb/src/main/java/com/fizzed/bigmap/rocksdb/RocksBigLinkedSetBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.rocksdb; 17 | 18 | import com.fizzed.bigmap.ByteCodec; 19 | import com.fizzed.bigmap.ByteCodecs; 20 | import com.fizzed.bigmap.Comparators; 21 | import com.fizzed.bigmap.impl.AbstractBigSetBuilder; 22 | import com.fizzed.bigmap.impl.BigMapHelper; 23 | import com.fizzed.bigmap.impl.None; 24 | 25 | import java.nio.file.Path; 26 | import java.util.Comparator; 27 | import java.util.UUID; 28 | 29 | public class RocksBigLinkedSetBuilder extends AbstractBigSetBuilder> { 30 | 31 | public RocksBigLinkedSet build() { 32 | final UUID id = UUID.randomUUID(); 33 | final Path dir = BigMapHelper.resolveScratchPath(this.scratchDirectory, false, id, "biglinkedset-rocks"); 34 | 35 | // we need 3 subdir paths 36 | final Path dataDir = dir.resolve("data"); 37 | final Path i2kDir = dir.resolve("i2k"); 38 | final Path k2iDir = dir.resolve("k2i"); 39 | 40 | final ByteCodec integerByteCodec = ByteCodecs.integerCodec(); 41 | final Comparator integerComparator = Comparators.autoComparator(Integer.class); 42 | final RocksBigMap dataMap = new RocksBigMap<>(UUID.randomUUID(), dataDir, this.valueCodec, this.valueComparator, ByteCodecs.noneCodec()); 43 | final RocksBigMap insertOrderToKeyMap = new RocksBigMap<>(UUID.randomUUID(), i2kDir, integerByteCodec, integerComparator, this.valueCodec); 44 | final RocksBigMap keyToInsertOrderMap = new RocksBigMap<>(UUID.randomUUID(), k2iDir, this.valueCodec, this.valueComparator, integerByteCodec); 45 | 46 | final RocksBigLinkedMap map = new RocksBigLinkedMap<>(id, dir, false, dataMap, insertOrderToKeyMap, keyToInsertOrderMap); 47 | 48 | final RocksBigLinkedSet set = new RocksBigLinkedSet<>(map); 49 | set.setListener(this.registry); 50 | set.open(); 51 | return set; 52 | } 53 | 54 | } -------------------------------------------------------------------------------- /bigmap-rocksdb/src/main/java/com/fizzed/bigmap/rocksdb/RocksBigMapBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.rocksdb; 17 | 18 | import com.fizzed.bigmap.impl.AbstractBigMapBuilder; 19 | import com.fizzed.bigmap.impl.BigMapHelper; 20 | 21 | import java.nio.file.Path; 22 | import java.util.UUID; 23 | 24 | public class RocksBigMapBuilder extends AbstractBigMapBuilder> { 25 | 26 | public RocksBigMap build() { 27 | final UUID id = UUID.randomUUID(); 28 | final Path dir = BigMapHelper.resolveScratchPath(this.scratchDirectory, false, id, "bigmap-rocks"); 29 | 30 | final RocksBigMap map = new RocksBigMap<>(id, dir, this.keyCodec, this.keyComparator, this.valueCodec); 31 | map.setListener(this.registry); 32 | map.open(); 33 | return map; 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /bigmap-rocksdb/src/main/java/com/fizzed/bigmap/rocksdb/RocksBigObjectCloser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.rocksdb; 17 | 18 | import com.fizzed.bigmap.impl.AbstractBigObjectCloser; 19 | import org.rocksdb.RocksDB; 20 | 21 | import java.io.IOException; 22 | import java.nio.file.Path; 23 | import java.util.UUID; 24 | 25 | public class RocksBigObjectCloser extends AbstractBigObjectCloser { 26 | 27 | private final RocksDB db; 28 | 29 | public RocksBigObjectCloser( 30 | UUID id, 31 | boolean persistent, 32 | Path directory, 33 | RocksDB db) { 34 | 35 | super(id, persistent, directory); 36 | this.db = db; 37 | } 38 | 39 | @Override 40 | public void doClose() throws IOException { 41 | this.db.close(); 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /bigmap-rocksdb/src/main/java/com/fizzed/bigmap/rocksdb/RocksBigSet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.rocksdb; 17 | 18 | import com.fizzed.bigmap.impl.AbstractBigSet; 19 | import com.fizzed.bigmap.BigSortedSet; 20 | import com.fizzed.bigmap.impl.None; 21 | 22 | public class RocksBigSet extends AbstractBigSet implements BigSortedSet { 23 | 24 | protected RocksBigSet( 25 | RocksBigMap map) { 26 | 27 | super(map); 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /bigmap-rocksdb/src/main/java/com/fizzed/bigmap/rocksdb/RocksBigSetBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.rocksdb; 17 | 18 | import com.fizzed.bigmap.ByteCodecs; 19 | import com.fizzed.bigmap.impl.AbstractBigSetBuilder; 20 | import com.fizzed.bigmap.impl.BigMapHelper; 21 | import com.fizzed.bigmap.impl.None; 22 | 23 | import java.nio.file.Path; 24 | import java.util.UUID; 25 | 26 | public class RocksBigSetBuilder extends AbstractBigSetBuilder> { 27 | 28 | public RocksBigSet build() { 29 | final UUID id = UUID.randomUUID(); 30 | final Path dir = BigMapHelper.resolveScratchPath(this.scratchDirectory, false, id, "bigset-rocks"); 31 | 32 | final RocksBigMap map = new RocksBigMap<>(id, dir, this.valueCodec, this.valueComparator, ByteCodecs.noneCodec()); 33 | 34 | final RocksBigSet set = new RocksBigSet<>(map); 35 | set.setListener(this.registry); 36 | set.open(); 37 | return set; 38 | } 39 | 40 | } -------------------------------------------------------------------------------- /bigmap-rocksdb/src/main/java/com/fizzed/bigmap/rocksdb/RocksForwardIterator.java: -------------------------------------------------------------------------------- 1 | package com.fizzed.bigmap.rocksdb; 2 | 3 | import com.fizzed.bigmap.impl.KeyValueBytes; 4 | import org.rocksdb.RocksDB; 5 | import org.rocksdb.RocksIterator; 6 | 7 | import java.util.Iterator; 8 | import java.util.NoSuchElementException; 9 | 10 | public class RocksForwardIterator implements Iterator { 11 | 12 | static public RocksForwardIterator build(RocksDB db) { 13 | final RocksIterator iter = db.newIterator(); 14 | iter.seekToFirst(); 15 | return new RocksForwardIterator(iter); 16 | } 17 | 18 | private final org.rocksdb.RocksIterator it; 19 | 20 | public RocksForwardIterator(RocksIterator it) { 21 | this.it = it; 22 | } 23 | 24 | public boolean hasNext() { 25 | return it.isValid(); 26 | } 27 | 28 | public KeyValueBytes next() { 29 | // NOTE: this throws a NoSuchElementException is no element exists 30 | if (!it.isValid()) { 31 | throw new NoSuchElementException(); 32 | } 33 | 34 | // we are already on the item we want 35 | final KeyValueBytes kvb = new KeyValueBytes(it.key(), it.value()); 36 | 37 | // now we'll iterate to the next 38 | it.next(); 39 | 40 | return kvb; 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /bigmap-rocksdb/src/main/java/com/fizzed/bigmap/rocksdb/RocksJavaComparator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.rocksdb; 17 | 18 | import com.fizzed.bigmap.ByteCodec; 19 | import org.rocksdb.AbstractComparator; 20 | import org.rocksdb.ComparatorOptions; 21 | 22 | import java.nio.ByteBuffer; 23 | import java.util.Comparator; 24 | import java.util.Objects; 25 | 26 | public class RocksJavaComparator extends AbstractComparator { 27 | 28 | private final ByteCodec codec; 29 | private final Comparator comparator; 30 | 31 | public RocksJavaComparator(ByteCodec codec, Comparator comparator) { 32 | super(new ComparatorOptions().setUseDirectBuffer(true)); 33 | Objects.requireNonNull(codec, "codec was null"); 34 | Objects.requireNonNull(comparator, "comparator was null"); 35 | this.codec = codec; 36 | this.comparator = comparator; 37 | } 38 | 39 | @Override 40 | public String name() { 41 | return "jvm-comparator"; 42 | } 43 | 44 | @Override 45 | public int compare(ByteBuffer a, ByteBuffer b) { 46 | byte[] _a = new byte[a.remaining()]; 47 | a.get(_a); 48 | byte[] _b = new byte[b.remaining()]; 49 | b.get(_b); 50 | T t1 = this.codec.deserialize(_a); 51 | T t2 = this.codec.deserialize(_b); 52 | return this.comparator.compare(t1, t2); 53 | } 54 | 55 | // @Override 56 | // public byte[] findShortestSeparator(byte[] start, byte[] limit) { 57 | // return start; 58 | // } 59 | // 60 | // @Override 61 | // public byte[] findShortSuccessor(byte[] key) { 62 | // return key; 63 | // } 64 | 65 | // @Override 66 | // public int compare(byte[] o1, byte[] o2) { 67 | // T t1 = this.codec.deserialize(o1); 68 | // T t2 = this.codec.deserialize(o2); 69 | // return this.comparator.compare(t1, t2); 70 | // } 71 | 72 | } -------------------------------------------------------------------------------- /bigmap-rocksdb/src/test/java/com/fizzed/bigmap/rocksdb/RocksBigMapTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.rocksdb; 17 | 18 | import com.fizzed.jne.HardwareArchitecture; 19 | import com.fizzed.jne.NativeTarget; 20 | import com.fizzed.jne.OperatingSystem; 21 | import org.junit.jupiter.api.Test; 22 | import org.junit.jupiter.api.condition.DisabledIf; 23 | import org.junit.jupiter.api.condition.DisabledOnOs; 24 | import org.junit.jupiter.api.condition.OS; 25 | 26 | import java.nio.file.Paths; 27 | import java.util.Map; 28 | 29 | import static org.hamcrest.MatcherAssert.assertThat; 30 | import static org.hamcrest.Matchers.is; 31 | import static org.hamcrest.Matchers.nullValue; 32 | 33 | @DisabledIf("isUnsupportedOs") 34 | public class RocksBigMapTest { 35 | 36 | static public boolean isUnsupportedOs() { 37 | final NativeTarget current = NativeTarget.detect(); 38 | return current.getOperatingSystem() == OperatingSystem.FREEBSD 39 | || current.getOperatingSystem() == OperatingSystem.OPENBSD 40 | || (current.getOperatingSystem() == OperatingSystem.WINDOWS && current.getHardwareArchitecture() == HardwareArchitecture.ARM64) 41 | || (current.getOperatingSystem() == OperatingSystem.LINUX && current.getHardwareArchitecture() == HardwareArchitecture.RISCV64); 42 | } 43 | 44 | @Test 45 | public void putGetWithStrings() { 46 | final Map map = new RocksBigMapBuilder() 47 | .setScratchDirectory(Paths.get("target")) 48 | .setKeyType(String.class) 49 | .setValueType(String.class) 50 | .build(); 51 | 52 | map.put("a", "1"); 53 | 54 | assertThat(map.get("a"), is("1")); 55 | assertThat(map.size(), is(1)); 56 | assertThat(map.isEmpty(), is(false)); 57 | 58 | map.remove("a"); 59 | 60 | assertThat(map.get("a"), is(nullValue())); 61 | assertThat(map.size(), is(0)); 62 | assertThat(map.isEmpty(), is(true)); 63 | 64 | String removed = map.put("b", "2"); 65 | 66 | assertThat(removed, is(nullValue())); 67 | assertThat(map.size(), is(1)); 68 | 69 | String removed1 = map.put("b", "3"); 70 | 71 | assertThat(removed1, is("2")); 72 | assertThat(map.size(), is(1)); 73 | } 74 | 75 | @Test 76 | public void putGetWithLongs() { 77 | final Map map = new RocksBigMapBuilder() 78 | .setScratchDirectory(Paths.get("target")) 79 | .setKeyType(Long.class) 80 | .setValueType(String.class) 81 | .build(); 82 | 83 | map.put(1L, "1"); 84 | 85 | assertThat(map.get(1L), is("1")); 86 | assertThat(map.size(), is(1)); 87 | assertThat(map.isEmpty(), is(false)); 88 | 89 | map.remove(1L); 90 | 91 | assertThat(map.get(1L), is(nullValue())); 92 | assertThat(map.size(), is(0)); 93 | assertThat(map.isEmpty(), is(true)); 94 | 95 | String removed = map.put(2L, "2"); 96 | 97 | assertThat(removed, is(nullValue())); 98 | 99 | String removed1 = map.put(2L, "3"); 100 | 101 | assertThat(removed1, is("2")); 102 | } 103 | 104 | } -------------------------------------------------------------------------------- /bigmap-tkrzw/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | bigmap-tkrzw 5 | bigmap-tkrzw 6 | jar 7 | 8 | 9 | com.fizzed 10 | bigmap 11 | 1.1.1-SNAPSHOT 12 | 13 | 14 | 15 | 16 | 17 | com.fizzed 18 | bigmap-core 19 | 20 | 21 | 22 | com.fizzed 23 | tkrzw-api 24 | 25 | 26 | 27 | 28 | com.fizzed 29 | tkrzw-all-natives 30 | provided 31 | 32 | 33 | 34 | 35 | 36 | org.hamcrest 37 | java-hamcrest 38 | test 39 | 40 | 41 | 42 | org.junit.jupiter 43 | junit-jupiter 44 | test 45 | 46 | 47 | 48 | ch.qos.logback 49 | logback-classic 50 | test 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /bigmap-tkrzw/src/main/java/com/fizzed/bigmap/tkrzw/TkrzwBigLinkedMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.tkrzw; 17 | 18 | import com.fizzed.bigmap.impl.AbstractBigLinkedMap; 19 | 20 | import java.nio.file.Path; 21 | import java.util.UUID; 22 | 23 | public class TkrzwBigLinkedMap extends AbstractBigLinkedMap { 24 | 25 | protected TkrzwBigLinkedMap( 26 | UUID id, 27 | Path directory, 28 | boolean persistent, 29 | TkrzwBigMap dataMap, 30 | TkrzwBigMap insertOrderToKeyMap, 31 | TkrzwBigMap keyToInsertOrderMap) { 32 | 33 | super(id, directory, persistent, dataMap, insertOrderToKeyMap, keyToInsertOrderMap); 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /bigmap-tkrzw/src/main/java/com/fizzed/bigmap/tkrzw/TkrzwBigLinkedMapBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.tkrzw; 17 | 18 | import com.fizzed.bigmap.*; 19 | import com.fizzed.bigmap.impl.AbstractBigMapBuilder; 20 | import com.fizzed.bigmap.impl.BigMapHelper; 21 | 22 | import java.nio.file.Path; 23 | import java.util.Comparator; 24 | import java.util.UUID; 25 | 26 | public class TkrzwBigLinkedMapBuilder extends AbstractBigMapBuilder> { 27 | 28 | public TkrzwBigLinkedMap build() { 29 | final UUID id = UUID.randomUUID(); 30 | final Path path = BigMapHelper.resolveScratchPath(this.scratchDirectory, false, id, "biglinkedmap-tokyo"); 31 | // take the path, append the map name, then the extension tokyo needs 32 | final Path dataFile = BigMapHelper.appendFileName(path, this.name, ".tkt"); 33 | final Path i2kFile = BigMapHelper.appendFileName(path, this.name, "i2k", ".tkt"); 34 | final Path k2iFile = BigMapHelper.appendFileName(path, this.name, "k2i", ".tkt"); 35 | 36 | final ByteCodec integerByteCodec = ByteCodecs.integerCodec(); 37 | final Comparator integerComparator = Comparators.autoComparator(Integer.class); 38 | final TkrzwBigMap dataMap = new TkrzwBigMap<>(UUID.randomUUID(), dataFile, this.keyCodec, this.keyComparator, this.valueCodec); 39 | final TkrzwBigMap insertOrderToKeyMap = new TkrzwBigMap<>(UUID.randomUUID(), i2kFile, integerByteCodec, integerComparator, this.keyCodec); 40 | final TkrzwBigMap keyToInsertOrderMap = new TkrzwBigMap<>(UUID.randomUUID(), k2iFile, this.keyCodec, this.keyComparator, integerByteCodec); 41 | 42 | final TkrzwBigLinkedMap map = new TkrzwBigLinkedMap<>(id, dataFile, false, dataMap, insertOrderToKeyMap, keyToInsertOrderMap); 43 | map.setListener(this.registry); 44 | map.open(); 45 | return map; 46 | } 47 | 48 | } -------------------------------------------------------------------------------- /bigmap-tkrzw/src/main/java/com/fizzed/bigmap/tkrzw/TkrzwBigLinkedSet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.tkrzw; 17 | 18 | import com.fizzed.bigmap.impl.AbstractBigSet; 19 | import com.fizzed.bigmap.impl.None; 20 | 21 | public class TkrzwBigLinkedSet extends AbstractBigSet { 22 | 23 | protected TkrzwBigLinkedSet( 24 | TkrzwBigLinkedMap map) { 25 | 26 | super(map); 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /bigmap-tkrzw/src/main/java/com/fizzed/bigmap/tkrzw/TkrzwBigLinkedSetBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.tkrzw; 17 | 18 | import com.fizzed.bigmap.ByteCodec; 19 | import com.fizzed.bigmap.ByteCodecs; 20 | import com.fizzed.bigmap.Comparators; 21 | import com.fizzed.bigmap.impl.AbstractBigSetBuilder; 22 | import com.fizzed.bigmap.impl.BigMapHelper; 23 | import com.fizzed.bigmap.impl.None; 24 | 25 | import java.nio.file.Path; 26 | import java.util.Comparator; 27 | import java.util.UUID; 28 | 29 | public class TkrzwBigLinkedSetBuilder extends AbstractBigSetBuilder> { 30 | 31 | public TkrzwBigLinkedSet build() { 32 | final UUID id = UUID.randomUUID(); 33 | final Path path = BigMapHelper.resolveScratchPath(this.scratchDirectory, false, id, "biglinkedset-tokyo"); 34 | // take the path, append the map name, then the extension tokyo needs 35 | final Path dataFile = BigMapHelper.appendFileName(path, this.name, ".tkt"); 36 | final Path i2kFile = BigMapHelper.appendFileName(path, this.name, "i2k", ".tkt"); 37 | final Path k2iFile = BigMapHelper.appendFileName(path, this.name, "k2i", ".tkt"); 38 | 39 | final ByteCodec integerByteCodec = ByteCodecs.integerCodec(); 40 | final Comparator integerComparator = Comparators.autoComparator(Integer.class); 41 | final TkrzwBigMap dataMap = new TkrzwBigMap<>(UUID.randomUUID(), dataFile, this.valueCodec, this.valueComparator, ByteCodecs.noneCodec()); 42 | final TkrzwBigMap insertOrderToKeyMap = new TkrzwBigMap<>(UUID.randomUUID(), i2kFile, integerByteCodec, integerComparator, this.valueCodec); 43 | final TkrzwBigMap keyToInsertOrderMap = new TkrzwBigMap<>(UUID.randomUUID(), k2iFile, this.valueCodec, this.valueComparator, integerByteCodec); 44 | 45 | final TkrzwBigLinkedMap map = new TkrzwBigLinkedMap<>(id, dataFile, false, dataMap, insertOrderToKeyMap, keyToInsertOrderMap); 46 | 47 | final TkrzwBigLinkedSet set = new TkrzwBigLinkedSet<>(map); 48 | set.setListener(this.registry); 49 | set.open(); 50 | return set; 51 | } 52 | 53 | } -------------------------------------------------------------------------------- /bigmap-tkrzw/src/main/java/com/fizzed/bigmap/tkrzw/TkrzwBigMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.tkrzw; 17 | 18 | import com.fizzed.bigmap.*; 19 | import com.fizzed.bigmap.impl.AbstractBigMap; 20 | import com.fizzed.bigmap.impl.ByteArrayBigMap; 21 | import com.fizzed.bigmap.impl.KeyValueBytes; 22 | import tkrzw.DBM; 23 | import tkrzw.Status; 24 | 25 | import java.nio.file.Files; 26 | import java.nio.file.Path; 27 | import java.util.Comparator; 28 | import java.util.Iterator; 29 | import java.util.Objects; 30 | import java.util.UUID; 31 | 32 | public class TkrzwBigMap extends AbstractBigMap implements ByteArrayBigMap, BigSortedMap { 33 | 34 | protected DBM db; 35 | 36 | protected TkrzwBigMap( 37 | UUID id, 38 | Path file, 39 | ByteCodec keyCodec, 40 | Comparator keyComparator, 41 | ByteCodec valueCodec) { 42 | 43 | super(id, file, false, keyCodec, keyComparator, valueCodec); 44 | 45 | Objects.requireNonNull(valueCodec, "valueCodec was null"); 46 | } 47 | 48 | public DBM getDb() { 49 | return this.db; 50 | } 51 | 52 | @Override 53 | protected void _open() { 54 | this.db = new DBM(); 55 | try { 56 | Files.createDirectories(this.path.getParent()); 57 | } catch (Exception e) { 58 | throw new RuntimeException(e); 59 | } 60 | 61 | Status status; 62 | 63 | status = this.db.open(this.path.toAbsolutePath().toString(), true); 64 | if (!status.isOK()){ 65 | throw new RuntimeException("Tkrzw open error: " + status.getMessage()); 66 | } 67 | this.closer = new TkrzwBigObjectCloser(this.id, this.persistent, this.path, this.db); 68 | } 69 | 70 | @Override 71 | public byte[] _get(byte[] keyBytes) { 72 | return this.db.get(keyBytes); 73 | } 74 | 75 | @Override 76 | public byte[] _put(byte[] keyBytes, byte[] valueBytes) { 77 | byte[] oldValueBytes = this.db.get(keyBytes); 78 | 79 | this._set(keyBytes, valueBytes); 80 | 81 | return oldValueBytes; 82 | } 83 | 84 | @Override 85 | public void _set(byte[] keyBytes, byte[] valueBytes) { 86 | final Status status = this.db.set(keyBytes, valueBytes); 87 | if (!status.isOK()) { 88 | throw new BigMapDataException("Set failed " + status.getMessage()); 89 | } 90 | } 91 | 92 | @Override 93 | public boolean _containsKey(byte[] keyBytes) { 94 | return this.db.get(keyBytes) != null; 95 | } 96 | 97 | @Override 98 | public byte[] _remove(byte[] keyBytes) { 99 | byte[] valueBytes = this.db.get(keyBytes); 100 | 101 | final Status status = this.db.remove(keyBytes); 102 | 103 | if (!status.isOK()) { 104 | // if no record is found? 105 | if (status.getCode() == Status.Code.NOT_FOUND_ERROR) { 106 | return null; 107 | } 108 | throw new BigMapDataException("Remove failed " + status.getMessage()); 109 | } 110 | 111 | return valueBytes; 112 | } 113 | 114 | @Override 115 | public void _delete(byte[] keyBytes) { 116 | final Status status = this.db.remove(keyBytes); 117 | 118 | if (!status.isOK() && status.getCode() != Status.Code.NOT_FOUND_ERROR) { 119 | throw new BigMapDataException("Remove failed " + status.getMessage()); 120 | } 121 | } 122 | 123 | @Override 124 | public Iterator _forwardIterator() { 125 | return TkrzwForwardIterator.build(this.db); 126 | } 127 | 128 | } -------------------------------------------------------------------------------- /bigmap-tkrzw/src/main/java/com/fizzed/bigmap/tkrzw/TkrzwBigMapBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.tkrzw; 17 | 18 | import com.fizzed.bigmap.impl.AbstractBigMapBuilder; 19 | import com.fizzed.bigmap.impl.BigMapHelper; 20 | 21 | import java.nio.file.Path; 22 | import java.util.UUID; 23 | 24 | public class TkrzwBigMapBuilder extends AbstractBigMapBuilder> { 25 | 26 | public TkrzwBigMap build() { 27 | final UUID id = UUID.randomUUID(); 28 | final Path path = BigMapHelper.resolveScratchPath(this.scratchDirectory, false, id, "bigmap-tokyo"); 29 | // take the path, append the map name, then the extension tokyo needs 30 | final Path file = BigMapHelper.appendFileName(path, this.name, ".tkt"); 31 | 32 | final TkrzwBigMap map = new TkrzwBigMap<>(id, file, this.keyCodec, this.keyComparator, this.valueCodec); 33 | map.setListener(this.registry); 34 | map.open(); 35 | return map; 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /bigmap-tkrzw/src/main/java/com/fizzed/bigmap/tkrzw/TkrzwBigObjectCloser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.tkrzw; 17 | 18 | import com.fizzed.bigmap.impl.AbstractBigObjectCloser; 19 | import tkrzw.DBM; 20 | 21 | import java.io.IOException; 22 | import java.nio.file.Path; 23 | import java.util.UUID; 24 | 25 | public class TkrzwBigObjectCloser extends AbstractBigObjectCloser { 26 | 27 | private final DBM dbm; 28 | 29 | public TkrzwBigObjectCloser( 30 | UUID id, 31 | boolean persistent, 32 | Path directory, 33 | DBM dbm) { 34 | 35 | super(id, persistent, directory); 36 | this.dbm = dbm; 37 | } 38 | 39 | @Override 40 | public void doClose() throws IOException { 41 | this.dbm.close(); 42 | // also, very important its destructed too 43 | this.dbm.destruct(); 44 | } 45 | 46 | } -------------------------------------------------------------------------------- /bigmap-tkrzw/src/main/java/com/fizzed/bigmap/tkrzw/TkrzwBigSet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.tkrzw; 17 | 18 | import com.fizzed.bigmap.impl.AbstractBigSet; 19 | import com.fizzed.bigmap.BigSortedSet; 20 | import com.fizzed.bigmap.impl.None; 21 | 22 | public class TkrzwBigSet extends AbstractBigSet implements BigSortedSet { 23 | 24 | protected TkrzwBigSet( 25 | TkrzwBigMap map) { 26 | 27 | super(map); 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /bigmap-tkrzw/src/main/java/com/fizzed/bigmap/tkrzw/TkrzwBigSetBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.tkrzw; 17 | 18 | import com.fizzed.bigmap.*; 19 | import com.fizzed.bigmap.impl.AbstractBigSetBuilder; 20 | import com.fizzed.bigmap.impl.BigMapHelper; 21 | import com.fizzed.bigmap.impl.None; 22 | 23 | import java.nio.file.Path; 24 | import java.util.UUID; 25 | 26 | public class TkrzwBigSetBuilder extends AbstractBigSetBuilder> { 27 | 28 | public TkrzwBigSet build() { 29 | final UUID id = UUID.randomUUID(); 30 | final Path path = BigMapHelper.resolveScratchPath(this.scratchDirectory, false, id, "bigset-tokyo"); 31 | // take the path, append the map name, then the extension tokyo needs 32 | final Path file = BigMapHelper.appendFileName(path, this.name, ".tkt"); 33 | 34 | final TkrzwBigMap map = new TkrzwBigMap<>(id, file, this.valueCodec, this.valueComparator, ByteCodecs.noneCodec()); 35 | 36 | final TkrzwBigSet set = new TkrzwBigSet<>(map); 37 | set.setListener(this.registry); 38 | set.open(); 39 | return set; 40 | } 41 | 42 | } -------------------------------------------------------------------------------- /bigmap-tkrzw/src/main/java/com/fizzed/bigmap/tkrzw/TkrzwForwardIterator.java: -------------------------------------------------------------------------------- 1 | package com.fizzed.bigmap.tkrzw; 2 | 3 | import com.fizzed.bigmap.impl.KeyValueBytes; 4 | import tkrzw.DBM; 5 | 6 | import java.io.Closeable; 7 | import java.util.Iterator; 8 | import java.util.NoSuchElementException; 9 | 10 | public class TkrzwForwardIterator implements Closeable, Iterator { 11 | 12 | static public TkrzwForwardIterator build(DBM db) { 13 | final tkrzw.Iterator iterator = db.makeIterator(); 14 | iterator.first(); 15 | 16 | // probe if it has a "first" record 17 | final boolean hasNext = iterator.getKey() != null; 18 | 19 | // CRITICAL: if there isn't a next record, we need to destruct the iterator 20 | // so the native resources are cleaned up 21 | if (!hasNext) { 22 | iterator.destruct(); 23 | } 24 | 25 | return new TkrzwForwardIterator(iterator, hasNext); 26 | } 27 | 28 | private tkrzw.Iterator iterator; 29 | private boolean hasNext; 30 | // since we need to forward look at the next key/value, we'll keep it 31 | // locally present so we don't need to get it fetched/allocated from the db again 32 | private byte[] nextKey; 33 | private byte[] nextValue; 34 | 35 | public TkrzwForwardIterator(tkrzw.Iterator iterator, boolean hasNext) { 36 | this.iterator = iterator; 37 | this.hasNext = hasNext; 38 | if (hasNext) { 39 | this.nextKey = iterator.getKey(); 40 | this.nextValue = iterator.getValue(); 41 | } 42 | } 43 | 44 | protected void finalize() { 45 | // even though finalize is not encouraged, we need to clean up native resources 46 | this.close(); 47 | } 48 | 49 | public void close() { 50 | if (this.iterator != null) { 51 | this.iterator.destruct(); 52 | this.iterator = null; 53 | } 54 | } 55 | 56 | @Override 57 | public boolean hasNext() { 58 | return this.hasNext; 59 | } 60 | 61 | @Override 62 | public KeyValueBytes next() { 63 | // NOTE: this throws a NoSuchElementException is no element exists 64 | if (!hasNext) { 65 | throw new NoSuchElementException(); 66 | } 67 | 68 | // we are already on the item we want 69 | final KeyValueBytes kvb = new KeyValueBytes(this.nextKey, this.nextValue); 70 | 71 | // now we'll iterate to the next ahead of time 72 | // NOTE: if the current record is missing this operation will fail. 73 | // if the current record exists, but the next record is missing, this doesn't fail 74 | this.iterator.next(); 75 | this.nextKey = this.iterator.getKey(); 76 | this.nextValue = this.iterator.getValue(); 77 | this.hasNext = this.nextKey != null; 78 | 79 | // CRITICAL: if there's no "next" value, this iterator is done, and we can clean up resources 80 | if (!this.hasNext) { 81 | this.close(); 82 | } 83 | 84 | return kvb; 85 | } 86 | 87 | } -------------------------------------------------------------------------------- /bigmap-tkrzw/src/test/java/com/fizzed/bigmap/tkrzw/TkrzwBigMapTest.java: -------------------------------------------------------------------------------- 1 | package com.fizzed.bigmap.tkrzw; 2 | 3 | import com.fizzed.bigmap.BigMap; 4 | import org.junit.jupiter.api.Test; 5 | import org.junit.jupiter.api.condition.DisabledOnOs; 6 | import org.junit.jupiter.api.condition.OS; 7 | 8 | import java.io.IOException; 9 | import java.nio.file.Files; 10 | import java.nio.file.Paths; 11 | import java.util.Map; 12 | 13 | import static org.hamcrest.CoreMatchers.is; 14 | import static org.hamcrest.CoreMatchers.nullValue; 15 | import static org.hamcrest.MatcherAssert.assertThat; 16 | 17 | //@DisabledOnOs({ OS.FREEBSD, OS.OPENBSD }) 18 | public class TkrzwBigMapTest { 19 | 20 | @Test 21 | public void putGetWithStrings() { 22 | final Map map = new TkrzwBigMapBuilder() 23 | .setScratchDirectory(Paths.get("target")) 24 | .setKeyType(String.class) 25 | .setValueType(String.class) 26 | .autoCloseObjects() 27 | .build(); 28 | 29 | map.put("a", "1"); 30 | 31 | assertThat(map.get("a"), is("1")); 32 | assertThat(map.size(), is(1)); 33 | assertThat(map.isEmpty(), is(false)); 34 | 35 | map.remove("a"); 36 | 37 | assertThat(map.get("a"), is(nullValue())); 38 | assertThat(map.size(), is(0)); 39 | assertThat(map.isEmpty(), is(true)); 40 | 41 | String removed = map.put("b", "2"); 42 | 43 | assertThat(removed, is(nullValue())); 44 | assertThat(map.size(), is(1)); 45 | 46 | String removed1 = map.put("b", "3"); 47 | 48 | assertThat(removed1, is("2")); 49 | assertThat(map.size(), is(1)); 50 | } 51 | 52 | @Test 53 | public void close() throws IOException { 54 | final BigMap map = new TkrzwBigMapBuilder() 55 | .setScratchDirectory(Paths.get("target")) 56 | .setKeyType(String.class) 57 | .setValueType(String.class) 58 | .build(); 59 | 60 | map.put("a", "1"); 61 | 62 | map.close(); 63 | 64 | assertThat(map.isClosed(), is(true)); 65 | assertThat(Files.exists(map.getPath()), is(false)); 66 | } 67 | 68 | } -------------------------------------------------------------------------------- /bigmap-tkrzw/src/test/java/com/fizzed/bigmap/tkrzw/TkrzwBigSetTest.java: -------------------------------------------------------------------------------- 1 | package com.fizzed.bigmap.tkrzw; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.junit.jupiter.api.condition.DisabledOnOs; 5 | import org.junit.jupiter.api.condition.OS; 6 | 7 | import java.nio.file.Paths; 8 | import java.util.Set; 9 | 10 | //@DisabledOnOs({ OS.FREEBSD, OS.OPENBSD }) 11 | public class TkrzwBigSetTest { 12 | 13 | @Test 14 | public void putGetWithStrings() { 15 | final Set set = new TkrzwBigSetBuilder() 16 | .setScratchDirectory(Paths.get("target")) 17 | .setValueType(String.class) 18 | .autoCloseObjects() 19 | .build(); 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /bigmap-tokyocabinet/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | 4 | bigmap-tokyocabinet 5 | bigmap-tokyocabinet 6 | jar 7 | 8 | 9 | com.fizzed 10 | bigmap 11 | 1.1.1-SNAPSHOT 12 | 13 | 14 | 15 | 16 | 17 | com.fizzed 18 | bigmap-core 19 | 20 | 21 | 22 | com.fizzed 23 | tokyocabinet-api 24 | 25 | 26 | 27 | 28 | com.fizzed 29 | tokyocabinet-all-natives 30 | provided 31 | 32 | 33 | 34 | 35 | 36 | org.hamcrest 37 | java-hamcrest 38 | test 39 | 40 | 41 | 42 | org.junit.jupiter 43 | junit-jupiter 44 | test 45 | 46 | 47 | 48 | ch.qos.logback 49 | logback-classic 50 | test 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /bigmap-tokyocabinet/src/main/java/com/fizzed/bigmap/tokyocabinet/TokyoBigLinkedMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.tokyocabinet; 17 | 18 | import com.fizzed.bigmap.impl.AbstractBigLinkedMap; 19 | 20 | import java.nio.file.Path; 21 | import java.util.UUID; 22 | 23 | public class TokyoBigLinkedMap extends AbstractBigLinkedMap { 24 | 25 | protected TokyoBigLinkedMap( 26 | UUID id, 27 | Path directory, 28 | boolean persistent, 29 | TokyoBigMap dataMap, 30 | TokyoBigMap insertOrderToKeyMap, 31 | TokyoBigMap keyToInsertOrderMap) { 32 | 33 | super(id, directory, persistent, dataMap, insertOrderToKeyMap, keyToInsertOrderMap); 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /bigmap-tokyocabinet/src/main/java/com/fizzed/bigmap/tokyocabinet/TokyoBigLinkedMapBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.tokyocabinet; 17 | 18 | import com.fizzed.bigmap.*; 19 | import com.fizzed.bigmap.impl.AbstractBigMapBuilder; 20 | import com.fizzed.bigmap.impl.BigMapHelper; 21 | 22 | import java.nio.file.Path; 23 | import java.util.Comparator; 24 | import java.util.Objects; 25 | import java.util.UUID; 26 | 27 | public class TokyoBigLinkedMapBuilder extends AbstractBigMapBuilder> { 28 | 29 | public TokyoBigLinkedMap build() { 30 | final UUID id = UUID.randomUUID(); 31 | final Path path = BigMapHelper.resolveScratchPath(this.scratchDirectory, false, id, "biglinkedmap-tokyo"); 32 | // take the path, append the map name, then the extension tokyo needs 33 | final Path dataFile = BigMapHelper.appendFileName(path, this.name, ".tcb"); 34 | final Path i2kFile = BigMapHelper.appendFileName(path, this.name, "i2k", ".tcb"); 35 | final Path k2iFile = BigMapHelper.appendFileName(path, this.name, "k2i", ".tcb"); 36 | 37 | final ByteCodec integerByteCodec = ByteCodecs.integerCodec(); 38 | final Comparator integerComparator = Comparators.autoComparator(Integer.class); 39 | final TokyoBigMap dataMap = new TokyoBigMap<>(UUID.randomUUID(), dataFile, this.keyCodec, this.keyComparator, this.valueCodec); 40 | final TokyoBigMap insertOrderToKeyMap = new TokyoBigMap<>(UUID.randomUUID(), i2kFile, integerByteCodec, integerComparator, this.keyCodec); 41 | final TokyoBigMap keyToInsertOrderMap = new TokyoBigMap<>(UUID.randomUUID(), k2iFile, this.keyCodec, this.keyComparator, integerByteCodec); 42 | 43 | final TokyoBigLinkedMap map = new TokyoBigLinkedMap<>(id, dataFile, false, dataMap, insertOrderToKeyMap, keyToInsertOrderMap); 44 | map.setListener(this.registry); 45 | map.open(); 46 | return map; 47 | } 48 | 49 | } -------------------------------------------------------------------------------- /bigmap-tokyocabinet/src/main/java/com/fizzed/bigmap/tokyocabinet/TokyoBigLinkedSet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.tokyocabinet; 17 | 18 | import com.fizzed.bigmap.impl.AbstractBigSet; 19 | import com.fizzed.bigmap.impl.None; 20 | 21 | public class TokyoBigLinkedSet extends AbstractBigSet { 22 | 23 | protected TokyoBigLinkedSet( 24 | TokyoBigLinkedMap map) { 25 | 26 | super(map); 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /bigmap-tokyocabinet/src/main/java/com/fizzed/bigmap/tokyocabinet/TokyoBigLinkedSetBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.tokyocabinet; 17 | 18 | import com.fizzed.bigmap.ByteCodec; 19 | import com.fizzed.bigmap.ByteCodecs; 20 | import com.fizzed.bigmap.Comparators; 21 | import com.fizzed.bigmap.impl.AbstractBigSetBuilder; 22 | import com.fizzed.bigmap.impl.BigMapHelper; 23 | import com.fizzed.bigmap.impl.None; 24 | 25 | import java.nio.file.Path; 26 | import java.util.Comparator; 27 | import java.util.Objects; 28 | import java.util.UUID; 29 | 30 | public class TokyoBigLinkedSetBuilder extends AbstractBigSetBuilder> { 31 | 32 | public TokyoBigLinkedSet build() { 33 | final UUID id = UUID.randomUUID(); 34 | final Path path = BigMapHelper.resolveScratchPath(this.scratchDirectory, false, id, "biglinkedset-tokyo"); 35 | // take the path, append the map name, then the extension tokyo needs 36 | final Path dataFile = BigMapHelper.appendFileName(path, this.name, ".tcb"); 37 | final Path i2kFile = BigMapHelper.appendFileName(path, this.name, "i2k", ".tcb"); 38 | final Path k2iFile = BigMapHelper.appendFileName(path, this.name, "k2i", ".tcb"); 39 | 40 | final ByteCodec integerByteCodec = ByteCodecs.integerCodec(); 41 | final Comparator integerComparator = Comparators.autoComparator(Integer.class); 42 | final TokyoBigMap dataMap = new TokyoBigMap<>(UUID.randomUUID(), dataFile, this.valueCodec, this.valueComparator, ByteCodecs.noneCodec()); 43 | final TokyoBigMap insertOrderToKeyMap = new TokyoBigMap<>(UUID.randomUUID(), i2kFile, integerByteCodec, integerComparator, this.valueCodec); 44 | final TokyoBigMap keyToInsertOrderMap = new TokyoBigMap<>(UUID.randomUUID(), k2iFile, this.valueCodec, this.valueComparator, integerByteCodec); 45 | 46 | final TokyoBigLinkedMap map = new TokyoBigLinkedMap<>(id, dataFile, false, dataMap, insertOrderToKeyMap, keyToInsertOrderMap); 47 | 48 | final TokyoBigLinkedSet set = new TokyoBigLinkedSet<>(map); 49 | set.setListener(this.registry); 50 | set.open(); 51 | return set; 52 | } 53 | 54 | } -------------------------------------------------------------------------------- /bigmap-tokyocabinet/src/main/java/com/fizzed/bigmap/tokyocabinet/TokyoBigMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.tokyocabinet; 17 | 18 | import com.fizzed.bigmap.*; 19 | import com.fizzed.bigmap.impl.AbstractBigMap; 20 | import com.fizzed.bigmap.impl.ByteArrayBigMap; 21 | import com.fizzed.bigmap.impl.KeyValueBytes; 22 | import tokyocabinet.BDB; 23 | import tokyocabinet.HDB; 24 | 25 | import java.nio.file.Files; 26 | import java.nio.file.Path; 27 | import java.util.Comparator; 28 | import java.util.Iterator; 29 | import java.util.Objects; 30 | import java.util.UUID; 31 | 32 | public class TokyoBigMap extends AbstractBigMap implements ByteArrayBigMap, BigSortedMap { 33 | 34 | protected BDB db; 35 | 36 | protected TokyoBigMap( 37 | UUID id, 38 | Path file, 39 | ByteCodec keyCodec, 40 | Comparator keyComparator, 41 | ByteCodec valueCodec) { 42 | 43 | super(id, file, false, keyCodec, keyComparator, valueCodec); 44 | 45 | Objects.requireNonNull(valueCodec, "valueCodec was null"); 46 | } 47 | 48 | public BDB getDb() { 49 | return this.db; 50 | } 51 | 52 | @Override 53 | protected void _open() { 54 | this.db = new BDB(); 55 | try { 56 | Files.createDirectories(this.path.getParent()); 57 | } catch (Exception e) { 58 | throw new RuntimeException(e); 59 | } 60 | // build database, initialize stats we track 61 | if (!this.db.open(this.path.toAbsolutePath().toString(), HDB.OWRITER | HDB.OCREAT)){ 62 | int ecode = db.ecode(); 63 | throw new RuntimeException("TokyoCabinet open error: " + this.db.errmsg(ecode)); 64 | } 65 | this.closer = new TokyoBigObjectCloser(this.id, this.persistent, this.path, this.db); 66 | } 67 | 68 | @Override 69 | public byte[] _get(byte[] keyBytes) { 70 | return this.db.get(keyBytes); 71 | } 72 | 73 | @Override 74 | public byte[] _put(byte[] keyBytes, byte[] valueBytes) { 75 | byte[] oldValueBytes = this.db.get(keyBytes); 76 | 77 | this.db.put(keyBytes, valueBytes); 78 | 79 | return oldValueBytes; 80 | } 81 | 82 | @Override 83 | public void _set(byte[] keyBytes, byte[] valueBytes) { 84 | this.db.put(keyBytes, valueBytes); 85 | } 86 | 87 | @Override 88 | public boolean _containsKey(byte[] keyBytes) { 89 | return this.db.get(keyBytes) != null; 90 | } 91 | 92 | @Override 93 | public byte[] _remove(byte[] keyBytes) { 94 | byte[] valueBytes = this.db.get(keyBytes); 95 | 96 | if (this.db.out(keyBytes)) { 97 | return valueBytes; 98 | } 99 | 100 | return null; 101 | } 102 | 103 | @Override 104 | public void _delete(byte[] keyBytes) { 105 | this.db.out(keyBytes); 106 | } 107 | 108 | @Override 109 | public Iterator _forwardIterator() { 110 | return TokyoForwardIterator.build(this.db); 111 | } 112 | 113 | } -------------------------------------------------------------------------------- /bigmap-tokyocabinet/src/main/java/com/fizzed/bigmap/tokyocabinet/TokyoBigMapBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.tokyocabinet; 17 | 18 | import com.fizzed.bigmap.impl.AbstractBigMapBuilder; 19 | import com.fizzed.bigmap.impl.BigMapHelper; 20 | 21 | import java.nio.file.Path; 22 | import java.util.Objects; 23 | import java.util.UUID; 24 | 25 | public class TokyoBigMapBuilder extends AbstractBigMapBuilder> { 26 | 27 | public TokyoBigMap build() { 28 | final UUID id = UUID.randomUUID(); 29 | final Path path = BigMapHelper.resolveScratchPath(this.scratchDirectory, false, id, "bigmap-tokyo"); 30 | // take the path, append the map name, then the extension tokyo needs 31 | final Path file = BigMapHelper.appendFileName(path, this.name, ".tcb"); 32 | 33 | final TokyoBigMap map = new TokyoBigMap<>(id, file, this.keyCodec, this.keyComparator, this.valueCodec); 34 | map.setListener(this.registry); 35 | map.open(); 36 | return map; 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /bigmap-tokyocabinet/src/main/java/com/fizzed/bigmap/tokyocabinet/TokyoBigObjectCloser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.tokyocabinet; 17 | 18 | import com.fizzed.bigmap.impl.AbstractBigObjectCloser; 19 | import tokyocabinet.BDB; 20 | 21 | import java.io.IOException; 22 | import java.nio.file.Path; 23 | import java.util.UUID; 24 | 25 | public class TokyoBigObjectCloser extends AbstractBigObjectCloser { 26 | 27 | private final BDB bdb; 28 | 29 | public TokyoBigObjectCloser( 30 | UUID id, 31 | boolean persistent, 32 | Path directory, 33 | BDB bdb) { 34 | 35 | super(id, persistent, directory); 36 | this.bdb = bdb; 37 | } 38 | 39 | @Override 40 | public void doClose() throws IOException { 41 | this.bdb.close(); 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /bigmap-tokyocabinet/src/main/java/com/fizzed/bigmap/tokyocabinet/TokyoBigSet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.tokyocabinet; 17 | 18 | import com.fizzed.bigmap.impl.AbstractBigSet; 19 | import com.fizzed.bigmap.BigSortedSet; 20 | import com.fizzed.bigmap.impl.None; 21 | 22 | public class TokyoBigSet extends AbstractBigSet implements BigSortedSet { 23 | 24 | protected TokyoBigSet( 25 | TokyoBigMap map) { 26 | 27 | super(map); 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /bigmap-tokyocabinet/src/main/java/com/fizzed/bigmap/tokyocabinet/TokyoBigSetBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Fizzed, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.fizzed.bigmap.tokyocabinet; 17 | 18 | import com.fizzed.bigmap.*; 19 | import com.fizzed.bigmap.impl.AbstractBigSetBuilder; 20 | import com.fizzed.bigmap.impl.BigMapHelper; 21 | import com.fizzed.bigmap.impl.None; 22 | 23 | import java.nio.file.Path; 24 | import java.util.Objects; 25 | import java.util.UUID; 26 | 27 | public class TokyoBigSetBuilder extends AbstractBigSetBuilder> { 28 | 29 | public TokyoBigSet build() { 30 | final UUID id = UUID.randomUUID(); 31 | final Path path = BigMapHelper.resolveScratchPath(this.scratchDirectory, false, id, "bigset-tokyo"); 32 | // take the path, append the map name, then the extension tokyo needs 33 | final Path file = BigMapHelper.appendFileName(path, this.name, ".tcb"); 34 | 35 | final TokyoBigMap map = new TokyoBigMap<>(id, file, this.valueCodec, this.valueComparator, ByteCodecs.noneCodec()); 36 | 37 | final TokyoBigSet set = new TokyoBigSet<>(map); 38 | set.setListener(this.registry); 39 | set.open(); 40 | return set; 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /bigmap-tokyocabinet/src/main/java/com/fizzed/bigmap/tokyocabinet/TokyoForwardIterator.java: -------------------------------------------------------------------------------- 1 | package com.fizzed.bigmap.tokyocabinet; 2 | 3 | import com.fizzed.bigmap.impl.KeyValueBytes; 4 | import tokyocabinet.BDB; 5 | import tokyocabinet.BDBCUR; 6 | 7 | import java.util.Iterator; 8 | import java.util.NoSuchElementException; 9 | 10 | public class TokyoForwardIterator implements Iterator { 11 | 12 | static public TokyoForwardIterator build(BDB db) { 13 | BDBCUR cursor = new BDBCUR(db); 14 | boolean hasNext = cursor.first(); 15 | return new TokyoForwardIterator(cursor, hasNext); 16 | } 17 | 18 | private final BDBCUR cursor; 19 | private boolean hasNext; 20 | 21 | public TokyoForwardIterator(BDBCUR cursor, boolean hasNext) { 22 | this.cursor = cursor; 23 | this.hasNext = hasNext; 24 | } 25 | 26 | public boolean hasNext() { 27 | return this.hasNext; 28 | } 29 | 30 | public KeyValueBytes next() { 31 | // NOTE: this throws a NoSuchElementException is no element exists 32 | if (!hasNext) { 33 | throw new NoSuchElementException(); 34 | } 35 | 36 | // we are already on the item we want 37 | final KeyValueBytes kvb = new KeyValueBytes(this.cursor.key(), this.cursor.val()); 38 | 39 | // now we'll iterate to the next 40 | this.hasNext = this.cursor.next(); 41 | 42 | return kvb; 43 | } 44 | 45 | } -------------------------------------------------------------------------------- /bigmap-tokyocabinet/src/test/java/com/fizzed/bigmap/tokyocabinet/TokyoBigMapTest.java: -------------------------------------------------------------------------------- 1 | package com.fizzed.bigmap.tokyocabinet; 2 | 3 | import com.fizzed.bigmap.BigMap; 4 | import org.junit.jupiter.api.Disabled; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.condition.DisabledOnOs; 7 | import org.junit.jupiter.api.condition.OS; 8 | 9 | import java.io.IOException; 10 | import java.nio.file.Files; 11 | import java.nio.file.Paths; 12 | import java.util.Map; 13 | 14 | import static org.hamcrest.CoreMatchers.is; 15 | import static org.hamcrest.CoreMatchers.nullValue; 16 | import static org.hamcrest.MatcherAssert.assertThat; 17 | 18 | @DisabledOnOs({ OS.WINDOWS }) 19 | public class TokyoBigMapTest { 20 | 21 | @Test 22 | public void putGetWithStrings() { 23 | final Map map = new TokyoBigMapBuilder() 24 | .setScratchDirectory(Paths.get("target")) 25 | .setKeyType(String.class) 26 | .setValueType(String.class) 27 | .autoCloseObjects() 28 | .build(); 29 | 30 | map.put("a", "1"); 31 | 32 | assertThat(map.get("a"), is("1")); 33 | assertThat(map.size(), is(1)); 34 | assertThat(map.isEmpty(), is(false)); 35 | 36 | map.remove("a"); 37 | 38 | assertThat(map.get("a"), is(nullValue())); 39 | assertThat(map.size(), is(0)); 40 | assertThat(map.isEmpty(), is(true)); 41 | 42 | String removed = map.put("b", "2"); 43 | 44 | assertThat(removed, is(nullValue())); 45 | assertThat(map.size(), is(1)); 46 | 47 | String removed1 = map.put("b", "3"); 48 | 49 | assertThat(removed1, is("2")); 50 | assertThat(map.size(), is(1)); 51 | } 52 | 53 | @Test 54 | public void close() throws IOException { 55 | final BigMap map = new TokyoBigMapBuilder() 56 | .setScratchDirectory(Paths.get("target")) 57 | .setKeyType(String.class) 58 | .setValueType(String.class) 59 | .build(); 60 | 61 | map.put("a", "1"); 62 | 63 | map.close(); 64 | 65 | assertThat(map.isClosed(), is(true)); 66 | assertThat(Files.exists(map.getPath()), is(false)); 67 | } 68 | 69 | } -------------------------------------------------------------------------------- /bigmap-tokyocabinet/src/test/java/com/fizzed/bigmap/tokyocabinet/TokyoBigSetTest.java: -------------------------------------------------------------------------------- 1 | package com.fizzed.bigmap.tokyocabinet; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.junit.jupiter.api.condition.DisabledOnOs; 5 | import org.junit.jupiter.api.condition.OS; 6 | 7 | import java.nio.file.Paths; 8 | import java.util.Set; 9 | 10 | @DisabledOnOs({ OS.WINDOWS }) 11 | public class TokyoBigSetTest { 12 | 13 | @Test 14 | public void putGetWithStrings() { 15 | final Set set = new TokyoBigSetBuilder() 16 | .setScratchDirectory(Paths.get("target")) 17 | .setValueType(String.class) 18 | .autoCloseObjects() 19 | .build(); 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /blaze.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fizzed/bigmap/8389cfa26f238d8ae1c2ac236bea14c2d02ae4c5/blaze.jar -------------------------------------------------------------------------------- /buildx-results.txt: -------------------------------------------------------------------------------- 1 | Buildx Results 2 | -------------- 3 | Cross platform tests use the Buildx project: https://github.com/fizzed/buildx 4 | Commit: 3bf372e98ed892e440dfa1cdd859b8f128c0f03f 5 | Date: 2025-01-22T17:01:19.227687Z[UTC] 6 | 7 | linux-x64 success 8 | linux-arm64 success 9 | linux-riscv64 success 10 | linux_musl-x64 success 11 | macos-x64 success 12 | macos-arm64 success 13 | windows-x64 success 14 | windows-arm64 success 15 | freebsd-x64 success 16 | openbsd-x64 success 17 | 18 | --------------------------------------------------------------------------------