Java 类java.util.concurrent.ConcurrentSkipListMap 实例源码

项目:googles-monorepo-demo    文件:TestsForMapsInJavaUtil.java   
public Test testsForConcurrentSkipListMapNatural() {
  return NavigableMapTestSuiteBuilder.using(
          new TestStringSortedMapGenerator() {
            @Override
            protected SortedMap<String, String> create(Entry<String, String>[] entries) {
              return populate(new ConcurrentSkipListMap<String, String>(), entries);
            }
          })
      .named("ConcurrentSkipListMap, natural")
      .withFeatures(
          MapFeature.GENERAL_PURPOSE,
          CollectionFeature.SUPPORTS_ITERATOR_REMOVE,
          CollectionFeature.KNOWN_ORDER,
          CollectionFeature.SERIALIZABLE,
          CollectionSize.ANY)
      .suppressing(suppressForConcurrentSkipListMap())
      .createTestSuite();
}
项目:cruise-control    文件:MetricSampleAggregator.java   
/**
 * Construct the metric sample aggregator.
 *
 * @param config   The load monitor configurations.
 * @param metadata The metadata of the cluster.
 */
public MetricSampleAggregator(KafkaCruiseControlConfig config,
                              Metadata metadata,
                              MetricCompletenessChecker metricCompletenessChecker) {
  _windowedAggregatedPartitionMetrics = new ConcurrentSkipListMap<>(Comparator.reverseOrder());
  // We keep twice as many the snapshot windows.
  _numSnapshots = config.getInt(KafkaCruiseControlConfig.NUM_LOAD_SNAPSHOTS_CONFIG);
  _numSnapshotsToKeep = _numSnapshots * 2;
  _snapshotWindowMs = config.getLong(KafkaCruiseControlConfig.LOAD_SNAPSHOT_WINDOW_MS_CONFIG);
  _minSamplesPerSnapshot = config.getInt(KafkaCruiseControlConfig.MIN_SAMPLES_PER_LOAD_SNAPSHOT_CONFIG);
  _activeSnapshotWindow = -1L;
  _snapshotCollectionInProgress = new AtomicInteger(0);
  _metadata = metadata;
  _metricCompletenessChecker = metricCompletenessChecker;
  _cachedAggregationResult = null;
  _cachedAggregationResultWindow = -1L;
  _aggregationResultGeneration = new AtomicLong(0);
  _latestBrokerMetrics = new ConcurrentHashMap<>();
  _identityPartitionMap = new ConcurrentHashMap<>();
}
项目:ditb    文件:TestClientNoCluster.java   
/**
 * Create up a map that is keyed by meta row name and whose value is the HRegionInfo and
 * ServerName to return for this row.
 * @return Map with faked hbase:meta content in it.
 */
