@SuppressWarnings("unchecked") public OpenHashSet(int capacity, float loadFactor) { this.loadFactor = loadFactor; int c = Pow2.roundToPowerOfTwo(capacity); this.mask = c - 1; this.maxSize = (int)(loadFactor * c); this.keys = (T[])new Object[c]; }
@Test public void isPowerOf2() { for (int i = 1; i > 0; i *= 2) { assertTrue(Pow2.isPowerOfTwo(i)); } assertFalse(Pow2.isPowerOfTwo(3)); assertFalse(Pow2.isPowerOfTwo(5)); assertFalse(Pow2.isPowerOfTwo(6)); assertFalse(Pow2.isPowerOfTwo(7)); }
@SuppressWarnings("unchecked") public OpenHashSet(int capacity, float loadFactor) { this.loadFactor = loadFactor; int c = Pow2.roundToPowerOfTwo(capacity); this.mask = c - 1; this.maxSize = (int)(loadFactor * c); this.keys = (T[])new Object[c]; }
@SuppressWarnings("unchecked") public OpenHashSet(int capacity, float loadFactor) { this.loadFactor = loadFactor; int c = Pow2.roundToPowerOfTwo(capacity); this.mask = c - 1; this.maxSize = (int)(loadFactor * c); this.keys = (T[])new Object[c]; }
public AbstractSpscArrayQueue(int capacity) { super(Pow2.roundToPowerOfTwo(capacity)); this.mask = length() - 1; this.producerIndex = new AtomicLong(); this.consumerIndex = new AtomicLong(); lookAheadStep = Math.min(capacity / 4, MAX_LOOK_AHEAD_STEP); }
public AbstractSpscArrayQueue(int capacity) { super(Pow2.roundToPowerOfTwo(capacity)); this.mask = length() - 1; this.producerIndex = new AtomicLong(); this.consumerIndex = new AtomicLong(); lookAheadStep = Math.min(capacity / 4, MAX_LOOK_AHEAD_STEP); }
public AbstractSpscArrayQueue(int capacity) { super(Pow2.roundToPowerOfTwo(capacity)); this.mask = length() - 1; this.producerIndex = new AtomicLong(); this.consumerIndex = new AtomicLong(); lookAheadStep = Math.min(capacity / 4, MAX_LOOK_AHEAD_STEP); }
public AbstractSpscLinkedArrayQueue(final int bufferSize) { int p2capacity = Pow2.roundToPowerOfTwo(Math.max(8, bufferSize)); int mask = p2capacity - 1; AtomicReferenceArray<Object> buffer = new AtomicReferenceArray<Object>(p2capacity + 1); producerBuffer = buffer; producerMask = mask; adjustLookAheadStep(p2capacity); consumerBuffer = buffer; consumerMask = mask; producerLookAhead = mask - 1; // we know it's all empty to start with soProducerIndex(0L); }
public AbstractSpscLinkedArrayQueue(final int bufferSize) { int p2capacity = Pow2.roundToPowerOfTwo(Math.max(8, bufferSize)); int mask = p2capacity - 1; AtomicReferenceArray<Object> buffer = new AtomicReferenceArray<Object>(p2capacity + 1); producerBuffer = buffer; producerMask = mask; adjustLookAheadStep(p2capacity); consumerBuffer = buffer; consumerMask = mask; producerLookAhead = mask - 1; // we know it's all empty to start with soProducerIndex(0L); }
public AbstractSpscLinkedArrayQueue(final int bufferSize) { int p2capacity = Pow2.roundToPowerOfTwo(Math.max(8, bufferSize)); int mask = p2capacity - 1; AtomicReferenceArray<Object> buffer = new AtomicReferenceArray<Object>(p2capacity + 1); producerBuffer = buffer; producerMask = mask; adjustLookAheadStep(p2capacity); consumerBuffer = buffer; consumerMask = mask; producerLookAhead = mask - 1; // we know it's all empty to start with soProducerIndex(0L); }