Skip to content
This repository has been archived by the owner on Jul 16, 2022. It is now read-only.

Commit

Permalink
PDIC: coding styles
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Miura <miurahr@linux.com>
  • Loading branch information
miurahr committed Sep 28, 2021
1 parent aaa3d39 commit 3ebd621
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 23 deletions.
Expand Up @@ -5,8 +5,8 @@

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.Charset;

@SuppressWarnings("visibilitymodifier")
final class PdicHeader {
private final static int L_HEADERNAME = 100; // ヘッダー部文字列長
private final static int L_DICTITLE = 40; // 辞書タイトル名長
Expand Down
Expand Up @@ -17,7 +17,7 @@
import java.nio.charset.Charset;
import java.util.WeakHashMap;


@SuppressWarnings("membername")
class PdicInfo {
protected File m_file;
protected int m_bodyptr;
Expand All @@ -44,7 +44,8 @@ class PdicInfo {

private RandomAccessFile mSrcStream = null;

public PdicInfo(File file, int start, int size, int nindex, boolean blockbits, int blocksize) {
PdicInfo(final File file, final int start, final int size, final int nindex, final boolean blockbits,
final int blocksize) {
m_file = file;
m_start = start;
m_size = size;
Expand Down Expand Up @@ -121,6 +122,7 @@ public int searchIndexBlock(final String word) {

/**
* Read index blocks.
*
* @return true when successfully read block, otherwise false.
*/
public boolean readIndexBlock(String indexcache) {
Expand Down Expand Up @@ -487,7 +489,7 @@ public boolean searchWord() {
qtr++;

// 見出し語圧縮位置保存
while ((compbuff[complen++] = buff[qtr++]) != 0);
while ((compbuff[complen++] = buff[qtr++]) != 0) ;

// 見出し語の方が短ければ不一致
if (complen < wordlen) {
Expand Down Expand Up @@ -570,8 +572,9 @@ PdicElement getRecord() {
// 見出し語属性 skip
attr = buff[qtr++];

// 見出し語 skip
while (buff[qtr++] != 0);
while (buff[qtr++] != 0) {
// 見出し語 skip
}

// 訳語
if ((attr & 0x10) != 0) { // 拡張属性ありの時
Expand Down Expand Up @@ -658,7 +661,7 @@ public boolean hasMoreResult(boolean incrementptr) {
qtr++;

// 見出し語圧縮位置保存
while ((compbuff[complen++] = buff[qtr++]) != 0);
while ((compbuff[complen++] = buff[qtr++]) != 0) ;

// 見出し語の方が短ければ不一致
if (complen < wordlen) {
Expand Down
Expand Up @@ -20,7 +20,7 @@ class PdicInfoCache {
private byte[] mFixedBuffer;
private byte[] mSegmentData = null;

public PdicInfoCache(final RandomAccessFile file, final int start, final int size) {
PdicInfoCache(final RandomAccessFile file, final int start, final int size) {
mFile = file;
mStart = start;
mSize = size;
Expand Down Expand Up @@ -101,9 +101,9 @@ public int getShort(int ptr) {

if (address >= mBlockSize) {
address %= mBlockSize;
segmentdata = getSegment(segment++);
segmentdata = getSegment(segment);
}
b = segmentdata[address++];
b = segmentdata[address];
b &= 0xFF;
dat |= (b << 8);
}
Expand Down Expand Up @@ -137,9 +137,9 @@ public int getInt(int ptr) {
dat |= (b << 16);
if (address >= mBlockSize) {
address %= mBlockSize;
segmentdata = getSegment(segment++);
segmentdata = getSegment(segment);
}
b = segmentdata[address++];
b = segmentdata[address];
b &= 0x7F;
dat |= (b << 24);
}
Expand All @@ -161,7 +161,7 @@ private static int compareArrayAsUnsigned(byte[] aa, int pa, int la, byte[] ab,
}
}
if (lb > 0) {
short sb = ab[pb++];
short sb = ab[pb];
if (sb == 0x09) { // 比較対象の'\t'は'\0'とみなす
return 0;
}
Expand All @@ -170,12 +170,14 @@ private static int compareArrayAsUnsigned(byte[] aa, int pa, int la, byte[] ab,
return 0;
}

public int compare(byte[] aa, int pa, int la, int ptr, int len) {
public int compare(final byte[] aa, final int pa, final int la, final int ptr, final int len) {
int segment = ptr / mBlockSize;
int address = ptr % mBlockSize;
byte[] segmentdata = getSegment(segment++);

if (segmentdata == null) return -1;
if (segmentdata == null) {
return -1;
}

if (len < 0) {
return 1;
Expand All @@ -186,10 +188,7 @@ public int compare(byte[] aa, int pa, int la, int ptr, int len) {
return compareArrayAsUnsigned(aa, pa, la, segmentdata, address, len);
} else {
int lena = mBlockSize - address;
int leno = la;
if (la >= lena) {
leno = lena;
}
int leno = Math.min(la, lena);
int ret = compareArrayAsUnsigned(aa, pa, leno, segmentdata, address, lena);
PdicInfo.decodetoCharBuffer(CharsetICU.forNameICU("BOCU-1"), segmentdata, address, lena);
if (ret != 0) {
Expand All @@ -199,21 +198,30 @@ public int compare(byte[] aa, int pa, int la, int ptr, int len) {
return -1;
}
address = 0;
segmentdata = getSegment(segment++);
segmentdata = getSegment(segment);
PdicInfo.decodetoCharBuffer(CharsetICU.forNameICU("BOCU-1"), segmentdata, address, len - lena);
return compareArrayAsUnsigned(aa, pa + lena, la - lena, segmentdata, address, len - lena);
}
}


public boolean createIndex(int blockbits, int nindex, int[] indexPtr) {
/**
* Create index of words.
* @param blockbits
* @param nindex
* @param indexPtr
* @return true when success, otherwise false.
*/
public boolean createIndex(final int blockbits, final int nindex, final int[] indexPtr) {
// インデックスの先頭から見出し語のポインタを拾っていく
int blocksize = 64 * 1024;
int[] params = new int[]{0, 0, nindex, blocksize, blockbits, 1, 0};

int segment = 0;
mSegmentData = null;
while (countIndexWords(params, getSegment(segment++), indexPtr)) ;
boolean hasNext = true;
for (int i = 0; hasNext; i++) {
hasNext = countIndexWords(params, getSegment(i), indexPtr);
}
indexPtr[params[0]] = params[1] + blockbits; // ターミネータを入れておく
return true;
}
Expand Down

0 comments on commit 3ebd621

Please sign in to comment.