static SortedMap<byte [], Pair<HRegionInfo, ServerName>> makeMeta(final byte [] tableName,
    final int regionCount, final long namespaceSpan, final int serverCount) {
  // I need a comparator for meta rows so we sort properly.
  SortedMap<byte [], Pair<HRegionInfo, ServerName>> meta =
    new ConcurrentSkipListMap<byte[], Pair<HRegionInfo,ServerName>>(new MetaRowsComparator());
  HRegionInfo [] hris = makeHRegionInfos(tableName, regionCount, namespaceSpan);
  ServerName [] serverNames = makeServerNames(serverCount);
  int per = regionCount / serverCount;
  int count = 0;
  for (HRegionInfo hri: hris) {
    Pair<HRegionInfo, ServerName> p =
      new Pair<HRegionInfo, ServerName>(hri, serverNames[count++ / per]);
    meta.put(hri.getRegionName(), p);
  }
  return meta;
}
项目:guava-mock    文件:TestsForMapsInJavaUtil.java   
public Test testsForConcurrentSkipListMapNatural() {
  return NavigableMapTestSuiteBuilder.using(
          new TestStringSortedMapGenerator() {
            @Override
            protected SortedMap<String, String> create(Entry<String, String>[] entries) {
              return populate(new ConcurrentSkipListMap<String, String>(), entries);
            }
          })
      .named("ConcurrentSkipListMap, natural")
      .withFeatures(
          MapFeature.GENERAL_PURPOSE,
          CollectionFeature.SUPPORTS_ITERATOR_REMOVE,
          CollectionFeature.KNOWN_ORDER,
          CollectionFeature.SERIALIZABLE,
          CollectionSize.ANY)
      .suppressing(suppressForConcurrentSkipListMap())
      .createTestSuite();
}
项目:monarch    文件:AmpoolRegionMapFactoryDUnitTest.java   
public void validateFTableRegionMap(final String tableName) {
  MCache mCache = MCacheFactory.getAnyInstance();
  FTable ftable = mCache.getFTable(tableName);
  // check the region map and internal map
  RegionMap regionMap =
      ((LocalRegion) ((ProxyFTableRegion) ftable).getTableRegion()).getRegionMap();
  assertNotNull(regionMap);
  assertTrue(regionMap instanceof RowTupleLRURegionMap);
  Set<BucketRegion> allLocalBucketRegions =
      ((PartitionedRegion) ((ProxyFTableRegion) ftable).getTableRegion()).getDataStore()
          .getAllLocalBucketRegions();
  allLocalBucketRegions.forEach((BR) -> {
    assertTrue(BR.entries instanceof RowTupleLRURegionMap);
    assertTrue(BR.entries.getInternalMap() instanceof RowTupleConcurrentSkipListMap);
    assertTrue(((RowTupleConcurrentSkipListMap) BR.entries.getInternalMap())
        .getInternalMap() instanceof ConcurrentSkipListMap);
  });
}
项目:hadoop    文件:FifoScheduler.java   
private synchronized void initScheduler(Configuration conf) {
  validateConf(conf);
  //Use ConcurrentSkipListMap because applications need to be ordered
  this.applications =
      new ConcurrentSkipListMap<ApplicationId, SchedulerApplication<FiCaSchedulerApp>>();
  this.minimumAllocation =
      Resources.createResource(conf.getInt(
          YarnConfiguration.RM_SCHEDULER_MINIMUM_ALLOCATION_MB,
          YarnConfiguration.DEFAULT_RM_SCHEDULER_MINIMUM_ALLOCATION_MB));
  initMaximumResourceCapability(
      Resources.createResource(conf.getInt(
          YarnConfiguration.RM_SCHEDULER_MAXIMUM_ALLOCATION_MB,
          YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB),
        conf.getInt(
          YarnConfiguration.RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES,
          YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES),
        conf.getInt(
          YarnConfiguration.RM_SCHEDULER_MAXIMUM_ALLOCATION_GCORES,
          YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_GCORES)));
  this.usePortForNodeName = conf.getBoolean(
      YarnConfiguration.RM_SCHEDULER_INCLUDE_PORT_IN_NODE_NAME,
      YarnConfiguration.DEFAULT_RM_SCHEDULER_USE_PORT_FOR_NODE_NAME);
  this.metrics = QueueMetrics.forQueue(DEFAULT_QUEUE_NAME, null, false,
      conf);
  this.activeUsersManager = new ActiveUsersManager(metrics);
}
项目:jdk8u-jdk    文件:CollectionDefaults.java   
@DataProvider(name="setProvider", parallel=true)
public static Iterator<Object[]> setCases() {
    final List<Object[]> cases = new LinkedList<>();
    cases.add(new Object[] { new HashSet<>() });
    cases.add(new Object[] { new LinkedHashSet<>() });
    cases.add(new Object[] { new TreeSet<>() });
    cases.add(new Object[] { new java.util.concurrent.ConcurrentSkipListSet<>() });
    cases.add(new Object[] { new java.util.concurrent.CopyOnWriteArraySet<>() });

    cases.add(new Object[] { new ExtendsAbstractSet<>() });

    cases.add(new Object[] { Collections.newSetFromMap(new HashMap<>()) });
    cases.add(new Object[] { Collections.newSetFromMap(new LinkedHashMap<>()) });
    cases.add(new Object[] { Collections.newSetFromMap(new TreeMap<>()) });
    cases.add(new Object[] { Collections.newSetFromMap(new ConcurrentHashMap<>()) });
    cases.add(new Object[] { Collections.newSetFromMap(new ConcurrentSkipListMap<>()) });

    cases.add(new Object[] { new HashSet<Integer>(){{add(42);}} });
    cases.add(new Object[] { new ExtendsAbstractSet<Integer>(){{add(42);}} });
    cases.add(new Object[] { new LinkedHashSet<Integer>(){{add(42);}} });
    cases.add(new Object[] { new TreeSet<Integer>(){{add(42);}} });
    return cases.iterator();
}
项目:jdk8u-jdk    文件:TabulatorsTest.java   
@Test(dataProvider = "StreamTestData<Integer>", dataProviderClass = StreamTestDataProvider.class)
public void testSimpleGroupBy(String name, TestData.OfRef<Integer> data) throws ReflectiveOperationException {
    Function<Integer, Integer> classifier = i -> i % 3;

    // Single-level groupBy
    exerciseMapTabulation(data, groupingBy(classifier),
                          new GroupedMapAssertion<>(classifier, HashMap.class,
                                                    new ListAssertion<>()));
    exerciseMapTabulation(data, groupingByConcurrent(classifier),
                          new GroupedMapAssertion<>(classifier, ConcurrentHashMap.class,
                                                    new ListAssertion<>()));

    // With explicit constructors
    exerciseMapTabulation(data,
                          groupingBy(classifier, TreeMap::new, toCollection(HashSet::new)),
                          new GroupedMapAssertion<>(classifier, TreeMap.class,
                                                    new CollectionAssertion<Integer>(HashSet.class, false)));
    exerciseMapTabulation(data,
                          groupingByConcurrent(classifier, ConcurrentSkipListMap::new,
                                               toCollection(HashSet::new)),
                          new GroupedMapAssertion<>(classifier, ConcurrentSkipListMap.class,
                                                    new CollectionAssertion<Integer>(HashSet.class, false)));
}
项目:jdk8u-jdk    文件:ToArray.java   
private static void realMain(String[] args) throws Throwable {
    Map<Integer, Long>[] maps = (Map<Integer, Long>[]) new Map[]{
                new HashMap<>(),
                new Hashtable<>(),
                new IdentityHashMap<>(),
                new LinkedHashMap<>(),
                new TreeMap<>(),
                new WeakHashMap<>(),
                new ConcurrentHashMap<>(),
                new ConcurrentSkipListMap<>()
            };

    // for each map type.
    for (Map<Integer, Long> map : maps) {
         try {
            testMap(map);
         } catch(Exception all) {
            unexpected("Failed for " + map.getClass().getName(), all);
         }
    }
}
项目:switchboard    文件:UnreasonablyOptimisticPlayer.java   
private Collection<Choice> goodChoicesFor(Board board, Goal goal) {
  return board
      .availableChoices()
      .sorted(goal.choiceComparator())
      .reduce(
          new ConcurrentSkipListMap<Double, Choice>(goal.comparator()),
          (diffMap, choice) -> {
            diffMap.put(board.boardScore() - board.choose(choice).boardScore(), choice);
            return diffMap;
          },
          (m1, m2) -> m1)
      .values()
      .stream()
      .limit(3)
      .collect(toImmutableList());
}
项目:openjdk-jdk10    文件:CollectionDefaults.java   
@DataProvider(name="setProvider", parallel=true)
public static Iterator<Object[]> setCases() {
    final List<Object[]> cases = new LinkedList<>();
    cases.add(new Object[] { new HashSet<>() });
    cases.add(new Object[] { new LinkedHashSet<>() });
    cases.add(new Object[] { new TreeSet<>() });
    cases.add(new Object[] { new java.util.concurrent.ConcurrentSkipListSet<>() });
    cases.add(new Object[] { new java.util.concurrent.CopyOnWriteArraySet<>() });

    cases.add(new Object[] { new ExtendsAbstractSet<>() });

    cases.add(new Object[] { Collections.newSetFromMap(new HashMap<>()) });
    cases.add(new Object[] { Collections.newSetFromMap(new LinkedHashMap<>()) });
    cases.add(new Object[] { Collections.newSetFromMap(new TreeMap<>()) });
    cases.add(new Object[] { Collections.newSetFromMap(new ConcurrentHashMap<>()) });
    cases.add(new Object[] { Collections.newSetFromMap(new ConcurrentSkipListMap<>()) });

    cases.add(new Object[] { new HashSet<Integer>(){{add(42);}} });
    cases.add(new Object[] { new ExtendsAbstractSet<Integer>(){{add(42);}} });
    cases.add(new Object[] { new LinkedHashSet<Integer>(){{add(42);}} });
    cases.add(new Object[] { new TreeSet<Integer>(){{add(42);}} });
    return cases.iterator();
}
项目:openjdk-jdk10    文件:AddNonComparable.java   
@Test
public void maps() {
    test(new TreeMap<>(), NonComparable::new,
         (m, e) -> {
             assertEquals(m.size(), 0);
             assertTrue(e instanceof ClassCastException);
         });
    test(new TreeMap<>(), AComparable::new,
         (m, e) -> {
             assertEquals(m.size(), 1);
             assertTrue(e == null);
         });

    test(new ConcurrentSkipListMap<>(), NonComparable::new,
         (s, e) -> {
             assertEquals(s.size(), 0);
             assertTrue(e instanceof ClassCastException);
         });
    test(new ConcurrentSkipListMap<>(), AComparable::new,
         (s, e) -> {
             assertEquals(s.size(), 1);
             assertTrue(e == null);
         });
}
项目:openjdk-jdk10    文件:ConcurrentSkipListMapTest.java   
/**
 * Submaps of submaps subdivide correctly
 */
