From c03ad90f3c2ed0b550bc8e1724b14aed63f87321 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Reimar=20D=C3=B6ffinger?= Date: Tue, 8 Dec 2015 06:41:00 +0100 Subject: [PATCH] More compact row list format. --- .../android/dictionary/engine/HtmlEntry.java | 4 +-- .../android/dictionary/engine/Index.java | 6 +--- .../android/dictionary/engine/PairEntry.java | 4 +-- .../android/dictionary/engine/RowBase.java | 32 ++++++++++++------- .../android/dictionary/engine/TextEntry.java | 4 +-- .../android/dictionary/engine/TokenRow.java | 4 +-- 6 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/com/hughes/android/dictionary/engine/HtmlEntry.java b/src/com/hughes/android/dictionary/engine/HtmlEntry.java index 7694fe9..573a969 100644 --- a/src/com/hughes/android/dictionary/engine/HtmlEntry.java +++ b/src/com/hughes/android/dictionary/engine/HtmlEntry.java @@ -107,8 +107,8 @@ public class HtmlEntry extends AbstractEntry implements RAFSerializable { } RAFList.write(raf, sortedIndexEntries, indexEntrySerializer, 16, true); new SerializableSerializer>().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) { diff --git a/src/com/hughes/android/dictionary/engine/PairEntry.java b/src/com/hughes/android/dictionary/engine/PairEntry.java index ad9625c..645b943 100644 --- a/src/com/hughes/android/dictionary/engine/PairEntry.java +++ b/src/com/hughes/android/dictionary/engine/PairEntry.java @@ -99,8 +99,8 @@ public class PairEntry extends AbstractEntry implements RAFSerializable= 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); } } diff --git a/src/com/hughes/android/dictionary/engine/TextEntry.java b/src/com/hughes/android/dictionary/engine/TextEntry.java index 187216f..449d83d 100644 --- a/src/com/hughes/android/dictionary/engine/TextEntry.java +++ b/src/com/hughes/android/dictionary/engine/TextEntry.java @@ -76,8 +76,8 @@ public class TextEntry extends AbstractEntry implements RAFSerializable