java.util.concurrent.ConcurrentSkipListSet Java Examples
The following examples show how to use
java.util.concurrent.ConcurrentSkipListSet.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BinaryUtils.java From ignite with Apache License 2.0 | 6 votes |
/** * Attempts to create a new collection of the same known type. Will return null if collection type is unknown. * * @param col Collection. * @return New empty collection. */ public static <V> Collection<V> newKnownCollection(Object col) { Class<?> cls = col == null ? null : col.getClass(); if (cls == HashSet.class) return U.newHashSet(((Collection)col).size()); else if (cls == LinkedHashSet.class) return U.newLinkedHashSet(((Collection)col).size()); else if (!wrapTrees() && cls == TreeSet.class) return new TreeSet<>(((TreeSet<Object>)col).comparator()); else if (cls == ConcurrentSkipListSet.class) return new ConcurrentSkipListSet<>(((ConcurrentSkipListSet<Object>)col).comparator()); else if (cls == ArrayList.class) return new ArrayList<>(((Collection)col).size()); else if (cls == LinkedList.class) return new LinkedList<>(); else if (cls == SINGLETON_LIST_CLS) return new MutableSingletonList<>(); return null; }
Example #2
Source File: ConcurrentSkipListSetTest.java From j2objc with Apache License 2.0 | 6 votes |
public void testSubSetContents2() { ConcurrentSkipListSet set = set5(); SortedSet sm = set.subSet(two, three); assertEquals(1, sm.size()); assertEquals(two, sm.first()); assertEquals(two, sm.last()); assertFalse(sm.contains(one)); assertTrue(sm.contains(two)); assertFalse(sm.contains(three)); assertFalse(sm.contains(four)); assertFalse(sm.contains(five)); Iterator i = sm.iterator(); Object k; k = (Integer)(i.next()); assertEquals(two, k); assertFalse(i.hasNext()); Iterator j = sm.iterator(); j.next(); j.remove(); assertFalse(set.contains(two)); assertEquals(4, set.size()); assertEquals(0, sm.size()); assertTrue(sm.isEmpty()); assertFalse(sm.remove(three)); assertEquals(4, set.size()); }
Example #3
Source File: ConcurrentSkipListSetTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * headSet returns set with keys in requested range */ public void testHeadSetContents() { ConcurrentSkipListSet set = set5(); SortedSet sm = set.headSet(four); assertTrue(sm.contains(one)); assertTrue(sm.contains(two)); assertTrue(sm.contains(three)); assertFalse(sm.contains(four)); assertFalse(sm.contains(five)); Iterator i = sm.iterator(); Object k; k = (Integer)(i.next()); assertEquals(one, k); k = (Integer)(i.next()); assertEquals(two, k); k = (Integer)(i.next()); assertEquals(three, k); assertFalse(i.hasNext()); sm.clear(); assertTrue(sm.isEmpty()); assertEquals(2, set.size()); assertEquals(four, set.first()); }
Example #4
Source File: BuildJobSubmitter.java From kylin-on-parquet-v2 with Apache License 2.0 | 6 votes |
void doRun() { checkTimes++; logger.debug("\n========================================================================= {}", checkTimes); dumpSegmentBuildJobCheckList(); coordinator.getStreamMetadataStore().reportStat(); List<SegmentJobBuildInfo> successJobs = traceEarliestSegmentBuildJob(); for (SegmentJobBuildInfo successJob : successJobs) { ConcurrentSkipListSet<SegmentJobBuildInfo> submittedBuildJobs = segmentBuildJobCheckList .get(successJob.cubeName); logger.trace("Remove job {} from check list.", successJob.jobID); submittedBuildJobs.remove(successJob); } findSegmentReadyToBuild(); if (checkTimes % 100 == 1) { logger.info("Force traverse all cubes periodically."); for (StreamingCubeInfo cubeInfo : coordinator.getEnableStreamingCubes()) { List<String> segmentList = checkSegmentBuildJobFromMetadata(cubeInfo.getCubeName()); for (String segmentName : segmentList) { submitSegmentBuildJob(cubeInfo.getCubeName(), segmentName); } } } }
Example #5
Source File: ConcurrentSkipListSetTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Subsets of subsets subdivide correctly */ public void testRecursiveSubSets() throws Exception { int setSize = expensiveTests ? 1000 : 100; Class cl = ConcurrentSkipListSet.class; NavigableSet<Integer> set = newSet(cl); BitSet bs = new BitSet(setSize); populate(set, setSize, bs); check(set, 0, setSize - 1, true, bs); check(set.descendingSet(), 0, setSize - 1, false, bs); mutateSet(set, 0, setSize - 1, bs); check(set, 0, setSize - 1, true, bs); check(set.descendingSet(), 0, setSize - 1, false, bs); bashSubSet(set.subSet(0, true, setSize, false), 0, setSize - 1, true, bs); }
Example #6
Source File: MeanShift.java From clust4j with Apache License 2.0 | 6 votes |
@Override protected ConcurrentSkipListSet<MeanShiftSeed> compute() { if(high - low <= 1) { // generally should equal one... return reduce(chunks.get(low)); } else { int mid = this.low + (this.high - this.low) / 2; ParallelSeedExecutor left = new ParallelSeedExecutor(this, low, mid); ParallelSeedExecutor right = new ParallelSeedExecutor(this, mid, high); left.fork(); right.compute(); left.join(); return computedSeeds; } }
Example #7
Source File: TableCacheImpl.java From hadoop-ozone with Apache License 2.0 | 6 votes |
public TableCacheImpl(CacheCleanupPolicy cleanupPolicy) { // As for full table cache only we need elements to be inserted in sorted // manner, so that list will be easy. For other we can go with Hash map. if (cleanupPolicy == CacheCleanupPolicy.NEVER) { cache = new ConcurrentSkipListMap<>(); } else { cache = new ConcurrentHashMap<>(); } epochEntries = new ConcurrentSkipListSet<>(); // Created a singleThreadExecutor, so one cleanup will be running at a // time. ThreadFactory build = new ThreadFactoryBuilder().setDaemon(true) .setNameFormat("PartialTableCache Cleanup Thread - %d").build(); executorService = Executors.newSingleThreadExecutor(build); this.cleanupPolicy = cleanupPolicy; }
Example #8
Source File: StreamsRegistryStorage.java From apicurio-registry with Apache License 2.0 | 6 votes |
@Override public Set<String> getArtifactIds(Integer limit) { Set<String> ids = new ConcurrentSkipListSet<>(); try (Stream<String> stream = storageStore.allKeys()) { // exists can be costly ... if (limit != null) { stream.filter(this::exists) .limit(limit) .forEach(ids::add); } else { stream.filter(this::exists).forEach(ids::add); } } ids.remove(GLOBAL_RULES_ID); return ids; }
Example #9
Source File: BoundedPriorityQueueSet.java From neoscada with Eclipse Public License 1.0 | 5 votes |
public BoundedPriorityQueueSet ( final int capacity, final Comparator<E> comparator ) { if ( capacity < 1 ) { throw new IllegalArgumentException (); } this.capacity = capacity; this.internalSet = new ConcurrentSkipListSet<E> ( comparator ); }
Example #10
Source File: Chapter07Concurrency02.java From Java-9-Cookbook with MIT License | 5 votes |
private static void demo3_NavigableSet() { System.out.println(); System.out.println("***** TreeSet API:"); demoNavigableSetApi(new TreeSet<>(Arrays.asList(0, 1, 2, 3))); System.out.println(); System.out.println("***** ConcurrentSkipListSet API:"); demoNavigableSetApi(new ConcurrentSkipListSet<>(Arrays.asList(0, 1, 2, 3))); System.out.println(); System.out.println("***** TreeSet set.remove(2):"); demoNavigableSetRemove(new TreeSet<>(Arrays.asList(0, 1, 2, 3))); System.out.println(); System.out.println("***** ConcurrentSkipListSet set.remove(2):"); demoNavigableSetRemove(new ConcurrentSkipListSet<>(Arrays.asList(0, 1, 2, 3))); System.out.println(); System.out.println("***** TreeSet iter.remove():"); demoNavigableSetIterRemove(new TreeSet<>(Arrays.asList(0, 1, 2, 3))); System.out.println(); System.out.println("***** ConcurrentSkipListSet iter.remove():"); demoNavigableSetIterRemove(new ConcurrentSkipListSet<>(Arrays.asList(0, 1, 2, 3))); System.out.println(); System.out.println("***** TreeSet set.add():"); demoNavigableSetAdd(new TreeSet<>(Arrays.asList(0, 1, 2, 3))); System.out.println(); System.out.println("***** ConcurrentSkipListSet set.add():"); demoNavigableSetAdd(new ConcurrentSkipListSet<>(Arrays.asList(0, 1, 2, 3))); }
Example #11
Source File: ConcurrentSkipListSetTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * addAll of a collection with any null elements throws NPE after * possibly adding some elements */ public void testAddAll3() { ConcurrentSkipListSet q = new ConcurrentSkipListSet(); Integer[] ints = new Integer[SIZE]; for (int i = 0; i < SIZE - 1; ++i) ints[i] = new Integer(i); try { q.addAll(Arrays.asList(ints)); shouldThrow(); } catch (NullPointerException success) {} }
Example #12
Source File: ConcurrentSkipListSetTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * Returns a new set of first 5 ints. */ private ConcurrentSkipListSet set5() { ConcurrentSkipListSet q = new ConcurrentSkipListSet(); assertTrue(q.isEmpty()); q.add(one); q.add(two); q.add(three); q.add(four); q.add(five); assertEquals(5, q.size()); return q; }
Example #13
Source File: ConcurrentSkipListSetTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * removeAll(c) removes only those elements of c and reports true if changed */ public void testRemoveAll() { for (int i = 1; i < SIZE; ++i) { ConcurrentSkipListSet q = populatedSet(SIZE); ConcurrentSkipListSet p = populatedSet(i); assertTrue(q.removeAll(p)); assertEquals(SIZE - i, q.size()); for (int j = 0; j < i; ++j) { Integer x = (Integer)(p.pollFirst()); assertFalse(q.contains(x)); } } }
Example #14
Source File: ConcurrentSkipListSetTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * addAll of a collection with null elements throws NPE */ public void testAddAll2() { ConcurrentSkipListSet q = new ConcurrentSkipListSet(); Integer[] ints = new Integer[SIZE]; try { q.addAll(Arrays.asList(ints)); shouldThrow(); } catch (NullPointerException success) {} }
Example #15
Source File: LruCache.java From onos with Apache License 2.0 | 5 votes |
/** * Returns the last (newest) value of this LRU cache. * * @return last (newest) value of this LRU cache */ public synchronized T getLastValue() { // Get all keys sorted SortedSet<Integer> keys = new ConcurrentSkipListSet<Integer>(this.keySet()); // Return the value that corresponds to the last key return this.get(keys.last()); }
Example #16
Source File: ConcurrentSkipListSetTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Initializing from null Collection throws NPE */ public void testConstructor3() { try { new ConcurrentSkipListSet((Collection)null); shouldThrow(); } catch (NullPointerException success) {} }
Example #17
Source File: RendezvousHash.java From RendezvousHash with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Creates a new RendezvousHash with a starting set of nodes provided by init. The funnels will be used when generating the hash that combines the nodes and * keys. The hasher specifies the hashing algorithm to use. */ public RendezvousHash(HashFunction hasher, Funnel<K> keyFunnel, Funnel<N> nodeFunnel, Collection<N> init) { if (hasher == null) throw new NullPointerException("hasher"); if (keyFunnel == null) throw new NullPointerException("keyFunnel"); if (nodeFunnel == null) throw new NullPointerException("nodeFunnel"); if (init == null) throw new NullPointerException("init"); this.hasher = hasher; this.keyFunnel = keyFunnel; this.nodeFunnel = nodeFunnel; this.ordered = new ConcurrentSkipListSet<N>(init); }
Example #18
Source File: ConcurrentSkipListSetTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * The comparator used in constructor is used */ public void testConstructor7() { MyReverseComparator cmp = new MyReverseComparator(); ConcurrentSkipListSet q = new ConcurrentSkipListSet(cmp); assertEquals(cmp, q.comparator()); Integer[] ints = new Integer[SIZE]; for (int i = 0; i < SIZE; ++i) ints[i] = new Integer(i); q.addAll(Arrays.asList(ints)); for (int i = SIZE - 1; i >= 0; --i) assertEquals(ints[i], q.pollFirst()); }
Example #19
Source File: TinHandler.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
private double getMedianFromSet( final ConcurrentSkipListSet<Double> set ) { double threshold = 0; int halfNum = set.size() / 2; int count = 0; for( double value : set ) { if (count == halfNum) { threshold = value; break; } count++; } return threshold; }
Example #20
Source File: ConcurrentSkipListSetTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * addAll is idempotent */ public void testAddAll_idempotent() throws Exception { Set x = populatedSet(SIZE); Set y = new ConcurrentSkipListSet(x); y.addAll(x); assertEquals(x, y); assertEquals(y, x); }
Example #21
Source File: Chapter07Concurrency02.java From Java-11-Cookbook-Second-Edition with MIT License | 5 votes |
private static void demo3_NavigableSet() { System.out.println(); System.out.println("***** TreeSet API:"); demoNavigableSetApi(new TreeSet<>(Arrays.asList(0, 1, 2, 3))); System.out.println(); System.out.println("***** ConcurrentSkipListSet API:"); demoNavigableSetApi(new ConcurrentSkipListSet<>(Arrays.asList(0, 1, 2, 3))); System.out.println(); System.out.println("***** TreeSet set.remove(2):"); demoNavigableSetRemove(new TreeSet<>(Arrays.asList(0, 1, 2, 3))); System.out.println(); System.out.println("***** ConcurrentSkipListSet set.remove(2):"); demoNavigableSetRemove(new ConcurrentSkipListSet<>(Arrays.asList(0, 1, 2, 3))); System.out.println(); System.out.println("***** TreeSet iter.remove():"); demoNavigableSetIterRemove(new TreeSet<>(Arrays.asList(0, 1, 2, 3))); System.out.println(); System.out.println("***** ConcurrentSkipListSet iter.remove():"); demoNavigableSetIterRemove(new ConcurrentSkipListSet<>(Arrays.asList(0, 1, 2, 3))); System.out.println(); System.out.println("***** TreeSet set.add():"); demoNavigableSetAdd(new TreeSet<>(Arrays.asList(0, 1, 2, 3))); System.out.println(); System.out.println("***** ConcurrentSkipListSet set.add():"); demoNavigableSetAdd(new ConcurrentSkipListSet<>(Arrays.asList(0, 1, 2, 3))); }
Example #22
Source File: TestByteBuffer.java From titan1withtp3.1 with Apache License 2.0 | 5 votes |
private static long testByte() { LongObjectMap<ConcurrentSkipListSet<ByteEntry>> tx = new LongObjectHashMap<ConcurrentSkipListSet<ByteEntry>>(NUM); for (int i = 0; i < NUM; i++) { tx.put(i, new ConcurrentSkipListSet<ByteEntry>()); } for (int i = 0; i < NUM; i++) { for (int j = 0; j < NUM; j++) { if (i == j) continue; if (Math.random() < FRACTION) { ByteBuffer key = ByteBuffer.allocate(16); key.putLong(5).putLong(j).flip(); ByteBuffer value = ByteBuffer.allocate(4); value.putInt(random.nextInt(ROUNDSIZE)).flip(); tx.get(i).add(new ByteEntry(key, value)); } } } long time = System.currentTimeMillis(); long sum = 0; for (int t = 0; t < TRIALS; t++) { for (int i = 0; i < NUM; i++) { for (Vertex v : (new ByteVertex(i, tx)).getNeighbors(0)) { sum += v.getId(); } } } time = System.currentTimeMillis() - time; return time; }
Example #23
Source File: JaccardTextSimilarity.java From similarity with Apache License 2.0 | 5 votes |
/** * 判定相似度的方式:Jaccard相似性系数 * @param words1 词列表1 * @param words2 词列表2 * @return 相似度分值 */ @Override protected double getSimilarityImpl(List<Word> words1, List<Word> words2) { if (words1.isEmpty() && words2.isEmpty()) { return 1.0; } //HashSet的contains性能要大于ArrayList的contains Set<Word> words2Set = new HashSet<>(); words2Set.addAll(words2); //求交集 Set<String> intersectionSet = new ConcurrentSkipListSet<>(); words1.parallelStream().forEach(word -> { if (words2Set.contains(word)) { intersectionSet.add(word.getName()); } }); //交集的大小 int intersectionSize = intersectionSet.size(); //求并集 Set<String> unionSet = new HashSet<>(); words1.forEach(word -> unionSet.add(word.getName())); words2.forEach(word -> unionSet.add(word.getName())); //并集的大小 int unionSize = unionSet.size(); //相似度分值 double score = intersectionSize / (double) unionSize; if (LOGGER.isDebugEnabled()) { LOGGER.debug("交集的大小:" + intersectionSize); LOGGER.debug("并集的大小:" + unionSize); LOGGER.debug("相似度分值=" + intersectionSize + "/(double)" + unionSize + "=" + score); } return score; }
Example #24
Source File: ConcurrentSkipListSetTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * add(null) throws NPE */ public void testAddNull() { ConcurrentSkipListSet q = new ConcurrentSkipListSet(); try { q.add(null); shouldThrow(); } catch (NullPointerException success) {} }
Example #25
Source File: ConcurrentSkipListSetTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * Set contains all elements of collection used to initialize */ public void testConstructor6() { Integer[] ints = new Integer[SIZE]; for (int i = 0; i < SIZE; ++i) ints[i] = new Integer(i); ConcurrentSkipListSet q = new ConcurrentSkipListSet(Arrays.asList(ints)); for (int i = 0; i < SIZE; ++i) assertEquals(ints[i], q.pollFirst()); }
Example #26
Source File: ChainBuildingMessageHandler.java From protect with MIT License | 5 votes |
private synchronized void recordVote(final long messagePosition, final SignedMessage bftMessage, final int voterId) { // Get the map for this position this.votes.putIfAbsent(messagePosition, new ConcurrentHashMap<SignedMessage, Set<Integer>>()); final ConcurrentMap<SignedMessage, Set<Integer>> positionVotes = this.votes.get(messagePosition); // Get the set of votes for this message positionVotes.putIfAbsent(bftMessage, new ConcurrentSkipListSet<>()); final Set<Integer> messageVotes = positionVotes.get(bftMessage); messageVotes.add(voterId); // Check if Opt-BFT quorum has been met if (messageVotes.size() == this.optQuorum) { // System.err.println("QUORUM MET, added " + (optChain.size() + 1) + "th message // to Opt-BFT Chain: " /*+ bftMessage*/); synchronized (this.optChain) { System.out.println("Certified message #" + (messagePosition + 1) + " is available."); if (this.optChain.putIfAbsent(messagePosition + 1, bftMessage) == null) { // Increment contiguousOptMessages if we are contiguous while (this.optChain.containsKey(new Long(contiguousOptMessages.get() + 1))) { contiguousOptMessages.incrementAndGet(); } final String msgFileName = String.format("%08d", messagePosition + 1) + ".msg"; final File messageFile = new File(this.certifiedMessageFolder, msgFileName); try { AtomicFileOperations.atomicWriteSignedMessage(messageFile, bftMessage); } catch (IOException e) { e.printStackTrace(); System.exit(-1); } this.notifyAll(); } } } }
Example #27
Source File: ConcurrentSkipListSetTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * removeAll(c) removes only those elements of c and reports true if changed */ public void testRemoveAll() { for (int i = 1; i < SIZE; ++i) { ConcurrentSkipListSet q = populatedSet(SIZE); ConcurrentSkipListSet p = populatedSet(i); assertTrue(q.removeAll(p)); assertEquals(SIZE - i, q.size()); for (int j = 0; j < i; ++j) { Integer x = (Integer)(p.pollFirst()); assertFalse(q.contains(x)); } } }
Example #28
Source File: ConcurrentSkipListSetTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * addAll(null) throws NPE */ public void testAddAll1() { ConcurrentSkipListSet q = new ConcurrentSkipListSet(); try { q.addAll(null); shouldThrow(); } catch (NullPointerException success) {} }
Example #29
Source File: ThreadIndexCalculatorTest.java From Oak with Apache License 2.0 | 5 votes |
@Test(timeout = 10000) public void testThreadIDCollision() throws InterruptedException { CountDownLatch threadsStart = new CountDownLatch(1); CountDownLatch threadsFinished = new CountDownLatch(ThreadIndexCalculator.MAX_THREADS); ThreadIndexCalculator indexCalculator = ThreadIndexCalculator.newInstance(); ConcurrentSkipListSet<Integer> uniqueIndices = new ConcurrentSkipListSet<>(); List<Thread> threads = new ArrayList<>(ThreadIndexCalculator.MAX_THREADS); while (threads.size() < ThreadIndexCalculator.MAX_THREADS) { Thread thread = new Thread(() -> { try { threadsStart.await(); } catch (InterruptedException e) { e.printStackTrace(); } int index = indexCalculator.getIndex(); uniqueIndices.add(index); threadsFinished.countDown(); }); if (thread.getId() % ThreadIndexCalculator.MAX_THREADS == 0) { threads.add(thread); thread.start(); } } threadsStart.countDown(); threadsFinished.await(); Assert.assertEquals(ThreadIndexCalculator.MAX_THREADS, uniqueIndices.size()); }
Example #30
Source File: ConcurrentSkipListSetTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * iterator iterates through all elements */ public void testIterator() { ConcurrentSkipListSet q = populatedSet(SIZE); Iterator it = q.iterator(); int i; for (i = 0; it.hasNext(); i++) assertTrue(q.contains(it.next())); assertEquals(i, SIZE); assertIteratorExhausted(it); }