private long getOffsetToNextBlock(byte[] block) { return readNumber(block,NUMBERS_IN_BLOCK); }
long getFirstNumber(long startOffset) throws IOException { byte[] block = getBlock(startOffset); return readNumber(block,0); }
List<Long> getNumbers(long startOffset) throws IOException { int slot; List<Long> numbers = new ArrayList<Long>(); for(;;) { byte[] block = getBlock(startOffset); for (slot=0;slot<NUMBERS_IN_BLOCK;slot++) { long el = readNumber(block,slot); if (el == 0L) { // end of the block, move to next one break; } numbers.add(new Long(el)); } long nextBlock = getOffsetToNextBlock(block); if (nextBlock == 0L) { return numbers; } startOffset = nextBlock; } }
void putFirst(long startOffset,long number) throws IOException { int slot; long offset = startOffset; long movedNumber = 0; for(;;) { byte[] block = getBlock(offset); for (slot=0;slot<NUMBERS_IN_BLOCK;slot++) { long el = readNumber(block,slot); if (offset == startOffset && slot == 0) { // first block if (number == el) { // already first element return; } movedNumber = el; writeNumber(offset,block,slot,number); } else if (el == 0L) { // end of the block, move to next one break; } else if (el == number) { // number is already in the list writeNumber(offset,block,slot,movedNumber); // replace number and return return; } } offset = getOffsetToNextBlock(block); if (offset == 0L) { System.out.println("Error - number not found at end"); return; } } }
long addNumber(long startOffset,long number) throws IOException { int slot; byte[] block = getBlock(startOffset); for (slot=0;slot<NUMBERS_IN_BLOCK;slot++) { long el = readNumber(block,slot); if (el == 0L) { writeNumber(startOffset,block,slot,number); return startOffset; } if (el == number) { // number is already in the list return startOffset; // do nothing } } long nextBlock = addBlock(); // create next blok block = getBlock(nextBlock); writeNumber(nextBlock,block,slot,startOffset); // put next block in front of old block writeNumber(nextBlock,block,0,number); // write number to first position in the new block return nextBlock; }
private long getOffsetToNextBlock(byte[] block) { return readNumber(block,NUMBERS_IN_BLOCK); }
private long getOffsetToNextBlock(byte[] block) { return readNumber(block,NUMBERS_IN_BLOCK); }
long getFirstNumber(long startOffset) throws IOException { byte[] block = getBlock(startOffset); return readNumber(block,0); }
long getFirstNumber(long startOffset) throws IOException { byte[] block = getBlock(startOffset); return readNumber(block,0); }
List getNumbers(long startOffset) throws IOException { int slot; List numbers = new ArrayList(); for(;;) { byte[] block = getBlock(startOffset); for (slot=0;slot<NUMBERS_IN_BLOCK;slot++) { long el = readNumber(block,slot); if (el == 0L) { // end of the block, move to next one break; } numbers.add(new Long(el)); } long nextBlock = getOffsetToNextBlock(block); if (nextBlock == 0L) { return numbers; } startOffset = nextBlock; } }
List<Long> getNumbers(long startOffset) throws IOException { int slot; List<Long> numbers = new ArrayList<Long>(); for(;;) { byte[] block = getBlock(startOffset); for (slot=0;slot<NUMBERS_IN_BLOCK;slot++) { long el = readNumber(block,slot); if (el == 0L) { // end of the block, move to next one break; } numbers.add(new Long(el)); } long nextBlock = getOffsetToNextBlock(block); if (nextBlock == 0L) { return numbers; } startOffset = nextBlock; } }
void putFirst(long startOffset,long number) throws IOException { int slot; long offset = startOffset; long movedNumber = 0; for(;;) { byte[] block = getBlock(offset); for (slot=0;slot<NUMBERS_IN_BLOCK;slot++) { long el = readNumber(block,slot); if (offset == startOffset && slot == 0) { // first block if (number == el) { // already first element return; } movedNumber = el; writeNumber(offset,block,slot,number); } else if (el == 0L) { // end of the block, move to next one break; } else if (el == number) { // number is already in the list writeNumber(offset,block,slot,movedNumber); // replace number and return return; } } offset = getOffsetToNextBlock(block); if (offset == 0L) { System.out.println("Error - number not found at end"); return; } } }
void putFirst(long startOffset,long number) throws IOException { int slot; long offset = startOffset; long movedNumber = 0; for(;;) { byte[] block = getBlock(offset); for (slot=0;slot<NUMBERS_IN_BLOCK;slot++) { long el = readNumber(block,slot); if (offset == startOffset && slot == 0) { // first block if (number == el) { // already first element return; } movedNumber = el; writeNumber(offset,block,slot,number); } else if (el == 0L) { // end of the block, move to next one break; } else if (el == number) { // number is already in the list writeNumber(offset,block,slot,movedNumber); // replace number and return return; } } offset = getOffsetToNextBlock(block); if (offset == 0L) { System.out.println("Error - number not found at end"); return; } } }
long addNumber(long startOffset,long number) throws IOException { int slot; byte[] block = getBlock(startOffset); for (slot=0;slot<NUMBERS_IN_BLOCK;slot++) { long el = readNumber(block,slot); if (el == 0L) { writeNumber(startOffset,block,slot,number); return startOffset; } if (el == number) { // number is already in the list return startOffset; // do nothing } } long nextBlock = addBlock(); // create next blok block = getBlock(nextBlock); writeNumber(nextBlock,block,slot,startOffset); // put next block in front of old block writeNumber(nextBlock,block,0,number); // write number to first position in the new block return nextBlock; }
long addNumber(long startOffset,long number) throws IOException { int slot; byte[] block = getBlock(startOffset); for (slot=0;slot<NUMBERS_IN_BLOCK;slot++) { long el = readNumber(block,slot); if (el == 0L) { writeNumber(startOffset,block,slot,number); return startOffset; } if (el == number) { // number is already in the list return startOffset; // do nothing } } long nextBlock = addBlock(); // create next blok block = getBlock(nextBlock); writeNumber(nextBlock,block,slot,startOffset); // put next block in front of old block writeNumber(nextBlock,block,0,number); // write number to first position in the new block return nextBlock; }