]> gitweb.fperrin.net Git - Dictionary.git/commitdiff
More compact row list format.
authorReimar Döffinger <Reimar.Doeffinger@gmx.de>
Tue, 8 Dec 2015 05:41:00 +0000 (06:41 +0100)
committerReimar Döffinger <Reimar.Doeffinger@gmx.de>
Tue, 8 Dec 2015 05:41:00 +0000 (06:41 +0100)
src/com/hughes/android/dictionary/engine/HtmlEntry.java
src/com/hughes/android/dictionary/engine/Index.java
src/com/hughes/android/dictionary/engine/PairEntry.java
src/com/hughes/android/dictionary/engine/RowBase.java
src/com/hughes/android/dictionary/engine/TextEntry.java
src/com/hughes/android/dictionary/engine/TokenRow.java

index 7694fe9488ec7fee49bc28dfa44aa96cf5cacc88..573a96992d88e2f53e33c44206c9486e927d3f2a 100644 (file)
@@ -107,8 +107,8 @@ public class HtmlEntry extends AbstractEntry implements RAFSerializable<HtmlEntr
         boolean isExpanded = false;
 
         Row(final DataInput raf, final int thisRowIndex,
-                final Index index) throws IOException {
-            super(raf, thisRowIndex, index);
+                final Index index, int extra) throws IOException {
+            super(raf, thisRowIndex, index, extra);
         }
 
         Row(final int referenceIndex, final int thisRowIndex,
index cb29bac28ab989a40d6f12c7d647f77b39c974ab..63867081a6623aa60ec344ce33b8b3fea2d562df 100644 (file)
@@ -160,11 +160,7 @@ public final class Index implements RAFSerializable<Index> {
         }
         RAFList.write(raf, sortedIndexEntries, indexEntrySerializer, 16, true);
         new SerializableSerializer<Set<String>>().write(raf, stoplist);
-        UniformRAFList.write(raf, rows, new RowBase.Serializer(this), 5 /*
-                                                                                               * bytes
-                                                                                               * per
-                                                                                               * entry
-                                                                                               */);
+        UniformRAFList.write(raf, rows, new RowBase.Serializer(this), 3 /* bytes per entry */);
     }
 
     public void print(final PrintStream out) {
index ad9625caaf3ac7ec450ceecb788dee36bd54a9d5..645b94380ed08c8d09ca4d52ad187b1f57c2d80e 100644 (file)
@@ -99,8 +99,8 @@ public class PairEntry extends AbstractEntry implements RAFSerializable<PairEntr
     public static class Row extends RowBase {
 
         Row(final DataInput raf, final int thisRowIndex,
-                final Index index) throws IOException {
-            super(raf, thisRowIndex, index);
+                final Index index, int extra) throws IOException {
+            super(raf, thisRowIndex, index, extra);
         }
 
         Row(final int referenceIndex, final int thisRowIndex,
index 1cbf047ab8aab1eafb627f0c2b772cde900bc9d7..2930fa721f2754c0a1c48f780fd4a10d200c2160 100644 (file)
@@ -42,11 +42,11 @@ public abstract class RowBase extends IndexedObject {
      */
     private TokenRow tokenRow = null;
 
-    RowBase(final DataInput raf, final int thisRowIndex, final Index index)
+    RowBase(final DataInput raf, final int thisRowIndex, final Index index, final int extra)
             throws IOException {
         super(thisRowIndex);
         this.index = index;
-        this.referenceIndex = raf.readInt(); // what this points to.
+        this.referenceIndex = extra == -1 ? raf.readInt() : ((extra << 24) + raf.readUnsignedShort()); // what this points to.
     }
 
     public RowBase(final int referenceIndex, final int thisRowIndex, final Index index) {
@@ -149,32 +149,40 @@ public abstract class RowBase extends IndexedObject {
 
         @Override
         public RowBase read(DataInput raf, final int listIndex) throws IOException {
-            final byte rowType = raf.readByte();
+            int rowType = raf.readUnsignedByte();
+            int extra = -1;
+            if (rowType >= 0x20) {
+                extra = rowType & 0x1f;
+                rowType = (rowType >> 5) - 1;
+            }
             if (rowType == 0) {
-                return new PairEntry.Row(raf, listIndex, index);
+                return new PairEntry.Row(raf, listIndex, index, extra);
             } else if (rowType == 1 || rowType == 3) {
-                return new TokenRow(raf, listIndex, index, /* hasMainEntry */rowType == 1);
+                return new TokenRow(raf, listIndex, index, /* hasMainEntry */rowType == 1, extra);
             } else if (rowType == 2) {
-                return new TextEntry.Row(raf, listIndex, index);
+                return new TextEntry.Row(raf, listIndex, index, extra);
             } else if (rowType == 4) {
-                return new HtmlEntry.Row(raf, listIndex, index);
+                return new HtmlEntry.Row(raf, listIndex, index, extra);
             }
             throw new RuntimeException("Invalid rowType:" + rowType);
         }
 
         @Override
         public void write(DataOutput raf, RowBase t) throws IOException {
+            int type = 0;
             if (t instanceof PairEntry.Row) {
-                raf.writeByte(0);
+                type = 0;
             } else if (t instanceof TokenRow) {
                 final TokenRow tokenRow = (TokenRow) t;
-                raf.writeByte(tokenRow.hasMainEntry ? 1 : 3);
+                type = tokenRow.hasMainEntry ? 1 : 3;
             } else if (t instanceof TextEntry.Row) {
-                raf.writeByte(2);
+                type = 2;
             } else if (t instanceof HtmlEntry.Row) {
-                raf.writeByte(4);
+                type = 4;
             }
-            raf.writeInt(t.referenceIndex);
+            assert t.referenceIndex < (1 << 21);
+            raf.writeByte(((type + 1) << 5) + (t.referenceIndex >> 24));
+            raf.writeShort(t.referenceIndex);
         }
     }
 
index 187216fe0eb1993ea28ba1a652a5919039268c6f..449d83dcd2b63741bc01628778823d0de243de03 100644 (file)
@@ -76,8 +76,8 @@ public class TextEntry extends AbstractEntry implements RAFSerializable<TextEntr
     public static class Row extends RowBase {
 
         Row(final DataInput raf, final int thisRowIndex,
-                final Index index) throws IOException {
-            super(raf, thisRowIndex, index);
+                final Index index, int extra) throws IOException {
+            super(raf, thisRowIndex, index, extra);
         }
 
         public TextEntry getEntry() {
index 6ae67b9fb476fff0e52de4adbe9c5c843d8d36bc..367b207c77345c7921404a7d147584a6bd4d1002 100644 (file)
@@ -28,8 +28,8 @@ public class TokenRow extends RowBase {
     public final boolean hasMainEntry;
 
     TokenRow(final DataInput raf, final int thisRowIndex, final Index index,
-            final boolean hasMainEntry) throws IOException {
-        super(raf, thisRowIndex, index);
+            final boolean hasMainEntry, int extra) throws IOException {
+        super(raf, thisRowIndex, index, extra);
         this.hasMainEntry = hasMainEntry;
     }