当前位置: 首页>>代码示例>>Java>>正文


Java AtomicLongArray.length方法代码示例

本文整理汇总了Java中java.util.concurrent.atomic.AtomicLongArray.length方法的典型用法代码示例。如果您正苦于以下问题:Java AtomicLongArray.length方法的具体用法?Java AtomicLongArray.length怎么用?Java AtomicLongArray.length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.atomic.AtomicLongArray的用法示例。


在下文中一共展示了AtomicLongArray.length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: write

import java.util.concurrent.atomic.AtomicLongArray; //导入方法依赖的package包/类
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType) throws IOException {
    SerializeWriter out = serializer.getWriter();
    if (object != null) {
        AtomicLongArray array = (AtomicLongArray) object;
        int len = array.length();
        out.append('[');
        for (int i = 0; i < len; i++) {
            long val = array.get(i);
            if (i != 0) {
                out.write(',');
            }
            out.writeLong(val);
        }
        out.append(']');
    } else if (out.isEnabled(SerializerFeature.WriteNullListAsEmpty)) {
        out.write("[]");
    } else {
        out.writeNull();
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:21,代码来源:AtomicLongArrayCodec.java

示例2: write

import java.util.concurrent.atomic.AtomicLongArray; //导入方法依赖的package包/类
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
    SerializeWriter out = serializer.getWriter();

    if (object == null) {
        if (out.isEnabled(SerializerFeature.WriteNullListAsEmpty)) {
            out.write("[]");
        } else {
            out.writeNull();
        }
        return;
    }

    AtomicLongArray array = (AtomicLongArray) object;
    int len = array.length();
    out.append('[');
    for (int i = 0; i < len; ++i) {
        long val = array.get(i);
        if (i != 0) {
            out.write(',');
        }
        out.writeLong(val);
    }
    out.append(']');
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:25,代码来源:AtomicLongArrayCodec.java

示例3: maxSetBit

import java.util.concurrent.atomic.AtomicLongArray; //导入方法依赖的package包/类
public long maxSetBit() {
    ThreadSafeBitSetSegments segments = this.segments.get();

    int segmentIdx = segments.numSegments() - 1;

    for(;segmentIdx >= 0; segmentIdx--) {
        AtomicLongArray segment = segments.getSegment(segmentIdx);
        for(int longIdx=segment.length() - 1; longIdx >= 0; longIdx--) {
            long l = segment.get(longIdx);
            if(l != 0)
                return (segmentIdx << log2SegmentSize) + (longIdx * 64) + (63 - Long.numberOfLeadingZeros(l));
        }
    }

    return -1;
}
 
开发者ID:Netflix,项目名称:hollow,代码行数:17,代码来源:ThreadSafeBitSet.java

示例4: growKeyArray

import java.util.concurrent.atomic.AtomicLongArray; //导入方法依赖的package包/类
/**
 * Grow the key array.  All of the values in the current array must be re-hashed and added to the new array.
 */
private void growKeyArray() {
    AtomicLongArray newKeys = emptyKeyArray(pointersAndOrdinals.length() * 2);

    long valuesToAdd[] = new long[size];

    int counter = 0;

    /// do not iterate over these values in the same order in which they appear in the hashed array.
    /// if we do so, we cause large clusters of collisions to appear (because we resolve collisions with linear probing).
    for(int i=0;i<pointersAndOrdinals.length();i++) {
        long key = pointersAndOrdinals.get(i);
        if(key != EMPTY_BUCKET_VALUE) {
            valuesToAdd[counter++] = key;
        }
    }

    Arrays.sort(valuesToAdd);

    populateNewHashArray(newKeys, valuesToAdd);

    /// 70% load factor
    sizeBeforeGrow = (newKeys.length() * 7) / 10;
    pointersAndOrdinals = newKeys;
}
 
开发者ID:Netflix,项目名称:hollow,代码行数:28,代码来源:ByteArrayOrdinalMap.java

示例5: equals

import java.util.concurrent.atomic.AtomicLongArray; //导入方法依赖的package包/类
/**
* Compares this object against the specified object.
* The result is {@code true} if and only if the argument is
* not {@code null} and is a {@code ConcurrentBitSet} object that has
* exactly the same set of bits set to {@code true} as this bit
* set. That is, for every nonnegative {@code int} index {@code k},
* <pre>((ConcurrentBitSet)obj).get(k) == this.get(k)</pre>
* must be true. The current sizes of the two bit sets are not compared.
*
* @param obj the object to compare with
* @return {@code true} if the objects are the same;
* {@code false} otherwise
* @see #size()
*/
@Override
public boolean equals(Object obj) {
  if (!(obj instanceof ConcurrentBitSet)) {
    return false;
  }
  if (this == obj) {
    return true;
  }

  ConcurrentBitSet set = (ConcurrentBitSet)obj;

  for (int i = 0; i < arrays.length(); i++) {
    AtomicLongArray array1 = arrays.get(i);
    AtomicLongArray array2 = set.arrays.get(i);
    if (array1 == null && array2 == null) continue;
    int size = array1 == null ? array2.length() : array1.length();
    for (int k=0; k<size;k++) {
      long word1 = array1 == null ? 0 : array1.get(k);
      long word2 = array2 == null ? 0 : array2.get(k);
      if (word1 != word2) return false;
    }
  }

  return true;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:40,代码来源:ConcurrentBitSet.java

示例6: main

import java.util.concurrent.atomic.AtomicLongArray; //导入方法依赖的package包/类
public static void main(String[] args) {
	long[] data = new long[] { 1, 22, 333, 4444, 55555, 0, 1, 22, 333 };
	AtomicLongArray ala = new AtomicLongArray(data);

	ExecutorService pool = Executors.newFixedThreadPool(3);

	for (int i = 0; i < 3; i++) {
		pool.execute(new Ato(ala));
	}

	pool.shutdown();

	for (int i = 0; i < ala.length(); i++) {
		System.out.print(ala.get(i) + " ");
	}
}
 
开发者ID:bdceo,项目名称:bd-codes,代码行数:17,代码来源:AtomicTest.java

示例7: toString

import java.util.concurrent.atomic.AtomicLongArray; //导入方法依赖的package包/类
/** Returns an {@link AtomicLongArray} array as a string, but does not print trailing zeroes.
 *
 * @param a an atomic array.
 * @return {@link Arrays#toString(long[])} of {@code a}, but without trailing zeroes.
 */
public static String toString(final AtomicLongArray a) {
	int i;
	for(i = a.length(); i-- != 0;) if (a.get(i) != 0) break;
	final long[] b = new long[i + 1];
	for(++i; i-- != 0;) b[i] = a.get(i);
	return Arrays.toString(b);
}
 
开发者ID:LAW-Unimi,项目名称:BUbiNG,代码行数:13,代码来源:StatsThread.java

示例8: cardinality

import java.util.concurrent.atomic.AtomicLongArray; //导入方法依赖的package包/类
/**
 * @return the number of bits which are set in this bit set.
 */
public int cardinality() {
    ThreadSafeBitSetSegments segments = this.segments.get();

    int numSetBits = 0;

    for(int i=0;i<segments.numSegments();i++) {
        AtomicLongArray segment = segments.getSegment(i);
        for(int j=0;j<segment.length();j++) {
            numSetBits += Long.bitCount(segment.get(j));
        }
    }

    return numSetBits;
}
 
开发者ID:Netflix,项目名称:hollow,代码行数:18,代码来源:ThreadSafeBitSet.java

示例9: clearAll

import java.util.concurrent.atomic.AtomicLongArray; //导入方法依赖的package包/类
/**
 * Clear all bits to 0.
 */
public void clearAll() {
    ThreadSafeBitSetSegments segments = this.segments.get();

    for(int i=0;i<segments.numSegments();i++) {
        AtomicLongArray segment = segments.getSegment(i);

        for(int j=0;j<segment.length();j++) {
            segment.set(j, 0L);
        }
    }
}
 
开发者ID:Netflix,项目名称:hollow,代码行数:15,代码来源:ThreadSafeBitSet.java

示例10: serializeBitsTo

import java.util.concurrent.atomic.AtomicLongArray; //导入方法依赖的package包/类
public void serializeBitsTo(DataOutputStream os) throws IOException {
    ThreadSafeBitSetSegments segments = this.segments.get();

    os.writeInt(segments.numSegments() * numLongsPerSegment);

    for(int i=0;i<segments.numSegments();i++) {
        AtomicLongArray arr = segments.getSegment(i);

        for(int j=0;j<arr.length();j++) {
            os.writeLong(arr.get(j));
        }
    }
}
 
开发者ID:Netflix,项目名称:hollow,代码行数:14,代码来源:ThreadSafeBitSet.java

示例11: populateNewHashArray

import java.util.concurrent.atomic.AtomicLongArray; //导入方法依赖的package包/类
/**
 * Hash all of the existing values specified by the keys in the supplied long array
 * into the supplied AtomicLongArray.
 */
private void populateNewHashArray(AtomicLongArray newKeys, long[] valuesToAdd) {
    int modBitmask = newKeys.length() - 1;

    for(int i=0;i<valuesToAdd.length;i++) {
        if(valuesToAdd[i] != EMPTY_BUCKET_VALUE) {
            int hash = rehashPreviouslyAddedData(valuesToAdd[i]);
            int bucket = hash & modBitmask;
            while(newKeys.get(bucket) != EMPTY_BUCKET_VALUE)
                bucket = (bucket + 1) & modBitmask;
            newKeys.set(bucket, valuesToAdd[i]);
        }
    }
}
 
开发者ID:Netflix,项目名称:hollow,代码行数:18,代码来源:ByteArrayOrdinalMap.java

示例12: emptyKeyArray

import java.util.concurrent.atomic.AtomicLongArray; //导入方法依赖的package包/类
/**
 * Create an AtomicLongArray of the specified size, each value in the array will be EMPTY_BUCKET_VALUE
 */
private AtomicLongArray emptyKeyArray(int size) {
    AtomicLongArray arr = new AtomicLongArray(size);
    for(int i=0;i<arr.length();i++) {
        arr.set(i, EMPTY_BUCKET_VALUE);
    }
    return arr;
}
 
开发者ID:Netflix,项目名称:hollow,代码行数:11,代码来源:ByteArrayOrdinalMap.java

示例13: write

import java.util.concurrent.atomic.AtomicLongArray; //导入方法依赖的package包/类
@Override
public List<Long> write(AtomicLongArray obj) {
    List<Long> list = new ArrayList<>();

    for (int i = 0; i < obj.length(); i++) {
        list.add(obj.get(i));
    }

    return list;
}
 
开发者ID:mkotb,项目名称:ConfigAPI,代码行数:11,代码来源:AtomicLongArrayAdapter.java

示例14: standardDeviationHistogram

import java.util.concurrent.atomic.AtomicLongArray; //导入方法依赖的package包/类
public static final double standardDeviationHistogram(AtomicLongArray histogram){
	long sum=max(1, sum(histogram));
	long sum2=0;
	for(int i=0; i<histogram.length(); i++){
		sum2+=(histogram.get(i)*i);
	}
	double avg=sum2/(double)sum;
	double sumdev2=0;
	for(int i=0; i<histogram.length(); i++){
		double dev=avg-i;
		double dev2=dev*dev;
		sumdev2+=(histogram.get(i)*dev2);
	}
	return Math.sqrt(sumdev2/sum);
}
 
开发者ID:abiswas-odu,项目名称:Disco,代码行数:16,代码来源:Tools.java

示例15: nextSetBit

import java.util.concurrent.atomic.AtomicLongArray; //导入方法依赖的package包/类
/**
* Returns the index of the first bit that is set to {@code true}
* that occurs on or after the specified starting index. If no such
* bit exists then {@code -1} is returned.
* <p/>
* <p>To iterate over the {@code true} bits,
* use the following loop:
* <p/>
* <pre> {@code
* for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i+1)) {
*     // operate on index i here
* }}</pre>
*
* @param fromIndex the index to start checking from (inclusive)
* @return the index of the next set bit, or {@code -1} if there
* is no such bit
* @throws IndexOutOfBoundsException if the specified index is negative
*/
public int nextSetBit(int fromIndex) {
  if (fromIndex < 0) {
    throw new IndexOutOfBoundsException("bitIndex < 0: " + fromIndex);
  }

  int arrayIndex;
  AtomicLongArray array = null;
  for (arrayIndex = arrayIndex(fromIndex); arrayIndex < arrays.length() && (array = arrays.get(arrayIndex)) == null; arrayIndex++);
  if (array == null) {
    return -1;
  }

  int wordIndexInArray = wordIndexInArray(fromIndex);

  long word = array.get(wordIndexInArray) & (WORD_MASK << fromIndex);

  while (true) {
    if (word != 0) {
      return ((1<<arrayIndex)-1 + wordIndexInArray) * BITS_PER_WORD + Long.numberOfTrailingZeros(word);
    }
    if (++wordIndexInArray == array.length()) {
      wordIndexInArray = 0;
      for (++arrayIndex; arrayIndex != arrays.length() && (array = arrays.get(arrayIndex)) == null; arrayIndex++);
      if (array == null) {
        return -1;
      }
    }

    word = array.get(wordIndexInArray);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:50,代码来源:ConcurrentBitSet.java


注:本文中的java.util.concurrent.atomic.AtomicLongArray.length方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。