
283
9.5 서브클래스
}
}
subtract(set) {
for(let element of set) {
this.remove(element);
}
}
intersect(set) {
for(let element of this) {
if (!set.has(element)) {
this.remove(element);
}
}
}
}
/**
* BitSet
은
AbstractWritableSet
의
완전히
구현된
서브클래스이며
*
지정된
최대
크기보다
작은
양의
정수로
구성된
세트를
구현합니다
.
*
이
세트는
크기가
고정되어
있으며
아주
효율적입니다
.
*/
class BitSet extends AbstractWritableSet {
constructor(max) {
super();
this.max
=
max; //
저장할
수
있는
가장
큰
정수
this.n
=
0; //
세트에
들어있는
정수
개수
this.numBytes
=
Math.floor(max / 8) + 1; //
필요한
바이트
this.data
=
new Uint8Array(this.numBytes); //
실제
바이트
}
//
값이
이
세트의
멤버가
될
수
있는지
체크하는
내부
메서드
_
valid(x) { return Number.isInteger(x) && x ...