1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748
|
//start of TwoLevelHashSearch.java
//TEXT_STYLE:CODE=Shift_JIS(Japanese):RET_CODE=CRLF
/**
* TwoLevelHashSearch.java
*
* Copyright (C) 2002 Michel Ishizuka All rights reserved.
*
* ȉ̏ɓӂȂ\[XƃoCi`̍ĔzzƎgp
* ύX̗Lɂ炸B
*
* PD\[XR[h̍ĔzzɂĒ쌠\ ̏̃Xg
* щL̐ێȂĂ͂ȂȂB
*
* QDoCi`̍ĔzzɂĒ쌠\ ̏̃Xg
* щL̐gp ̑̔zz
* ܂ގɋLqȂȂȂB
*
* ̃\tgEFA͐Β˔ڂɂĖۏŒA̖
* IBłƂۏAilLƂۏɂƂǂ܂炸A
* Ȃ閾IшÎIȕۏȂB
* Β˔ڂ ̃\tgEFA̎gpɂ钼ړIAԐړIA
* IAȁAT^IȁA邢͕KRIȑQ(gpɂf[^
* AƖ̒f〈܂Ăv̈⎸Ai
* T[rX̓l邪AĂꂾɌ肳Ȃ
* Q)ɑāAȂ鎖Ԃ̌ƂȂƂĂA_̐
* C△ߎӔC܂ ȂӔC낤ƂAƂꂪs
* ŝׂ߂łƂĂA܂͂̂悤ȑQ̉\
* ĂƂĂ̐ӔCȂ̂ƂB
*/
package jp.gr.java_conf.dangan.util.lha;
//import classes and interfaces
import jp.gr.java_conf.dangan.io.Bits;
import jp.gr.java_conf.dangan.lang.reflect.Factory;
import jp.gr.java_conf.dangan.util.lha.HashShort;
import jp.gr.java_conf.dangan.util.lha.HashMethod;
import jp.gr.java_conf.dangan.util.lha.LzssOutputStream;
import jp.gr.java_conf.dangan.util.lha.LzssSearchMethod;
//import exceptions
import java.io.IOException;
import java.lang.NoSuchMethodException;
import java.lang.ClassNotFoundException;
import java.lang.InstantiationException;
import java.lang.reflect.InvocationTargetException;
import java.lang.Error;
import java.lang.NoSuchMethodError;
import java.lang.InstantiationError;
import java.lang.NoClassDefFoundError;
/**
* iKnbVƒPAXggčꂽ LzssSearchMethodB<br>
* <a href="http://search.ieice.org/2000/pdf/e83-a_12_2689.pdf">茓̘_</a>
* QlɂB
*
* <pre>
* -- revision history --
* $Log: TwoLevelHashSearch.java,v $
* Revision 1.1 2002/12/10 22:06:40 dangan
* [bug fix]
* searchAndPut() ōŋ߂̍ŒvȂoOCB
*
* Revision 1.0 2002/12/03 00:00:00 dangan
* first edition
* add to version control
*
* </pre>
*
* @author $Author: dangan $
* @version $Revision: 1.1 $
*/
public class TwoLevelHashSearch implements LzssSearchMethod{
//------------------------------------------------------------------
// instance field
//------------------------------------------------------------------
// LZSS parameter
//------------------------------------------------------------------
// private int DictionarySize
// private int MaxMatch
// private int Threshold
//------------------------------------------------------------------
/**
* LZSSTCYB
*/
private int DictionarySize;
/**
* LZSSkɎgplB
* ővB
*/
private int MaxMatch;
/**
* LZSSkɎgp臒lB
* v ̒lȏłAkR[ho͂B
*/
private int Threshold;
//------------------------------------------------------------------
// instance field
//------------------------------------------------------------------
// text buffer
//------------------------------------------------------------------
// private byte[] TextBuffer
// private int DictionaryLimit
//------------------------------------------------------------------
/**
* LZSSk{߂̃obt@B
* Ö͎A
* 㔼͈k{߂̃f[^̓obt@B
* LzssSearchMethod̎ł͓ǂݍ݂̂B
*/
private byte[] TextBuffer;
/**
* ̌EʒuB
* TextBufferO̎̈Ƀf[^ꍇ
* ̈ɂs̃f[^(Javał0)gp
* Ĉkŝ}~B
*/
private int DictionaryLimit;
//------------------------------------------------------------------
// instance field
//------------------------------------------------------------------
// primary hash
//------------------------------------------------------------------
// private HashMethod primaryHash
// private int[] primaryHashTable
// private int[] primaryCount
//------------------------------------------------------------------
/**
* iڂ̃nbV
*/
private HashMethod primaryHash;
/**
* iڂ̃nbVe[u
* Y͈iڂ̃nbVlAe iڂ̃nbVe[u index
*/
private int[] primaryHashTable;
/**
* iڂ̃nbVe[uɊ̃f[^p^
* o^Ă邩JEgĂB
*/
private int[] primaryCount;
//------------------------------------------------------------------
// instance field
//------------------------------------------------------------------
// secondary hash
//------------------------------------------------------------------
// private int[] secondaryHashRequires
// private int[] secondaryHashTable
// private int[] dummy
//------------------------------------------------------------------
/**
* iڂ̃nbVlZo邽߂ɕKvȃoCgB
*/
private int[] secondaryHashRequires;
/**
* iڂ̃nbVe[u
* Y iڂ̃nbVe[u̒l + iڂ̃nbVlA
* e TextBuffer ̃f[^p^̊Jnʒu
*/
private int[] secondaryHashTable;
/**
* slide() ̖ secondaryHashTable Ɠւ_~[zB
* g܂킵pB
*/
private int[] dummy;
//------------------------------------------------------------------
// instance field
//------------------------------------------------------------------
// cahined list
//------------------------------------------------------------------
// private int[] prev
//------------------------------------------------------------------
/**
* nbVlf[^p^Jnʒu
* PAXgB
*/
private int[] prev;
//------------------------------------------------------------------
// constructor
//------------------------------------------------------------------
// private TwoLevelHashSearch()
// public TwoLevelHashSearch( int DictionarySize, int MaxMatch,
// int Threshold, byte[] TextBuffer )
// public TwoLevelHashSearch( int DictionarySize, int MaxMatch,
// int Threshold, byte[] TextBuffer,
// String HashMethodClassName )
//------------------------------------------------------------------
/**
* ftHgRXgN^B
* gpsB
*/
private TwoLevelHashSearch(){ }
/**
* iKnbVgp LzssSearchMethod \zB<br>
* iڂ̃nbVɂ ftHĝ̂gpB<br>
*
* @param DictionarySize TCY
* @param MaxMatch őv
* @param Threshold kAk臒l
* @param TextBuffer LZSSk{߂̃obt@
*/
public TwoLevelHashSearch( int DictionarySize,
int MaxMatch,
int Threshold,
byte[] TextBuffer ){
this( DictionarySize,
MaxMatch,
Threshold,
TextBuffer,
HashShort.class.getName() );
}
/**
* iKnbVgp LzssSearchMethod \zB
*
* @param DictionarySize TCY
* @param MaxMatch őv
* @param Threshold kAk臒l
* @param TextBuffer LZSSk{߂̃obt@
* @param HashMethodClassName HashNX
*
* @exception NoClassDefFoundError
* HashMethodClassName ŗ^ꂽNXȂꍇB
* @exception InstantiationError
* HashMethodClassName ŗ^ꂽNX
* abstract class ł邽߃CX^XłȂꍇB
* @exception NoSuchMethodError
* HashMethodClassName ŗ^ꂽNX
* RXgN^ HashMethod( byte[] )ȂꍇB
*/
public TwoLevelHashSearch( int DictionarySize,
int MaxMatch,
int Threshold,
byte[] TextBuffer,
String HashMethodClassName ){
this.DictionarySize = DictionarySize;
this.MaxMatch = MaxMatch;
this.Threshold = Threshold;
this.TextBuffer = TextBuffer;
this.DictionaryLimit = this.DictionarySize;
try{
this.primaryHash = (HashMethod)Factory.createInstance(
HashMethodClassName,
new Object[]{ TextBuffer } );
}catch( ClassNotFoundException exception ){
throw new NoClassDefFoundError( exception.getMessage() );
}catch( InvocationTargetException exception ){
throw new Error( exception.getTargetException().getMessage() );
}catch( NoSuchMethodException exception ){
throw new NoSuchMethodError( exception.getMessage() );
}catch( InstantiationException exception ){
throw new InstantiationError( exception.getMessage() );
}
// nbVe[u
this.primaryHashTable = new int[ this.primaryHash.tableSize() ];
this.secondaryHashTable = new int[ ( this.primaryHash.tableSize()
+ this.DictionarySize / 4 ) ];
for( int i = 0 ; i < this.primaryHashTable.length ; i++ ){
this.primaryHashTable[i] = i;
this.secondaryHashTable[i] = -1;
}
// ̑̔z
// primaryCount secondaryHashRequires ͔zɃ[NAĂ鎖𗘗pB
this.primaryCount = new int[ this.primaryHash.tableSize() ];
this.secondaryHashRequires = new int[ this.primaryHash.tableSize() ];
this.dummy = new int[ this.secondaryHashTable.length ];
// AXg
this.prev = new int[ this.DictionarySize ];
for( int i = 0 ; i < this.prev.length ; i++ ){
this.prev[i] = -1;
}
}
//------------------------------------------------------------------
// method of jp.gr.java_conf.dangan.util.lha.LzssSearchMethod
//------------------------------------------------------------------
// public void put( int position )
// public int searchAndPut( int position )
// public int search( int position, int lastPutPos )
// public void slide( int slideWidth, int slideEnd )
// public int putRequires()
//------------------------------------------------------------------
/**
* position n܂f[^p^
* iKnbVƘAXg琬錟@\ɓo^B<br>
*
* @param position TextBuffer̃f[^p^̊Jnʒu
*/
public void put( int position ){
int phash = this.primaryHash.hash( position );
int base = this.primaryHashTable[ phash ];
int shash = this.secondaryHash( position, this.secondaryHashRequires[ phash ] );
this.primaryCount[ phash ]++;
this.prev[ position & ( this.DictionarySize - 1 ) ] =
this.secondaryHashTable[ base + shash ];
this.secondaryHashTable[ base + shash ] = position;
}
/**
* iKnbVƘAXg琬錟@\ɓo^ꂽ
* f[^p^ position n܂f[^p^
* Œ̈v̂A
* position n܂f[^p^
* iKnbVƘAXg琬錟@\ɓo^B<br>
*
* @param position TextBuffer̃f[^p^̊JnʒuB
*
* @return vꍇ
* LzssOutputStream.createSearchReturn
* ɂĐꂽvʒuƈv̏lA
* vȂꍇ
* LzssOutputStream.NOMATCHB
*
* @see LzssOutputStream#createSearchReturn(int,int)
* @see LzssOutputStream#NOMATCH
*/
public int searchAndPut( int position ){
int matchlen = this.Threshold - 1;
int matchpos = position;
int scanlimit = Math.max( this.DictionaryLimit,
position - this.DictionarySize );
int phash = this.primaryHash.hash( position );
int base = this.primaryHashTable[ phash ];
int requires = this.secondaryHashRequires[ phash ];
int shash = this.secondaryHash( position, requires );
int scanpos = this.secondaryHashTable[ base + shash ];
byte[] buf = this.TextBuffer;
int max = position + this.MaxMatch;
int s = 0;
int p = 0;
int len = 0;
//------------------------------------------------------------------
// iڂ̃nbVɂđIꂽAXg郋[v
while( scanlimit <= scanpos ){
if( buf[ scanpos + matchlen ] == buf[ position + matchlen ] ){
s = scanpos;
p = position;
while( buf[s] == buf[p] ){
s++;
p++;
if( max <= p ) break;
}
len = p - position;
if( matchlen < len ){
matchpos = scanpos;
matchlen = len;
if( max <= p ) break;
}
}
scanpos = this.prev[ scanpos & ( this.DictionarySize - 1 ) ];
}
//------------------------------------------------------------------
// iڂ̃nbVɂČIꂽAXgɈvꍇA
// iڂ̃nbVɓo^ĂSĂ̘AXg
int revbits = 1;
int loopend = requires - Math.max( 0, this.Threshold - this.primaryHash.hashRequires() );
int maxmatch = this.primaryHash.hashRequires() + requires - 1;
for( int i = 1, send = 4 ; i <= loopend && matchlen <= maxmatch ; i++, send <<= 2 ){
max += position + maxmatch;
while( revbits < send ){
scanpos = this.secondaryHashTable[ base + ( shash ^ revbits ) ];
while( scanlimit <= scanpos ){
if( buf[ scanpos ] == buf[ position ] ){
s = scanpos + 1;
p = position + 1;
while( buf[s] == buf[p] ){
s++;
p++;
if( max <= p ) break;
}
len = p - position;
if( matchlen < len
|| ( matchlen == len && matchpos < scanpos ) ){
matchpos = scanpos;
matchlen = len;
if( max <= p ){
scanlimit = scanpos;
break;
}
}
}
scanpos = this.prev[ scanpos & ( this.DictionarySize - 1 ) ];
}
revbits++;
}
maxmatch = this.primaryHash.hashRequires() + requires - i - 1;
}
//------------------------------------------------------------------
// iKnbVƘAXggp@\
// position n܂f[^p^o^B
this.primaryCount[ phash ]++;
this.prev[ position & ( this.DictionarySize - 1 ) ] =
this.secondaryHashTable[ base + shash ];
this.secondaryHashTable[ base + shash ] = position;
//------------------------------------------------------------------
// ŒvĂяoɕԂB
if( this.Threshold <= matchlen ){
return LzssOutputStream.createSearchReturn( matchlen, matchpos );
}else{
return LzssOutputStream.NOMATCH;
}
}
/**
* nbVƘAXggp@\ɓo^ꂽ
* f[^p^ position n܂f[^p^
* Œ̈v̂B<br>
*
* @param position TextBuffer̃f[^p^̊JnʒuB
* @param lastPutPos Ōɓo^f[^p^̊JnʒuB
*
* @return vꍇ
* LzssOutputStream.createSearchReturn
* ɂĐꂽvʒuƈv̏lA
* vȂꍇ
* LzssOutputStream.NOMATCHB
*
* @see LzssOutputStream#createSearchReturn(int,int)
* @see LzssOutputStream#NOMATCH
*/
public int search( int position, int lastPutPos ){
//------------------------------------------------------------------
// nbVƘAXgɂ錟@\ɓo^ĂȂ
// f[^p^PȒŌB
int matchlen = this.Threshold - 1;
int matchpos = position;
int scanpos = position - 1;
int scanlimit = Math.max( this.DictionaryLimit, lastPutPos );
byte[] buf = this.TextBuffer;
int max = Math.min( this.TextBuffer.length,
position + this.MaxMatch );
int s = 0;
int p = 0;
int len = 0;
while( scanlimit < scanpos ){
s = scanpos;
p = position;
while( buf[ s ] == buf[ p ] ){
s++;
p++;
if( max <= p ) break;
}
if( matchlen < len ){
matchpos = scanpos;
matchlen = len;
}
scanpos--;
}
//------------------------------------------------------------------
// iKnbVƘAXggp@\猟B
int phashRequires = this.primaryHash.hashRequires();
if( phashRequires < this.TextBuffer.length - position ){
int phash = this.primaryHash.hash( position );
int base = this.primaryHashTable[ phash ];
int requires = this.secondaryHashRequires[ phash ];
int shash;
int start;
if( phashRequires + requires < this.TextBuffer.length - position ){
shash = this.secondaryHash( position, requires );
start = 0;
}else{
int avail = this.TextBuffer.length - position - phashRequires;
shash = this.secondaryHash( position, avail ) << ( ( requires - avail ) * 2 );
start = requires - avail;
}
int revbits = 0;
int loopend = requires - Math.max( 0, this.Threshold - this.primaryHash.hashRequires() );
int maxmatch = this.MaxMatch;
//------------------------------------------------------------------
// iڂ̂ɓo^ĂAXgDx̏Ɍ郋[v
for( int i = start, send = ( 1 << ( i * 2 ) ) ; i <= requires ; i++, send <<= 2 ){
max += position + maxmatch;
while( revbits < send ){
scanpos = this.secondaryHashTable[ base + ( shash ^ revbits ) ];
while( scanlimit <= scanpos ){
if( buf[ scanpos ] == buf[ position ] ){
s = scanpos + 1;
p = position + 1;
while( buf[s] == buf[p] ){
s++;
p++;
if( max <= p ) break;
}
len = p - position;
if( matchlen < len
|| ( matchlen == len && matchpos < scanpos ) ){
matchpos = scanpos;
matchlen = len;
if( max <= p ){
scanlimit = scanpos;
break;
}
}
}
scanpos = this.prev[ scanpos & ( this.DictionarySize - 1 ) ];
}
revbits++;
}
maxmatch = this.primaryHash.hashRequires() + requires - i - 1;
}
}// if( phashRequires < this.TextBuffer.length - position )
//------------------------------------------------------------------
// ŒvĂяoɕԂB
if( this.Threshold <= matchlen ){
return LzssOutputStream.createSearchReturn( matchlen, matchpos );
}else{
return LzssOutputStream.NOMATCH;
}
}
/**
* TextBufferposition܂ł̃f[^
* OֈړہAɉ SearchMethod
* f[^ TextBuffer̃f[^ƖȂ悤
* Oֈړ鏈sB
*/
public void slide(){
//------------------------------------------------------------------
// DictionaryLimitXV
this.DictionaryLimit = Math.max( 0, this.DictionaryLimit - this.DictionarySize );
//------------------------------------------------------------------
// primaryCount ̒lɂ secondaryHashTable č\
int secondaryIndex = 0;
int dummyIndex = 0;
for( int i = 0 ; i < this.primaryHashTable.length ; i++ ){
this.primaryHashTable[i] = dummyIndex;
int bits = this.secondaryHashRequires[i] * 2;
if( 1 << ( 5 + bits ) <= this.primaryCount[i] ){
for( int j = 0 ; j < ( 1 << bits ) ; j++ ){
this.divide( dummyIndex, secondaryIndex, this.primaryHash.hashRequires() + this.secondaryHashRequires[i] );
dummyIndex += 4;
secondaryIndex += 1;
}
this.secondaryHashRequires[i]++;
}else if( 0 < bits && this.primaryCount[i] < ( 1 << ( 2 + bits ) ) ){
for( int j = 0 ; j < ( 1 << ( bits - 2 ) ) ; j++ ){
this.merge( dummyIndex, secondaryIndex );
dummyIndex += 1;
secondaryIndex += 4;
}
this.secondaryHashRequires[i]--;
}else{
for( int j = 0 ; j < ( 1 << bits ) ; j++ ){
int pos = this.secondaryHashTable[ secondaryIndex++ ] - this.DictionarySize;
this.dummy[ dummyIndex++ ] = ( 0 <= pos ? pos : -1 );
}
}
this.primaryCount[i] = 0;
}
int[] temp = this.secondaryHashTable;
this.secondaryHashTable = this.dummy;
this.dummy = temp;
//------------------------------------------------------------------
// AXgXV
for( int i = 0 ; i < this.prev.length ; i++ ){
int pos = this.prev[i] - this.DictionarySize;
this.prev[i] = ( 0 <= pos ? pos : -1 );
}
}
/**
* put() LzssSearchMethodɃf[^
* o^ƂɎgpf[^ʂB
* TwoLevelHashSearch ł́AŎgpĂ HashMethod ̎
* hash() ̂߂ɕKvƂf[^( HashMethod.hashRequires() ̖߂l )
* iڂ̃nbVɕKvȍő̃oCg𑫂̂ԂB
*
* @return iڂƓiڂ̃nbVɕKvȃoCg𑫂́B
*/
public int putRequires(){
return this.primaryHash.hashRequires()
+ Math.max( Bits.len( this.DictionarySize ) - 5, 0 ) / 2;
}
//------------------------------------------------------------------
// local method
//------------------------------------------------------------------
// secondary hash method
//------------------------------------------------------------------
// private int secondaryHash( int position, int hashRequires )
//------------------------------------------------------------------
/**
* iڂ̃nbV
*
* @param position TextBuffer̃f[^p^̊Jnʒu
* @param hashRequires iڂ̃nbVlZôɕKvȃoCg
*/
private int secondaryHash( int position, int hashRequires ){
int hash = 0;
int pos = position + this.primaryHash.hashRequires();
while( 0 < hashRequires-- ){
hash <<= 2;
hash |= this.TextBuffer[ pos++ ] & 0x03;
}
return hash;
}
//------------------------------------------------------------------
// local method
//------------------------------------------------------------------
// divide and merge chained list
//------------------------------------------------------------------
// private void divide( int dbase, int sbase, int divoff )
// private void merge( int dbase, int sbase )
//------------------------------------------------------------------
/**
* iڂ̃nbVe[uƘAXgB
*
* @param dbase this.dummy index
* @param sbase this.secondaryHashTable index
* @param divoff ʒu
*/
private void divide( int dbase, int sbase, int divoff ){
int limit = this.DictionarySize;
int position = this.secondaryHashTable[ sbase ];
int[] current = { -1, -1, -1, -1 };
//------------------------------------------------------------------
// AXgĂ[v
while( limit < position ){
int shash = this.TextBuffer[ position + divoff ] & 0x03;
if( 0 < current[ shash ] ){
this.prev[ current[ shash ] & ( this.DictionarySize - 1 ) ] = position;
}else{
this.dummy[ dbase + shash ] = position - this.DictionarySize;
}
current[ shash ] = position;
position = this.prev[ position & ( this.DictionarySize - 1 ) ];
}
//------------------------------------------------------------------
// AXg^[~l[gB
for( int i = 0 ; i < current.length ; i++ ){
if( 0 < current[ i ] ){
this.prev[ current[ i ] & ( this.DictionarySize - 1 ) ] = -1;
}else{
this.dummy[ dbase + i ] = -1;
}
}
}
/**
* iڂ̃nbVe[uƘAXg𑩂˂B
*
* @param dbase this.dummy index
* @param sbase this.secondaryHashTable index
*/
private void merge( int dbase, int sbase ){
int limit = this.DictionarySize;
int position = -1;
//------------------------------------------------------------------
// AXg𑩂˂Ă[v
while( true ){
int shash = 0;
int max = this.secondaryHashTable[ sbase ];
for( int i = 1 ; i < 4 ; i++ ){
if( max < this.secondaryHashTable[ sbase + i ] ){
shash = i;
max = this.secondaryHashTable[ sbase + i ];
}
}
if( limit < max ){
this.secondaryHashTable[ sbase + shash ] =
this.prev[ max & ( this.DictionarySize - 1 ) ];
if( 0 < position ){
this.prev[ position & ( this.DictionarySize - 1 ) ] = max;
}else{
this.dummy[ dbase ] = max - this.DictionarySize;
}
position = max;
}else{
break;
}
}
//------------------------------------------------------------------
// AXg^[~l[gB
if( 0 < position ){
this.prev[ position & ( this.DictionarySize - 1 ) ] = -1;
}else{
this.dummy[ dbase ] = -1;
}
}
}
//end of TwoLevelHashSearch.java
|