public void testRecursiveSubMaps() throws Exception {
    int mapSize = expensiveTests ? 1000 : 100;
    Class cl = ConcurrentSkipListMap.class;
    NavigableMap<Integer, Integer> map = newMap(cl);
    bs = new BitSet(mapSize);

    populate(map, mapSize);
    check(map,                 0, mapSize - 1, true);
    check(map.descendingMap(), 0, mapSize - 1, false);

    mutateMap(map, 0, mapSize - 1);
    check(map,                 0, mapSize - 1, true);
    check(map.descendingMap(), 0, mapSize - 1, false);

    bashSubMap(map.subMap(0, true, mapSize, false),
               0, mapSize - 1, true);
}
项目:openjdk-jdk10    文件:ConcurrentSkipListMapTest.java   
/**
 * keySet is ordered
 */
public void testKeySetOrder() {
    ConcurrentSkipListMap map = map5();
    Set s = map.keySet();
    Iterator i = s.iterator();
    Integer last = (Integer)i.next();
    assertEquals(last, one);
    int count = 1;
    while (i.hasNext()) {
        Integer k = (Integer)i.next();
        assertTrue(last.compareTo(k) < 0);
        last = k;
        ++count;
    }
    assertEquals(5, count);
}
项目:openjdk-jdk10    文件:ConcurrentSkipListMapTest.java   
/**
 * descending iterator of key set is inverse ordered
 */
