it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap Java Examples

The following examples show how to use it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap. 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: UserTagAffinityManager.java    From seldon-server with Apache License 2.0 6 votes vote down vote up
protected UserTagStore loadTagAffinities(String client,Map<Long,Integer> tagCounts,BufferedReader reader) throws IOException
 {
	 String line;
	 ObjectMapper mapper = new ObjectMapper();
	 int numTags = 0;
	 Map<Long,Map<String,Float>> userTagAffinities = new Long2ObjectOpenHashMap<>(tagCounts.size(),1.0f);
//			 HashMap<Long,Map<String,Float>>(tagCounts.size(),1.0f);
	 while((line = reader.readLine()) !=null)
	 {
		 UserTagAffinity data = mapper.readValue(line.getBytes(), UserTagAffinity.class);
		 numTags++;
		 Map<String,Float> tagMap = userTagAffinities.get(data.user);
		 if (tagMap == null)
		 {
			 tagMap = new Object2FloatOpenHashMap<>(tagCounts.get(data.user),1.0f);
					 //new HashMap<String,Float>(tagCounts.get(data.user),1.0f);
			 userTagAffinities.put(data.user, tagMap);
		 }
		 tagMap.put(data.tag, data.weight);
	 }
	 logger.info("Loaded "+userTagAffinities.keySet().size()+" users with "+numTags+" tags for "+client);
	 return new UserTagStore(userTagAffinities);
 }
 
Example #2
Source File: DefaultTypeModelMapper.java    From fastjgame with Apache License 2.0 6 votes vote down vote up
public static DefaultTypeModelMapper newInstance(Collection<TypeModel> identifiers) {
    final Map<Class<?>, TypeModel> type2IdentifierMap = new IdentityHashMap<>(identifiers.size());
    final Map<String, TypeModel> name2TypeMap = CollectionUtils.newHashMapWithExpectedSize(identifiers.size());
    final Long2ObjectMap<TypeModel> number2TypeMap = new Long2ObjectOpenHashMap<>(identifiers.size());

    for (TypeModel typeModel : identifiers) {
        CollectionUtils.requireNotContains(type2IdentifierMap, typeModel.type(), "type");
        CollectionUtils.requireNotContains(name2TypeMap, typeModel.typeName(), "name");
        FastCollectionsUtils.requireNotContains(number2TypeMap, typeModel.typeId().toGuid(), "id");

        type2IdentifierMap.put(typeModel.type(), typeModel);
        name2TypeMap.put(typeModel.typeName(), typeModel);
        number2TypeMap.put(typeModel.typeId().toGuid(), typeModel);
    }

    return new DefaultTypeModelMapper(type2IdentifierMap, name2TypeMap, number2TypeMap);
}
 
