From aa7595938af40c2c19ec42d5a304ff3103710f73 Mon Sep 17 00:00:00 2001 From: qaate47 Date: Mon, 21 Mar 2022 16:36:05 +0100 Subject: [PATCH] fix HDTDiff certain size values close to 64 or 0 --- .../rdfhdt/hdt/compact/bitmap/Bitmap64.java | 3 + .../java/org/rdfhdt/hdt/hdt/impl/HDTImpl.java | 2 +- .../rdfhdt/hdt/hdtDiff/HdtDiffStaticTest.java | 18 +++++ .../test/resources/hdtDiff/example25-26.nt | 3 + .../src/test/resources/hdtDiff/example25.nt | 2 + .../src/test/resources/hdtDiff/example26.nt | 0 .../test/resources/hdtDiff/example27-28.nt | 66 +++++++++++++++++++ .../src/test/resources/hdtDiff/example27.nt | 66 +++++++++++++++++++ .../src/test/resources/hdtDiff/example28.nt | 0 9 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 hdt-java-core/src/test/resources/hdtDiff/example25-26.nt create mode 100644 hdt-java-core/src/test/resources/hdtDiff/example25.nt create mode 100644 hdt-java-core/src/test/resources/hdtDiff/example26.nt create mode 100644 hdt-java-core/src/test/resources/hdtDiff/example27-28.nt create mode 100644 hdt-java-core/src/test/resources/hdtDiff/example27.nt create mode 100644 hdt-java-core/src/test/resources/hdtDiff/example28.nt diff --git a/hdt-java-core/src/main/java/org/rdfhdt/hdt/compact/bitmap/Bitmap64.java b/hdt-java-core/src/main/java/org/rdfhdt/hdt/compact/bitmap/Bitmap64.java index 0a9f8df8..5c72935f 100644 --- a/hdt-java-core/src/main/java/org/rdfhdt/hdt/compact/bitmap/Bitmap64.java +++ b/hdt-java-core/src/main/java/org/rdfhdt/hdt/compact/bitmap/Bitmap64.java @@ -222,6 +222,9 @@ public long countOnes() { return 0; long acc = 0; int end = wordIndex(numbits); + if (end >= words.length) { + end = words.length - 1; + } for (int i = 0; i <= end; i++) acc += Long.bitCount(words[i]); return acc; diff --git a/hdt-java-core/src/main/java/org/rdfhdt/hdt/hdt/impl/HDTImpl.java b/hdt-java-core/src/main/java/org/rdfhdt/hdt/hdt/impl/HDTImpl.java index ecfdd010..9a8a509d 100644 --- a/hdt-java-core/src/main/java/org/rdfhdt/hdt/hdt/impl/HDTImpl.java +++ b/hdt-java-core/src/main/java/org/rdfhdt/hdt/hdt/impl/HDTImpl.java @@ -766,7 +766,7 @@ public void diffBit(String location, HDT hdt, Bitmap deleteBitmap, ProgressListe log.debug("Generating Triples..."); il.notifyProgress(40, "Generating Triples..."); // map the triples based on the new dictionary - BitmapTriplesIteratorMapDiff mapIter = new BitmapTriplesIteratorMapDiff(hdt, deleteBitmap, diff, iter.getCount()); + BitmapTriplesIteratorMapDiff mapIter = new BitmapTriplesIteratorMapDiff(hdt, deleteBitmap, diff, iter.getCount() + 1); BitmapTriples triples = new BitmapTriples(spec); triples.load(mapIter, listener); this.triples = triples; diff --git a/hdt-java-core/src/test/java/org/rdfhdt/hdt/hdtDiff/HdtDiffStaticTest.java b/hdt-java-core/src/test/java/org/rdfhdt/hdt/hdtDiff/HdtDiffStaticTest.java index 15b6d99c..e7e684aa 100644 --- a/hdt-java-core/src/test/java/org/rdfhdt/hdt/hdtDiff/HdtDiffStaticTest.java +++ b/hdt-java-core/src/test/java/org/rdfhdt/hdt/hdtDiff/HdtDiffStaticTest.java @@ -176,4 +176,22 @@ public void ntFilesDiffTest23M24() throws IOException, ParserException { "hdtDiff/example23-24.nt" ); } + + @Test + public void ntFilesDiffTest25M26() throws IOException, ParserException { + ntFilesDiffTest( + "hdtDiff/example25.nt", + "hdtDiff/example26.nt", + "hdtDiff/example25-26.nt" + ); + } + + @Test + public void ntFilesDiffTest27M28() throws IOException, ParserException { + ntFilesDiffTest( + "hdtDiff/example27.nt", + "hdtDiff/example28.nt", + "hdtDiff/example27-28.nt" + ); + } } diff --git a/hdt-java-core/src/test/resources/hdtDiff/example25-26.nt b/hdt-java-core/src/test/resources/hdtDiff/example25-26.nt new file mode 100644 index 00000000..aac4b978 --- /dev/null +++ b/hdt-java-core/src/test/resources/hdtDiff/example25-26.nt @@ -0,0 +1,3 @@ + . + + diff --git a/hdt-java-core/src/test/resources/hdtDiff/example25.nt b/hdt-java-core/src/test/resources/hdtDiff/example25.nt new file mode 100644 index 00000000..d3e9baf6 --- /dev/null +++ b/hdt-java-core/src/test/resources/hdtDiff/example25.nt @@ -0,0 +1,2 @@ + . + diff --git a/hdt-java-core/src/test/resources/hdtDiff/example26.nt b/hdt-java-core/src/test/resources/hdtDiff/example26.nt new file mode 100644 index 00000000..e69de29b diff --git a/hdt-java-core/src/test/resources/hdtDiff/example27-28.nt b/hdt-java-core/src/test/resources/hdtDiff/example27-28.nt new file mode 100644 index 00000000..8d477ac9 --- /dev/null +++ b/hdt-java-core/src/test/resources/hdtDiff/example27-28.nt @@ -0,0 +1,66 @@ + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + + diff --git a/hdt-java-core/src/test/resources/hdtDiff/example27.nt b/hdt-java-core/src/test/resources/hdtDiff/example27.nt new file mode 100644 index 00000000..8d477ac9 --- /dev/null +++ b/hdt-java-core/src/test/resources/hdtDiff/example27.nt @@ -0,0 +1,66 @@ + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + . + + diff --git a/hdt-java-core/src/test/resources/hdtDiff/example28.nt b/hdt-java-core/src/test/resources/hdtDiff/example28.nt new file mode 100644 index 00000000..e69de29b