public void testKeySetDescendingIteratorOrder() {
    ConcurrentSkipListMap map = map5();
    NavigableSet s = map.navigableKeySet();
    Iterator i = s.descendingIterator();
    Integer last = (Integer)i.next();
    assertEquals(last, five);
    int count = 1;
    while (i.hasNext()) {
        Integer k = (Integer)i.next();
        assertTrue(last.compareTo(k) > 0);
        last = k;
        ++count;
    }
    assertEquals(5, count);
}
项目:openjdk-jdk10    文件:ConcurrentSkipListMapTest.java   
/**
 * descendingKeySet is ordered
 */
public void testDescendingKeySetOrder() {
    ConcurrentSkipListMap map = map5();
    Set s = map.descendingKeySet();
    Iterator i = s.iterator();
    Integer last = (Integer)i.next();
    assertEquals(last, five);
    int count = 1;
    while (i.hasNext()) {
        Integer k = (Integer)i.next();
        assertTrue(last.compareTo(k) > 0);
        last = k;
        ++count;
    }
    assertEquals(5, count);
}
项目:openjdk-jdk10    文件:ConcurrentSkipListMapTest.java   
/**
 * entrySet contains all pairs
 */
public void testEntrySet() {
    ConcurrentSkipListMap map = map5();
    Set s = map.entrySet();
    assertEquals(5, s.size());
    Iterator it = s.iterator();
    while (it.hasNext()) {
        Map.Entry e = (Map.Entry) it.next();
        assertTrue(
                   (e.getKey().equals(one) && e.getValue().equals("A")) ||
                   (e.getKey().equals(two) && e.getValue().equals("B")) ||
                   (e.getKey().equals(three) && e.getValue().equals("C")) ||
                   (e.getKey().equals(four) && e.getValue().equals("D")) ||
                   (e.getKey().equals(five) && e.getValue().equals("E")));
    }
}
项目:openjdk-jdk10    文件:ConcurrentSkipListMapTest.java   
/**
 * descendingEntrySet contains all pairs
 */
