reformat code

This commit is contained in:
yhh
2020-07-28 16:25:20 +08:00
parent 5994f0bee3
commit 514572f291
103 changed files with 2896 additions and 2839 deletions

View File

@@ -4,43 +4,43 @@ module es {
*
* 它是由一个位向量实现的,但同样可以把它看成是一个非负整数的集合;集合中的每个整数由对应索引处的集合位表示。该结构的大小由集合中的最大整数决定。
*/
export class BitSet{
export class BitSet {
private static LONG_MASK: number = 0x3f;
private _bits: number[];
constructor(nbits: number = 64){
constructor(nbits: number = 64) {
let length = nbits >> 6;
if ((nbits & BitSet.LONG_MASK) != 0)
length ++;
length++;
this._bits = new Array(length);
}
public and(bs: BitSet){
public and(bs: BitSet) {
let max = Math.min(this._bits.length, bs._bits.length);
let i;
for (let i = 0; i < max; ++i)
this._bits[i] &= bs._bits[i];
while (i < this._bits.length)
this._bits[i ++] = 0;
this._bits[i++] = 0;
}
public andNot(bs: BitSet){
public andNot(bs: BitSet) {
let i = Math.min(this._bits.length, bs._bits.length);
while(--i >= 0)
while (--i >= 0)
this._bits[i] &= ~bs._bits[i];
}
public cardinality(): number{
public cardinality(): number {
let card = 0;
for (let i = this._bits.length - 1; i >= 0; i --){
for (let i = this._bits.length - 1; i >= 0; i--) {
let a = this._bits[i];
if (a == 0)
continue;
if (a == -1){
if (a == -1) {
card += 64;
continue;
}
@@ -56,26 +56,18 @@ module es {
return card;
}
public clear(pos?: number){
if (pos != undefined){
public clear(pos?: number) {
if (pos != undefined) {
let offset = pos >> 6;
this.ensure(offset);
this._bits[offset] &= ~(1 << pos);
}else{
for (let i = 0; i < this._bits.length; i ++)
} else {
for (let i = 0; i < this._bits.length; i++)
this._bits[i] = 0;
}
}
private ensure(lastElt: number){
if (lastElt >= this._bits.length){
let nd = new Number[lastElt + 1];
nd = this._bits.copyWithin(0, 0, this._bits.length);
this._bits = nd;
}
}
public get(pos: number): boolean{
public get(pos: number): boolean {
let offset = pos >> 6;
if (offset >= this._bits.length)
return false;
@@ -83,9 +75,9 @@ module es {
return (this._bits[offset] & (1 << pos)) != 0;
}
public intersects(set: BitSet){
public intersects(set: BitSet) {
let i = Math.min(this._bits.length, set._bits.length);
while (--i >= 0){
while (--i >= 0) {
if ((this._bits[i] & set._bits[i]) != 0)
return true;
}
@@ -93,8 +85,8 @@ module es {
return false;
}
public isEmpty(): boolean{
for (let i = this._bits.length - 1; i >= 0; i --){
public isEmpty(): boolean {
for (let i = this._bits.length - 1; i >= 0; i--) {
if (this._bits[i])
return false;
}
@@ -102,34 +94,42 @@ module es {
return true;
}
public nextSetBit(from: number){
public nextSetBit(from: number) {
let offset = from >> 6;
let mask = 1 << from;
while (offset < this._bits.length){
while (offset < this._bits.length) {
let h = this._bits[offset];
do {
if ((h & mask) != 0)
return from;
mask <<= 1;
from ++;
from++;
} while (mask != 0);
mask = 1;
offset ++;
offset++;
}
return -1;
}
public set(pos: number, value: boolean = true){
if (value){
public set(pos: number, value: boolean = true) {
if (value) {
let offset = pos >> 6;
this.ensure(offset);
this._bits[offset] |= 1 << pos;
}else{
} else {
this.clear(pos);
}
}
private ensure(lastElt: number) {
if (lastElt >= this._bits.length) {
let nd = new Number[lastElt + 1];
nd = this._bits.copyWithin(0, 0, this._bits.length);
this._bits = nd;
}
}
}
}