Example #3
Source File: KnowledgeBase.java    From fasten with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new knowledge base with no associated database; initializes kryo. One has to explicitly
 * call {@link #callGraphDB(RocksDB)} or {@link #callGraphDB(String)} (typically only once) before
 * using the resulting instance.
 *
 * @param readOnly
 */
private KnowledgeBase(final RocksDB callGraphDB, final ColumnFamilyHandle defaultHandle, final ColumnFamilyHandle gid2URIFamilyHandle, final ColumnFamilyHandle uri2GIDFamilyHandle, final String kbMetadataPathname, final boolean readOnly) {
	GIDAppearsIn = new Long2ObjectOpenHashMap<>();
	GIDCalledBy = new Long2ObjectOpenHashMap<>();
	callGraphs = new Long2ObjectOpenHashMap<>();

	GIDAppearsIn.defaultReturnValue(LongSets.EMPTY_SET);
	GIDCalledBy.defaultReturnValue(LongSets.EMPTY_SET);

	this.readOnly = readOnly;
	this.callGraphDB = callGraphDB;
	this.kbMetadataPathname = kbMetadataPathname;
	this.defaultHandle = defaultHandle;
	this.gid2uriFamilyHandle = gid2URIFamilyHandle;
	this.uri2gidFamilyHandle = uri2GIDFamilyHandle;

	initKryo();
}
 
Example #4
Source File: LoadFactorTest.java    From fastjgame with Apache License 2.0 6 votes vote down vote up
/**
 * 测试fastUtilMap的扩容
 * <p>
 * size > maxFill 扩容
 */
private static void testFastMap() {
    int size = 0;
    if (size++ >= getMaxFill()) {
        System.out.println("inner " + size);
    }
    System.out.println("outer " + size);

    // if (size ++ >= maxFill) 是判定再加,这种写法容易搞晕,一不小心就晕
    // 表示插入之前的容量已经到达阈值则扩容,<=> 插入后的size大于阈值则扩容
    // 等价于JDK的  ++size > maxFill
    Long2ObjectOpenHashMap<String> map3 = new Long2ObjectOpenHashMap<>(3, 1);
    putN(map3, 4);

    Long2ObjectOpenHashMap<String> map4 = new Long2ObjectOpenHashMap<>(4, 1);
    putN(map4, 5);
}
 
Example #5
Source File: CodecRegistrys.java    From fastjgame with Apache License 2.0 6 votes vote down vote up
public static CodecRegistry fromAppPojoCodecs(TypeModelMapper typeModelMapper, List<PojoCodecImpl<?>> pojoCodecs) {
    final Long2ObjectMap<PojoCodecImpl<?>> typeId2CodecMap = new Long2ObjectOpenHashMap<>(pojoCodecs.size());
    final IdentityHashMap<Class<?>, PojoCodecImpl<?>> type2CodecMap = new IdentityHashMap<>(pojoCodecs.size());

    for (PojoCodecImpl<?> pojoCodec : pojoCodecs) {
        final Class<?> type = pojoCodec.getEncoderClass();
        final TypeModel typeModel = typeModelMapper.ofType(type);

        if (typeModel == null) {
            continue;
        }

        FastCollectionsUtils.requireNotContains(typeId2CodecMap, typeModel.typeId().toGuid(), "typeId-(toGuid)");
        CollectionUtils.requireNotContains(type2CodecMap, type, "type");

        typeId2CodecMap.put(typeModel.typeId().toGuid(), pojoCodec);
        type2CodecMap.put(type, pojoCodec);
    }

    return new DefaultCodecRegistry(typeModelMapper, typeId2CodecMap, type2CodecMap);
}
 
Example #6
Source File: HillClimberWindowTinyLfuPolicy.java    From caffeine with Apache License 2.0 6 votes vote down vote up
public HillClimberWindowTinyLfuPolicy(HillClimberType strategy, double percentMain,
    HillClimberWindowTinyLfuSettings settings) {

  int maxMain = (int) (settings.maximumSize() * percentMain);
  this.maxProtected = (int) (maxMain * settings.percentMainProtected());
  this.maxWindow = settings.maximumSize() - maxMain;
  this.data = new Long2ObjectOpenHashMap<>();
  this.maximumSize = settings.maximumSize();
  this.headProtected = new Node();
  this.headProbation = new Node();
  this.headWindow = new Node();

  this.strategy = strategy;
  this.initialPercentMain = percentMain;
  this.policyStats = new PolicyStats(getPolicyName());
  this.admittor = new TinyLfu(settings.config(), policyStats);
  this.climber = strategy.create(settings.config());

  printSegmentSizes();
}
 
Example #7
Source File: FullySegmentedWindowTinyLfuPolicy.java    From caffeine with Apache License 2.0 6 votes vote down vote up
public FullySegmentedWindowTinyLfuPolicy(
    double percentMain, FullySegmentedWindowTinyLfuSettings settings) {
  String name = String.format(
      "sketch.FullySegmentedWindowTinyLfu (%.0f%%)", 100 * (1.0d - percentMain));
  this.policyStats = new PolicyStats(name);
  int maxMain = (int) (settings.maximumSize() * percentMain);
  this.maxWindow = settings.maximumSize() - maxMain;
  this.maxMainProtected = (int) (maxMain * settings.percentMainProtected());
  this.maxWindowProtected = (int) (maxWindow * settings.percentWindowProtected());
  this.admittor = new TinyLfu(settings.config(), policyStats);
  this.data = new Long2ObjectOpenHashMap<>();
  this.maximumSize = settings.maximumSize();
  this.headWindowProbation = new Node();
  this.headWindowProtected = new Node();
  this.headMainProbation = new Node();
  this.headMainProtected = new Node();
}
 
Example #8
Source File: BaseFullChunk.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void addBlockEntity(BlockEntity blockEntity) {
    if (this.tiles == null) {
        this.tiles = new Long2ObjectOpenHashMap<>();
        this.tileList = new Int2ObjectOpenHashMap<>();
    }
    this.tiles.put(blockEntity.getId(), blockEntity);
    int index = ((blockEntity.getFloorZ() & 0x0f) << 12) | ((blockEntity.getFloorX() & 0x0f) << 8) | (blockEntity.getFloorY() & 0xff);
    if (this.tileList.containsKey(index) && !this.tileList.get(index).equals(blockEntity)) {
        BlockEntity entity = this.tileList.get(index);
        this.tiles.remove(entity.getId());
        entity.close();
    }
    this.tileList.put(index, blockEntity);
    if (this.isInit) {
        this.setChanged();
    }
}
 
Example #9
Source File: FeedbackWindowTinyLfuPolicy.java    From caffeine with Apache License 2.0 6 votes vote down vote up
public FeedbackWindowTinyLfuPolicy(double percentMain, FeedbackWindowTinyLfuSettings settings) {
  this.policyStats = new PolicyStats(String.format(
      "sketch.FeedbackWindowTinyLfu (%.0f%%)", 100 * (1.0d - percentMain)));
  this.admittor = new TinyLfu(settings.config(), policyStats);

  int maxMain = (int) (settings.maximumSize() * percentMain);
  this.maxProtected = (int) (maxMain * settings.percentMainProtected());
  this.maxWindow = Math.min(settings.maximumWindowSize(), settings.maximumSize() - maxMain);
  this.data = new Long2ObjectOpenHashMap<>();
  this.maximumSize = settings.maximumSize();
  this.headProtected = new Node();
  this.headProbation = new Node();
  this.headWindow = new Node();

  pivot = (int) (settings.percentPivot() * maxWindow);
  maxPivot = Math.min(settings.maximumWindowSize(), maxProtected);
  sampleSize = Math.min(settings.maximumSampleSize(), maximumSize);
  feedback = settings.membership().filter().create(settings.filterConfig(sampleSize));

  checkState(settings.pivotIncrement() > 0, "Must increase by at least 1");
  checkState(settings.pivotDecrement() > 0, "Must decrease by at least 1");
  pivotIncrement = settings.pivotIncrement();
  pivotDecrement = settings.pivotDecrement();

  printSegmentSizes();
}
 
Example #10
Source File: SalsaNodeVisitorTest.java    From GraphJet with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimpleNodeVisitor() throws Exception {
  SalsaNodeVisitor.SimpleNodeVisitor simpleNodeVisitor =
      new SalsaNodeVisitor.SimpleNodeVisitor(
          salsaInternalState.getVisitedRightNodes());
  simpleNodeVisitor.resetWithRequest(salsaRequest);

  simpleNodeVisitor.visitRightNode(1, 2, (byte) 0, 0L, 1);
  simpleNodeVisitor.visitRightNode(2, 3, (byte) 0, 0L, 1);
  simpleNodeVisitor.visitRightNode(1, 3, (byte) 0, 0L, 1);

  Long2ObjectMap<NodeInfo> expectedVisitedRightNodesMap =
      new Long2ObjectOpenHashMap<NodeInfo>(2);
  expectedVisitedRightNodesMap.put(2, new NodeInfo(2, 1, 1));
  expectedVisitedRightNodesMap.put(3, new NodeInfo(3, 2, 1));

  assertEquals(expectedVisitedRightNodesMap, salsaInternalState.getVisitedRightNodes());
}
 
Example #11
Source File: SalsaNodeVisitorTest.java    From GraphJet with Apache License 2.0 6 votes vote down vote up
@Test
public void testNodeVisitorWithSocialProof() throws Exception {
  SalsaNodeVisitor.NodeVisitorWithSocialProof nodeVisitorWithSocialProof =
      new SalsaNodeVisitor.NodeVisitorWithSocialProof(
          salsaInternalState.getVisitedRightNodes());
  nodeVisitorWithSocialProof.resetWithRequest(salsaRequest);

  nodeVisitorWithSocialProof.visitRightNode(1, 2, (byte) 0, 0L, 1);
  nodeVisitorWithSocialProof.visitRightNode(2, 3, (byte) 0, 0L, 1);
  nodeVisitorWithSocialProof.visitRightNode(1, 3, (byte) 0, 0L, 1);

  NodeInfo node2 = new NodeInfo(2, 1, 1);
  NodeInfo node3 = new NodeInfo(3, 2, 1);
  assertTrue(node3.addToSocialProof(2, (byte) 0, 0L, 1));

  Long2ObjectMap<NodeInfo> expectedVisitedRightNodesMap =
      new Long2ObjectOpenHashMap<NodeInfo>(2);
  expectedVisitedRightNodesMap.put(2, node2);
  expectedVisitedRightNodesMap.put(3, node3);

  assertEquals(expectedVisitedRightNodesMap, salsaInternalState.getVisitedRightNodes());
}
 
Example #12
Source File: SalsaBitmaskTest.java    From GraphJet with Apache License 2.0 6 votes vote down vote up
private StaticBipartiteGraph buildTestGraph() {
  Long2ObjectMap<LongList> leftSideGraph = new Long2ObjectOpenHashMap<LongList>(3);
  leftSideGraph.put(1, new LongArrayList(new long[]{2, 3, 4, 5}));
  leftSideGraph.put(2, new LongArrayList(new long[]{tweetNode, summaryNode, photoNode, playerNode,
      2, 3}));
  leftSideGraph.put(3, new LongArrayList(new long[]{tweetNode, summaryNode, photoNode, playerNode,
      promotionNode, 4, 5}));

  Long2ObjectMap<LongList> rightSideGraph = new Long2ObjectOpenHashMap<LongList>(10);
  rightSideGraph.put(2, new LongArrayList(new long[]{1, 2}));
  rightSideGraph.put(3, new LongArrayList(new long[]{1, 2}));
  rightSideGraph.put(4, new LongArrayList(new long[]{1, 3}));
  rightSideGraph.put(5, new LongArrayList(new long[]{1, 3}));
  rightSideGraph.put(tweetNode, new LongArrayList(new long[]{2, 3}));
  rightSideGraph.put(summaryNode, new LongArrayList(new long[]{2, 3}));
  rightSideGraph.put(photoNode, new LongArrayList(new long[]{2, 3}));
  rightSideGraph.put(playerNode, new LongArrayList(new long[]{2, 3}));
  rightSideGraph.put(promotionNode, new LongArrayList(new long[]{3}));

  return new StaticBipartiteGraph(leftSideGraph, rightSideGraph);

}
 
Example #13
Source File: BipartiteGraphTestHelper.java    From GraphJet with Apache License 2.0 6 votes vote down vote up
/**
 * Build a random bipartite graph of given left and right sizes.
 *
 * @param leftSize   is the left hand size of the bipartite graph
 * @param rightSize  is the right hand size of the bipartite graph
 * @param random     is the random number generator to use for constructing the graph
 * @return a random bipartite graph
 */
public static StaticBipartiteGraph buildRandomBipartiteGraph(
    int leftSize, int rightSize, double edgeProbability, Random random) {
  Long2ObjectMap<LongList> leftSideGraph = new Long2ObjectOpenHashMap<LongList>(leftSize);
  Long2ObjectMap<LongList> rightSideGraph = new Long2ObjectOpenHashMap<LongList>(rightSize);
  int averageLeftDegree = (int) (rightSize * edgeProbability);
  int averageRightDegree = (int) (leftSize * edgeProbability);
  for (int i = 0; i < leftSize; i++) {
    leftSideGraph.put(i, new LongArrayList(averageLeftDegree));
    for (int j = 0; j < rightSize; j++) {
      if (random.nextDouble() < edgeProbability) {
        leftSideGraph.get(i).add(j);
        if (rightSideGraph.containsKey(j)) {
          rightSideGraph.get(j).add(i);
        } else {
          LongList rightSideList = new LongArrayList(averageRightDegree);
          rightSideList.add(i);
          rightSideGraph.put(j, rightSideList);
        }
      }
    }
  }

  return new StaticBipartiteGraph(leftSideGraph, rightSideGraph);
}
 
Example #14
Source File: BipartiteGraphTestHelper.java    From GraphJet with Apache License 2.0 6 votes vote down vote up
/**
 * Build a small test bipartite graph.
 *
 * @return a small test bipartite graph
 */
public static StaticBipartiteGraph buildSmallTestBipartiteGraph() {
  Long2ObjectMap<LongList> leftSideGraph = new Long2ObjectOpenHashMap<LongList>(3);
  leftSideGraph.put(1, new LongArrayList(new long[]{2, 3, 4, 5}));
  leftSideGraph.put(2, new LongArrayList(new long[]{5, 6, 10}));
  leftSideGraph.put(3, new LongArrayList(new long[]{7, 8, 5, 9, 2, 10, 11, 1}));

  Long2ObjectMap<LongList> rightSideGraph = new Long2ObjectOpenHashMap<LongList>(10);
  rightSideGraph.put(1, new LongArrayList(new long[]{3}));
  rightSideGraph.put(2, new LongArrayList(new long[]{1, 3}));
  rightSideGraph.put(3, new LongArrayList(new long[]{1}));
  rightSideGraph.put(4, new LongArrayList(new long[]{1}));
  rightSideGraph.put(5, new LongArrayList(new long[]{1, 2, 3}));
  rightSideGraph.put(6, new LongArrayList(new long[]{2}));
  rightSideGraph.put(7, new LongArrayList(new long[]{3}));
  rightSideGraph.put(8, new LongArrayList(new long[]{3}));
  rightSideGraph.put(9, new LongArrayList(new long[]{3}));
  rightSideGraph.put(10, new LongArrayList(new long[]{2, 3}));
  rightSideGraph.put(11, new LongArrayList(new long[]{3}));

  return new StaticBipartiteGraph(leftSideGraph, rightSideGraph);
}
 
Example #15
Source File: LirsPolicy.java    From caffeine with Apache License 2.0 5 votes vote down vote up
public LirsPolicy(Config config) {
  LirsSettings settings = new LirsSettings(config);
  this.maximumNonResidentSize = (int) (settings.maximumSize() * settings.nonResidentMultiplier());
  this.maximumHotSize = (int) (settings.maximumSize() * settings.percentHot());
  this.policyStats = new PolicyStats("irr.Lirs");
  this.data = new Long2ObjectOpenHashMap<>();
  this.maximumSize = settings.maximumSize();
  this.evicted = new ArrayList<>();
  this.headNR = new Node();
  this.headS = new Node();
  this.headQ = new Node();
}
 
Example #16
Source File: HillClimberFrdPolicy.java    From caffeine with Apache License 2.0 5 votes vote down vote up
public HillClimberFrdPolicy(Config config) {
  FrdSettings settings = new FrdSettings(config);
  this.maximumMainResidentSize = (int) (settings.maximumSize() * settings.percentMain());
  this.maximumFilterSize = settings.maximumSize() - maximumMainResidentSize;
  this.policyStats = new PolicyStats("irr.AdaptiveFrd");
  this.data = new Long2ObjectOpenHashMap<>();
  this.maximumSize = settings.maximumSize();
  this.headFilter = new Node();
  this.headMain = new Node();

  this.sampleSize = 10 * settings.maximumSize();
  this.pivot = (int) (0.05 * settings.maximumSize());
  this.tolerance = 100d * 0;
}
 
Example #17
Source File: TwoQueuePolicy.java    From caffeine with Apache License 2.0 5 votes vote down vote up
public TwoQueuePolicy(Config config) {
  TwoQueueSettings settings = new TwoQueueSettings(config);

  this.headIn = new Node();
  this.headOut = new Node();
  this.headMain = new Node();
  this.maximumSize = settings.maximumSize();
  this.data = new Long2ObjectOpenHashMap<>();
  this.maxIn = (int) (maximumSize * settings.percentIn());
  this.policyStats = new PolicyStats("two-queue.TwoQueue");
  this.maxOut = (int) (maximumSize * settings.percentOut());
}
 
Example #18
Source File: SegmentedLruPolicy.java    From caffeine with Apache License 2.0 5 votes vote down vote up
public SegmentedLruPolicy(Admission admission, Config config) {
  this.policyStats = new PolicyStats(admission.format("linked.SegmentedLru"));
  this.admittor = admission.from(config, policyStats);

  SegmentedLruSettings settings = new SegmentedLruSettings(config);
  this.headProtected = new Node();
  this.headProbation = new Node();
  this.maximumSize = settings.maximumSize();
  this.data = new Long2ObjectOpenHashMap<>();
  this.maxProtected = (int) (maximumSize * settings.percentProtected());
}
 
Example #19
Source File: MultiQueuePolicy.java    From caffeine with Apache License 2.0 5 votes vote down vote up
public MultiQueuePolicy(Config config) {
  MultiQueueSettings settings = new MultiQueueSettings(config);
  policyStats = new PolicyStats("linked.MultiQueue");
  threshold = new long[settings.numberOfQueues()];
  headQ = new Node[settings.numberOfQueues()];
  out = new Long2ObjectLinkedOpenHashMap<>();
  data = new Long2ObjectOpenHashMap<>();
  maximumSize = settings.maximumSize();
  lifetime = settings.lifetime();

  Arrays.setAll(headQ, Node::sentinel);
  Arrays.setAll(threshold, i -> 1L << i);
  maxOut = (int) (maximumSize * settings.percentOut());
}
 
Example #20
Source File: S4LruPolicy.java    From caffeine with Apache License 2.0 5 votes vote down vote up
public S4LruPolicy(Admission admission, Config config) {
  this.policyStats = new PolicyStats(admission.format("linked.S4Lru"));
  this.admittor = admission.from(config, policyStats);
  S4LruSettings settings = new S4LruSettings(config);
  this.data = new Long2ObjectOpenHashMap<>();
  this.maximumSize = settings.maximumSize();
  this.levels = settings.levels();
  this.headQ = new Node[levels];
  this.sizeQ = new int[levels];

  Arrays.setAll(headQ, Node::sentinel);
}
 
Example #21
Source File: TuQueuePolicy.java    From caffeine with Apache License 2.0 5 votes vote down vote up
public TuQueuePolicy(Config config) {
  TuQueueSettings settings = new TuQueueSettings(config);

  this.headHot = new Node();
  this.headWarm = new Node();
  this.headCold = new Node();
  this.maximumSize = settings.maximumSize();
  this.data = new Long2ObjectOpenHashMap<>();
  this.policyStats = new PolicyStats("two-queue.TuQueue");
  this.maxHot = (int) (maximumSize * settings.percentHot());
  this.maxWarm = (int) (maximumSize * settings.percentWarm());
}
 
Example #22
Source File: OrderBooks.java    From parity with Apache License 2.0 5 votes vote down vote up
OrderBooks(List<String> instruments, MarketData marketData, MarketReporting marketReporting) {
    this.books  = new Long2ObjectArrayMap<>();
    this.orders = new Long2ObjectOpenHashMap<>();

    EventHandler handler = new EventHandler();

    for (String instrument : instruments)
        books.put(ASCII.packLong(instrument), new OrderBook(handler));

    this.marketData      = marketData;
    this.marketReporting = marketReporting;

    this.nextOrderNumber = 1;
    this.nextMatchNumber = 1;
}
 
Example #23
Source File: Market.java    From parity with Apache License 2.0 5 votes vote down vote up
/**
 * Create a market.
 *
 * @param listener a listener for outbound events from the market
 */
public Market(MarketListener listener) {
    this.books  = new Long2ObjectArrayMap<>();
    this.orders = new Long2ObjectOpenHashMap<>();

    this.listener = listener;
}
 
Example #24
Source File: LinkedPolicy.java    From caffeine with Apache License 2.0 5 votes vote down vote up
public LinkedPolicy(Admission admission, EvictionPolicy policy, Config config) {
  this.policyStats = new PolicyStats(admission.format("linked." + policy.label()));
  this.admittor = admission.from(config, policyStats);
  BasicSettings settings = new BasicSettings(config);
  this.data = new Long2ObjectOpenHashMap<>();
  this.maximumSize = settings.maximumSize();
  this.sentinel = new Node();
  this.policy = policy;
}
 
Example #25
Source File: CarPolicy.java    From caffeine with Apache License 2.0 5 votes vote down vote up
public CarPolicy(Config config) {
  BasicSettings settings = new BasicSettings(config);
  this.policyStats = new PolicyStats("adaptive.Car");
  this.data = new Long2ObjectOpenHashMap<>();
  this.maximumSize = settings.maximumSize();
  this.headT1 = new Node();
  this.headT2 = new Node();
  this.headB1 = new Node();
  this.headB2 = new Node();
}
 
Example #26
Source File: ArcPolicy.java    From caffeine with Apache License 2.0 5 votes vote down vote up
public ArcPolicy(Config config) {
  BasicSettings settings = new BasicSettings(config);
  this.policyStats = new PolicyStats("adaptive.Arc");
  this.maximumSize = settings.maximumSize();
  this.data = new Long2ObjectOpenHashMap<>();
  this.headT1 = new Node();
  this.headT2 = new Node();
  this.headB1 = new Node();
  this.headB2 = new Node();
}
 
Example #27
Source File: CartPolicy.java    From caffeine with Apache License 2.0 5 votes vote down vote up
public CartPolicy(Config config) {
  BasicSettings settings = new BasicSettings(config);
  this.policyStats = new PolicyStats("adaptive.Cart");
  this.data = new Long2ObjectOpenHashMap<>();
  this.maximumSize = settings.maximumSize();
  this.headT1 = new Node();
  this.headT2 = new Node();
  this.headB1 = new Node();
  this.headB2 = new Node();
}
 
Example #28
Source File: ChunkManagerPlanet.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
public void resetCache() {

		try {
			fBiomeCacheMap.set(this.biomeCache, new Long2ObjectOpenHashMap(4096));
			((List)fBiomeCache.get(this.biomeCache)).clear();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
 
Example #29
Source File: OrderBook.java    From parity with Apache License 2.0 5 votes vote down vote up
/**
 * Create an order book.
 *
 * @param listener a listener for outbound events from the order book
 */
public OrderBook(OrderBookListener listener) {
    this.bids = new TreeSet<>(OrderBook::compareBids);
    this.asks = new TreeSet<>(OrderBook::compareAsks);

    this.orders = new Long2ObjectOpenHashMap<>();

    this.listener = listener;

    this.nextOrderNumber = 0;
}
 
Example #30
Source File: FrequentlyUsedPolicy.java    From caffeine with Apache License 2.0 5 votes vote down vote up
public FrequentlyUsedPolicy(Admission admission, EvictionPolicy policy, Config config) {
  this.policyStats = new PolicyStats(admission.format("linked." + policy.label()));
  this.admittor = admission.from(config, policyStats);
  BasicSettings settings = new BasicSettings(config);
  this.data = new Long2ObjectOpenHashMap<>();
  this.maximumSize = settings.maximumSize();
  this.policy = requireNonNull(policy);
  this.freq0 = new FrequencyNode();
}