public void testDescendingEntrySet() {
    ConcurrentSkipListMap map = map5();
    Set s = map.descendingMap().entrySet();
    assertEquals(5, s.size());
    Iterator it = s.iterator();
    while (it.hasNext()) {
        Map.Entry e = (Map.Entry) it.next();
        assertTrue(
                   (e.getKey().equals(one) && e.getValue().equals("A")) ||
                   (e.getKey().equals(two) && e.getValue().equals("B")) ||
                   (e.getKey().equals(three) && e.getValue().equals("C")) ||
                   (e.getKey().equals(four) && e.getValue().equals("D")) ||
                   (e.getKey().equals(five) && e.getValue().equals("E")));
    }
}
项目:openjdk-jdk10    文件:ConcurrentSkipListMapTest.java   
/**
 * pollLastEntry returns entries in order
 */
public void testPollLastEntry() {
    ConcurrentSkipListMap map = map5();
    Map.Entry e = map.pollLastEntry();
    assertEquals(five, e.getKey());
    assertEquals("E", e.getValue());
    e = map.pollLastEntry();
    assertEquals(four, e.getKey());
    map.put(five, "E");
    e = map.pollLastEntry();
    assertEquals(five, e.getKey());
    assertEquals("E", e.getValue());
    e = map.pollLastEntry();
    assertEquals(three, e.getKey());
    map.remove(two);
    e = map.pollLastEntry();
    assertEquals(one, e.getKey());
    try {
        e.setValue("E");
        shouldThrow();
    } catch (UnsupportedOperationException success) {}
    e = map.pollLastEntry();
    assertNull(e);
}
项目:fastmq    文件:MapTest.java   
@Test
public void testConcurrentSkipListMap() throws Exception {
    NavigableMap<Long, Boolean> map = new ConcurrentSkipListMap<>();
    map.put(1L, true);
    map.put(3L, true);
    map.put(5L, true);
    Assert.assertEquals(3L, map.ceilingKey(2L).longValue());
    Assert.assertEquals(5L, map.ceilingKey(4L).longValue());
}
项目:openjdk-jdk10    文件:ConcurrentSkipListMapTest.java   
/**
 * toString contains toString of elements
 */
public void testToString() {
    ConcurrentSkipListMap map = map5();
    String s = map.toString();
    for (int i = 1; i <= 5; ++i) {
        assertTrue(s.contains(String.valueOf(i)));
    }
}
项目:openjdk-jdk10    文件:ConcurrentSkipListMapTest.java   
/**
 * remove(null) throws NPE
 */
