static int add(Block[] targets, Block[] addends, int from, int to, boolean inv) { int s = 0; for (int i = from; i <= to; i++) { Block addend = addends[i]; if (addend == null) { if (!inv) continue; } else if (addend.isFull && inv) continue; Block target = targets[i]; if (target == null) targets[i] = target = new Block(); else if (target.isFull) continue; s += add(target, addend, inv); } return s; }
static int subtract(Block[] targets, Block[] subtrahends, int from, int to, boolean inv) { int s = 0; for (int i = from; i <= to; i++) { Block target = targets[i]; if (target == null || (!target.isFull && target.bits == null)) continue; Block subtrahend = subtrahends[i]; if (subtrahend == null) { if (inv) { if (target.isFull) { s -= BLOCK_SIZE; } else { s -= count(target.bits, 0, BLOCK_SIZE - 1); } target.isFull = false; target.bits = null; target.shared = false; } } else { s += subtract(target, subtrahend, inv); } } return s; }
static void unify(BlockSet bs, Term term) { if (bs.isLarge) { term.type = Term.BITSET2; term.bitset2 = Block.toBitset2(bs.blocks); } else { term.type = Term.BITSET; term.bitset = bs.block0 == null ? emptyBlock0 : bs.block0; } term.inverse = !bs.positive; term.weight = bs.positive ? bs.weight : MAX_WEIGHT - bs.weight; }
int s = BLOCK_SIZE; if ((targetbits = target.bits) != null) { s -= count(targetbits, 0, BLOCK_SIZE - 1); int s = BLOCK_SIZE; if ((targetbits = target.bits) != null) { s -= count(targetbits, 0, BLOCK_SIZE - 1); int s = BLOCK_SIZE; if ((targetbits = target.bits) != null) { s -= count(targetbits, 0, BLOCK_SIZE - 1); target.bits = addbits; target.shared = true; return count(addbits, 0, BLOCK_SIZE - 1); } else { target.bits = targetbits = emptyBits(null); target.shared = false; return BlockSet.add(targetbits, addbits, 0, BLOCK_SIZE - 1, inv); if (target.shared) targetbits = copyBits(target); return BlockSet.add(targetbits, addbits, 0, BLOCK_SIZE - 1, inv);
final void setRange(char c1, char c2) { //System.out.println("["+this+"].setRange("+c1+","+c2+"):"); //if(c1>31 && c1<=126 && c2>31 && c2<=126) System.out.println("setRange('"+c1+"','"+c2+"'):"); //else System.out.println("setRange(["+Integer.toHexString(c1)+"],["+Integer.toHexString(c2)+"]):"); if (c2 >= 256 || isLarge) { int s = 0; if (!isLarge) { enableLargeMode(); } Block[] blocks = this.blocks; for (int c = c1; c <= c2; c++) { int i2 = (c >> 8) & 0xff; int i = c & 0xff; Block block = blocks[i2]; if (block == null) { blocks[i2] = block = new Block(); } if (block.set(i)) s++; } weight += s; } else { IntBitSet block0 = this.block0; if (block0 == null) { this.block0 = block0 = new IntBitSet(); } weight += set(block0, c1, c2); } }
final void setCategory(String c) { if (!isLarge) enableLargeMode(); Block[] catBits = Category.categories.get(c).blocks; weight += Block.add(this.blocks, catBits, 0, BLOCK_COUNT - 1, false); //System.out.println("["+this+"].setCategory("+c+"): weight="+weight); }
private void enableLargeMode() { if (isLarge) return; Block[] blocks = new Block[BLOCK_COUNT]; this.blocks = blocks; if (block0 != null) { blocks[0] = new Block(block0); } isLarge = true; }
final boolean set(int c) { //System.out.println("Block.add("+CharacterClass.stringValue2(toBitset2(targets))+","+CharacterClass.stringValue2(toBitset2(addends))+","+from*BLOCK_SIZE+","+to*BLOCK_SIZE+","+inv+"):"); if (isFull) return false; IntBitSet bits = this.bits; if (bits == null) { this.bits = bits = new IntBitSet(BLOCK_SIZE); shared = false; bits.set(c); return true; } if (bits.get(c)) return false; if (shared) bits = copyBits(this); bits.set(c); return true; }
private static int subtractImpl(BlockSet bs1, BlockSet bs2, boolean inv) { int s = 0; if (!bs1.isLarge && !bs2.isLarge && !inv) { IntBitSet bits1, bits2; if ((bits2 = bs2.block0) != null) { bits1 = bs1.block0; if (bits1 == null) return 0; s += subtract(bits1, bits2, false); } } else { if (!bs1.isLarge) bs1.enableLargeMode(); if (!bs2.isLarge) bs2.enableLargeMode(); s += Block.subtract(bs1.blocks, bs2.blocks, 0, BLOCK_COUNT - 1, inv); } return s; }
int s = BLOCK_SIZE; if ((targetbits = target.bits) != null) { s -= count(targetbits, 0, BLOCK_SIZE - 1); int s = BLOCK_SIZE; if ((targetbits = target.bits) != null) { s -= count(targetbits, 0, BLOCK_SIZE - 1); int s = BLOCK_SIZE; if ((targetbits = target.bits) != null) { s -= count(targetbits, 0, BLOCK_SIZE - 1); target.bits = addbits; target.shared = true; return count(addbits, 0, BLOCK_SIZE - 1); } else { target.bits = targetbits = emptyBits(null); target.shared = false; return BlockSet.add(targetbits, addbits, 0, BLOCK_SIZE - 1, inv); if (target.shared) targetbits = copyBits(target); return BlockSet.add(targetbits, addbits, 0, BLOCK_SIZE - 1, inv);
final void setRange(char c1, char c2) { //System.out.println("["+this+"].setRange("+c1+","+c2+"):"); //if(c1>31 && c1<=126 && c2>31 && c2<=126) System.out.println("setRange('"+c1+"','"+c2+"'):"); //else System.out.println("setRange(["+Integer.toHexString(c1)+"],["+Integer.toHexString(c2)+"]):"); if (c2 >= 256 || isLarge) { int s = 0; if (!isLarge) { enableLargeMode(); } Block[] blocks = this.blocks; for (int c = c1; c <= c2; c++) { int i2 = (c >> 8) & 0xff; int i = c & 0xff; Block block = blocks[i2]; if (block == null) { blocks[i2] = block = new Block(); } if (block.set(i)) s++; } weight += s; } else { IntBitSet block0 = this.block0; if (block0 == null) { this.block0 = block0 = new IntBitSet(BLOCK_SIZE); } weight += set(block0, c1, c2); } }
final void setCategory(String c) { if (!isLarge) enableLargeMode(); Block[] catBits = Category.categories.get(c).blocks; weight += Block.add(this.blocks, catBits, 0, BLOCK_COUNT - 1, false); //System.out.println("["+this+"].setCategory("+c+"): weight="+weight); }
private void enableLargeMode() { if (isLarge) return; Block[] blocks = new Block[BLOCK_COUNT]; this.blocks = blocks; if (block0 != null) { blocks[0] = new Block(block0); } isLarge = true; }
final boolean set(int c) { //System.out.println("Block.add("+CharacterClass.stringValue2(toBitset2(targets))+","+CharacterClass.stringValue2(toBitset2(addends))+","+from*BLOCK_SIZE+","+to*BLOCK_SIZE+","+inv+"):"); if (isFull) return false; IntBitSet bits = this.bits; if (bits == null) { this.bits = bits = new IntBitSet(); shared = false; bits.set(c); return true; } if (bits.get(c)) return false; if (shared) bits = copyBits(this); bits.set(c); return true; }
private static int subtractImpl(BlockSet bs1, BlockSet bs2, boolean inv) { int s = 0; if (!bs1.isLarge && !bs2.isLarge && !inv) { IntBitSet bits1, bits2; if ((bits2 = bs2.block0) != null) { bits1 = bs1.block0; if (bits1 == null) return 0; s += subtract(bits1, bits2, false); } } else { if (!bs1.isLarge) bs1.enableLargeMode(); if (!bs2.isLarge) bs2.enableLargeMode(); s += Block.subtract(bs1.blocks, bs2.blocks, 0, BLOCK_COUNT - 1, inv); } return s; }
static int add(Block[] targets, Block[] addends, int from, int to, boolean inv) { int s = 0; for (int i = from; i <= to; i++) { Block addend = addends[i]; if (addend == null) { if (!inv) continue; } else if (addend.isFull && inv) continue; Block target = targets[i]; if (target == null) targets[i] = target = new Block(); else if (target.isFull) continue; s += add(target, addend, inv); } return s; }
static int subtract(Block[] targets, Block[] subtrahends, int from, int to, boolean inv) { int s = 0; for (int i = from; i <= to; i++) { Block target = targets[i]; if (target == null || (!target.isFull && target.bits == null)) continue; Block subtrahend = subtrahends[i]; if (subtrahend == null) { if (inv) { if (target.isFull) { s -= BLOCK_SIZE; } else { s -= count(target.bits, 0, BLOCK_SIZE - 1); } target.isFull = false; target.bits = null; target.shared = false; } } else { s += subtract(target, subtrahend, inv); } } return s; }
private static int addImpl(BlockSet bs1, BlockSet bs2, boolean inv) { int s = 0; if (!bs1.isLarge && !bs2.isLarge && !inv) { if (bs2.block0 != null) { IntBitSet bits = bs1.block0; if (bits == null) bs1.block0 = bits = new IntBitSet(BLOCK_SIZE); s += add(bits, bs2.block0, 0, BLOCK_SIZE - 1, false); } } else { if (!bs1.isLarge) bs1.enableLargeMode(); if (!bs2.isLarge) bs2.enableLargeMode(); s += Block.add(bs1.blocks, bs2.blocks, 0, BLOCK_COUNT - 1, inv); } return s; }