public void testRemove1_NullPointerException() {
    ConcurrentSkipListMap c = new ConcurrentSkipListMap();
    c.put("sadsdf", "asdads");
    try {
        c.remove(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
项目:memory-graph    文件:PropertyCollection.java   
public synchronized void addProperty(Property property) {
    ConcurrentSkipListMap<String, ConcurrentSkipListSet<Property>> propertiesByKey = propertiesByNameAndKey.get(property.getName());
    if (propertiesByKey == null) {
        propertiesByKey = new ConcurrentSkipListMap<>();
        this.propertiesByNameAndKey.put(property.getName(), propertiesByKey);
    }
    ConcurrentSkipListSet<Property> properties = propertiesByKey.get(property.getKey());
    if (properties == null) {
        properties = new ConcurrentSkipListSet<>();
        propertiesByKey.put(property.getKey(), properties);
    }
    properties.add(property);
    this.propertiesList.add(property);
}
项目:openjdk-jdk10    文件:ConcurrentSkipListMapTest.java   
/**
 * replace value succeeds when the given key mapped to expected value
 */
public void testReplaceValue2() {
    ConcurrentSkipListMap map = map5();
    assertEquals("A", map.get(one));
    assertTrue(map.replace(one, "A", "Z"));
    assertEquals("Z", map.get(one));
}
项目:shabdiz    文件:WorkerNetwork.java   
/**
 * Instantiates a new launcher and exposes the launcher callback on local address with the given port number.
 * The given application library URLs are loaded on any worker which is deployed by this launcher.
 *
 * @param callback_server_port the port on which the callback server is exposed
 * @throws IOException Signals that an I/O exception has occurred.
 */
public WorkerNetwork(final int callback_server_port) throws IOException {

    super("Shabdiz Worker Network");
    id_future_map = new ConcurrentSkipListMap<>();
    callback_server_factory = new LeanServerFactory<>(WorkerCallback.class);
    callback_server = callback_server_factory.createServer(this);
    callback_server.setBindAddress(NetworkUtil.getLocalIPv4InetSocketAddress(callback_server_port));
    expose();
    callback_address = callback_server.getLocalSocketAddress(); // Since the initial server port may be zero, get the actual address of the callback server
    worker_manager = new WorkerManager(this);
}
项目:shabdiz    文件:DefaultWorkerRemote.java   
protected DefaultWorkerRemote(final InetSocketAddress local_address, final InetSocketAddress callback_address) throws IOException {

        callback = CLIENT_FACTORY.get(callback_address);
        submitted_jobs = new ConcurrentSkipListMap<>();
        executor = createExecutorService();
        server = SERVER_FACTORY.createServer(this);
        init(local_address);
    }
项目:openjdk-jdk10    文件:ConcurrentSkipListMapTest.java   
/**
 * remove removes the correct key-value pair from the map
 */
public void testRemove() {
    ConcurrentSkipListMap map = map5();
    map.remove(five);
    assertEquals(4, map.size());
    assertFalse(map.containsKey(five));
}
项目:guava-mock    文件:MapBenchmark.java   
@Override Map<Element, Element> create(Collection<Element> keys) {
  Map<Element, Element> map = new ConcurrentSkipListMap<Element, Element>();
  for (Element element: keys) {
    map.put(element, element);
  }
  return map;
}
项目:guava-mock    文件:ConcurrentHashMultisetTest.java   
private static TestStringMultisetGenerator concurrentSkipListMultisetGenerator() {
  return new TestStringMultisetGenerator() {
    @Override protected Multiset<String> create(String[] elements) {
      Multiset<String> multiset = new ConcurrentHashMultiset<String>(
          new ConcurrentSkipListMap<String, AtomicInteger>());
      Collections.addAll(multiset, elements);
      return multiset;
    }

    @Override
    public List<String> order(List<String> insertionOrder) {
      return Ordering.natural().sortedCopy(insertionOrder);
    }
  };
}
项目:information-retrieval    文件:SearchEngine.java   
/**
 * Initialize a SearchEngine
 * @param dirname the path where the indexer output is
 * @param stopwordspath filter list filepath used for filtering queries
 */
public SearchEngine(String dirname, String stopwordspath) {
    this.dirname = dirname;

    dm = new DiskManager(dirname);
    mem = new MemMgr();
    Thread memT = new Thread(mem);
    memT.start();

    tmap_cache = new ConcurrentSkipListMap<>();

    dmap_cache = new ConcurrentSkipListMap<>();
    //since dmaps holds a mapping docID interval -> docID filepath we can afford to load this map in to mem right now
    buildDmap_cache();

    HashSet<String> stopWords = new HashSet<>();
    try {
        stopWords = DiskUtils.retrieveFilterList(stopwordspath);
    } catch (IOException | NullPointerException ex) {
        Logger.getLogger(Coordinator.class.getName()).log(Level.SEVERE, null, ex);
    }

    //despite this not being thread-safe, the Tokenizer is accessed in a synchronized fashion
    Filter filter = new StopWordFilter(stopWords);
    tkzer = new Tokenizer(filter);

    //build our split table
    splitTable = new ConcurrentSkipListMap<>();
    buildSplitTable();
}
项目:information-retrieval    文件:Ranker.java   
/**
 * Given a map containing the results of a query, rank the result based on their weight
 * @param res Query results
 * @return Query results ranked
 */
public ConcurrentSkipListMap<Integer, Double> rankResults(ConcurrentHashMap<String, ConcurrentHashMap<Integer, Double>> res) {
    ConcurrentHashMap<String, Double> idfs = new ConcurrentHashMap<>();

    // calculate IDFs
    res.entrySet()
            .parallelStream()
            .forEach((t) ->
                    idfs.put(t.getKey(), Math.log10((double) cs.getCorpusCount() / t.getValue().size())));

    /*
     * calculate IDF normalization
     * Normalization = √( ∑ idf(tokens)² )
     */
    double normalization = Math.sqrt(idfs.reduceEntriesToDouble(0, v -> Math.pow(v.getValue(), 2), 0, Double::sum));

    ConcurrentSkipListMap<Integer, Double> scores = new ConcurrentSkipListMap<>();

    res.entrySet()
            .forEach((entry) -> // entry is token:(docid:lnc)
                    entry.getValue()
                            .entrySet()
                            .parallelStream()
                            .forEach((t) -> // docid:lnc
                            {
                                /*
                                  Score for a given document is: Score = ∑ (for
                                  each token) = lnc * idf(token) /
                                  normalization
                                 */
                                Double lnc = res.get(entry.getKey()).get(t.getKey());
                                Double idf = idfs.get(entry.getKey());

                                scores.putIfAbsent(t.getKey(), 0.0);
                                scores.compute(t.getKey(), (k, v) -> Double.sum(v, (lnc * idf) / normalization));
                            }));

    return scores;

}
项目:openjdk-jdk10    文件:ConcurrentSkipListMapTest.java   
/**
 * replace(null, x, y) throws NPE
 */
public void testReplaceValue_NullPointerException() {
    ConcurrentSkipListMap c = map5();
    try {
        c.replace(null, one, "whatever");
        shouldThrow();
    } catch (NullPointerException success) {}
}
项目:datarouter    文件:DatarouterNodes.java   
/********************** constructors **********************************/

    DatarouterNodes(){
        this.topLevelNodes = new ConcurrentSkipListSet<>();
        this.nodeByName = new ConcurrentSkipListMap<>();
        this.topLevelNodesByRouterName = Multimaps.synchronizedMultimap(TreeMultimap.create());
        this.routerNameByNode = new ConcurrentSkipListMap<>();
        this.clientIdsByRouterName = new ConcurrentSkipListMap<>();
        this.physicalNodeByTableNameByClientName = new ConcurrentSkipListMap<>();
    }
项目:L2J-Global    文件:L2PcInstance.java   
/**
 * Add a skill level to the custom skills map.
 * @param skill the skill to add
 */
private void addCustomSkill(Skill skill)
{
    if ((skill != null) && (skill.getDisplayId() != skill.getId()))
    {
        if (_customSkills == null)
        {
            _customSkills = new ConcurrentSkipListMap<>();
        }
        _customSkills.put(skill.getDisplayId(), skill);
    }
}
项目:learnjava8    文件:TestNavigableMap.java   
public static void main(String[] args) {

    NavigableMap<Integer, String> nm = new ConcurrentSkipListMap<>();

    // add some elements        
    nm.put(4, "Wednesday");
    nm.put(5, "Thursday");
    nm.put(6, "Friday");
    nm.put(1, "Sunday");
    nm.put(2, "Monday");                       
    System.out.println("Add some elements. Content: " + nm.toString());

    // get key 5
    System.out.println("Get key 5 : " + nm.get(5));

    // ceilingkey & floorkey
    System.out.println("CeilingKey 3 : " + nm.ceilingKey(3));
    System.out.println("FloorKey 3 : " + nm.floorKey(3));

    // ceilingentry & floorentry
    System.out.println("CeilingEntry 3 : " + nm.ceilingEntry(3));
    System.out.println("FloorEntry 4 : " + nm.floorEntry(4));

    // higherEtntry & lowerEntry
    System.out.println("HigherEntry 4 : " + nm.higherEntry(4));
    System.out.println("HigherEntry 3 : " + nm.higherEntry(3));
    System.out.println("LowerEntry 4 : " + nm.lowerEntry(4));

    // firstEntry & lastEntry
    System.out.println("FirstEntry : " + nm.firstEntry());
    System.out.println("LastEntry : "+nm.lastEntry());                
}
项目:openjdk-jdk10    文件:ConcurrentSkipListMapTest.java   
/**
 * subMap returns map with keys in requested range
 */
public void testSubMapContents() {
    ConcurrentSkipListMap map = map5();
    NavigableMap sm = map.subMap(two, true, four, false);
    assertEquals(two, sm.firstKey());
    assertEquals(three, sm.lastKey());
    assertEquals(2, sm.size());
    assertFalse(sm.containsKey(one));
    assertTrue(sm.containsKey(two));
    assertTrue(sm.containsKey(three));
    assertFalse(sm.containsKey(four));
    assertFalse(sm.containsKey(five));
    Iterator i = sm.keySet().iterator();
    Object k;
    k = (Integer)(i.next());
    assertEquals(two, k);
    k = (Integer)(i.next());
    assertEquals(three, k);
    assertFalse(i.hasNext());
    Iterator r = sm.descendingKeySet().iterator();
    k = (Integer)(r.next());
    assertEquals(three, k);
    k = (Integer)(r.next());
    assertEquals(two, k);
    assertFalse(r.hasNext());

    Iterator j = sm.keySet().iterator();
    j.next();
    j.remove();
    assertFalse(map.containsKey(two));
    assertEquals(4, map.size());
    assertEquals(1, sm.size());
    assertEquals(three, sm.firstKey());
    assertEquals(three, sm.lastKey());
    assertEquals("C", sm.remove(three));
    assertTrue(sm.isEmpty());
    assertEquals(3, map.size());
}
项目:monarch    文件:SortedResultMapImpl.java   
public SortedResultMapImpl(boolean reverse) {
  Comparator comparator = new CachedDeserializableComparator(new NaturalComparator());
  if (reverse) {
    comparator = new ReverseComparator(comparator);
  }
  map = new ConcurrentSkipListMap(comparator);
}
项目:monarch    文件:RowTupleConcurrentSkipListMap.java   
private static SortedMap<Object, Object> getMap(final int mapType) {
  final SortedMap<Object, Object> sm;
  switch (mapType) {
    case 0:
      logger.info("Using: Object2ObjectAVLTreeMap");
      sm = Object2ObjectSortedMaps.synchronize(new Object2ObjectAVLTreeMap<>());
      break;
    default:
      logger.info("Using: ConcurrentSkipListMap");
      sm = new ConcurrentSkipListMap<>();
      break;
  }
  return sm;
}
项目:monarch    文件:AmpoolRegionMapFactoryDUnitTest.java   
private void validateMTableRegionMap(final String tableName, final boolean isOrdered,
    final boolean isLRU) {
  MCache mCache = MCacheFactory.getAnyInstance();
  // get ftable
  MTable mTable_ordered = mCache.getMTable(tableName);

  // check the region map and internal map
  RegionMap regionMap =
      ((LocalRegion) ((ProxyMTableRegion) mTable_ordered).getTableRegion()).getRegionMap();
  assertNotNull(regionMap);
  if (isLRU) {
    assertTrue(regionMap instanceof RowTupleLRURegionMap);
  } else {
    assertTrue(regionMap instanceof RowTupleRegionMap);
  }
  Set<BucketRegion> allLocalBucketRegions =
      ((PartitionedRegion) ((ProxyMTableRegion) mTable_ordered).getTableRegion()).getDataStore()
          .getAllLocalBucketRegions();
  allLocalBucketRegions.forEach((BR) -> {
    if (isLRU) {
      assertTrue(BR.entries instanceof RowTupleLRURegionMap);
    } else {
      assertTrue(BR.entries instanceof RowTupleRegionMap);
    }
    if (isOrdered) {
      assertTrue(BR.entries.getInternalMap() instanceof RowTupleConcurrentSkipListMap);
      assertTrue(((RowTupleConcurrentSkipListMap) BR.entries.getInternalMap())
          .getInternalMap() instanceof ConcurrentSkipListMap);
    } else {
      assertTrue(BR.entries.getInternalMap() instanceof RowTupleConcurrentHashMap);
    }
  });
}
项目:openjdk-jdk10    文件:ConcurrentSkipListMapTest.java   
/**
 * floorEntry returns preceding entry.
 */
public void testFloorEntry() {
    ConcurrentSkipListMap map = map5();
    Map.Entry e1 = map.floorEntry(three);
    assertEquals(three, e1.getKey());

    Map.Entry e2 = map.floorEntry(six);
    assertEquals(five, e2.getKey());

    Map.Entry e3 = map.floorEntry(one);
    assertEquals(one, e3.getKey());

    Map.Entry e4 = map.floorEntry(zero);
    assertNull(e4);
}