Java Code Examples for it.unimi.dsi.fastutil.longs.Long2ObjectMap#put()

The following examples show how to use it.unimi.dsi.fastutil.longs.Long2ObjectMap#put() . 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: 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 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: AgreeSetGenerator.java    From metanome-algorithms with Apache License 2.0 6 votes vote down vote up
private void calculateRelationship(StrippedPartition partitions, Long2ObjectMap<TupleEquivalenceClassRelation> relationships) {

        int partitionNr = 0;
        for (IntList partition : partitions.getValues()) {
            if (this.debugSysout)
                System.out.println(".");
            for (long index : partition) {
                if (!relationships.containsKey(index)) {
                    relationships.put(index, new TupleEquivalenceClassRelation());
                }
                relationships.get(index).addNewRelationship(partitions.getAttributeID(), partitionNr);
            }
            partitionNr++;
        }

    }
 
Example 4
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 5
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 6
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 7
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 8
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 9
Source File: ClientCacheMissResponseSerializer_v388.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, ClientCacheMissResponsePacket packet) {
    Long2ObjectMap<byte[]> blobs = packet.getBlobs();

    int length = VarInts.readUnsignedInt(buffer);

    for (int i = 0; i < length; i++) {
        long id = buffer.readLongLE();
        byte[] blob = BedrockUtils.readByteArray(buffer);
        blobs.put(id, blob);
    }
}
 
Example 10
Source File: ClientCacheMissResponseSerializer_v361.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, ClientCacheMissResponsePacket packet) {
    Long2ObjectMap<byte[]> blobs = packet.getBlobs();

    int length = VarInts.readUnsignedInt(buffer);

    for (int i = 0; i < length; i++) {
        long id = buffer.readLongLE();
        byte[] blob = BedrockUtils.readByteArray(buffer);
        blobs.put(id, blob);
    }
}
 
Example 11
Source File: AgreeSetGenerator.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
private void handlePartition(IntList actuelList, long position, Long2ObjectMap<LongSet> index, Set<IntList> max) {

        if (!this.isSubset(actuelList, index)) {
            max.add(actuelList);
            for (long e : actuelList) {
                if (!index.containsKey(e)) {
                    index.put(e, new LongArraySet());
                }
                index.get(e).add(position);
            }
        }
    }
 
Example 12
Source File: SalsaIterationsTest.java    From GraphJet with Apache License 2.0 5 votes vote down vote up
@Test
public void testSingleLeftIteration() throws Exception {
  SalsaIterations<BipartiteGraph> salsaIterations = new SalsaIterations<BipartiteGraph>(
      salsaInternalState,
      new LeftSalsaIteration(salsaInternalState),
      new RightSalsaIteration(salsaInternalState),
      new FinalSalsaIteration(salsaInternalState)
  );
  salsaIterations.resetWithRequest(salsaRequest, random);
  SingleSalsaIteration leftSalsaIteration =
      new LeftSalsaIteration(salsaInternalState);
  leftSalsaIteration.resetWithRequest(salsaRequest, random);

  salsaIterations.seedLeftSideForFirstIteration();
  leftSalsaIteration.runSingleIteration();

  Long2ObjectMap<NodeInfo> expectedVisitedRightNodesMap =
      new Long2ObjectOpenHashMap<NodeInfo>(9);

  // highest weight
  expectedVisitedRightNodesMap.put(2, new NodeInfo(2, 167, 1));
  expectedVisitedRightNodesMap.put(3, new NodeInfo(3, 168, 1));
  expectedVisitedRightNodesMap.put(4, new NodeInfo(4, 167, 1));
  expectedVisitedRightNodesMap.put(5, new NodeInfo(5, 177, 1));
  // medium weight
  expectedVisitedRightNodesMap.put(6, new NodeInfo(6, 22, 1));
  expectedVisitedRightNodesMap.put(10, new NodeInfo(10, 25, 1));
  // small weight
  expectedVisitedRightNodesMap.put(7, new NodeInfo(7, 2, 1));
  expectedVisitedRightNodesMap.put(9, new NodeInfo(9, 1, 1));
  expectedVisitedRightNodesMap.put(11, new NodeInfo(11, 1, 1));

  assertEquals(1, salsaInternalState.getCurrentLeftNodes().size());
  assertEquals(expectedVisitedRightNodesMap, salsaInternalState.getVisitedRightNodes());
}
 
Example 13
Source File: BipartiteGraphTestHelper.java    From GraphJet with Apache License 2.0 5 votes vote down vote up
/**
 * Build a small test bipartite graph.
 *
 * @return a small test bipartite graph
 */
public static StaticLeftIndexedBipartiteGraph buildSmallTestLeftIndexedBipartiteGraph() {
  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}));

  return new StaticLeftIndexedBipartiteGraph(leftSideGraph);
}
 
Example 14
Source File: ForgeQueue_All.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
public boolean regenerateChunk(World world, int x, int z) {
    IChunkProvider provider = world.getChunkProvider();
    if (!(provider instanceof ChunkProviderServer)) {
        return false;
    }
    BlockFalling.fallInstantly = true;
    try {
        ChunkProviderServer chunkServer = (ChunkProviderServer) provider;
        IChunkGenerator gen = (IChunkGenerator) fieldChunkGenerator.get(chunkServer);
        long pos = ChunkPos.asLong(x, z);
        Chunk mcChunk;
        if (chunkServer.chunkExists(x, z)) {
            mcChunk = chunkServer.loadChunk(x, z);
            mcChunk.onUnload();
        }
        PlayerChunkMap playerManager = ((WorldServer) getWorld()).getPlayerChunkMap();
        List<EntityPlayerMP> oldWatchers = null;
        if (chunkServer.chunkExists(x, z)) {
            mcChunk = chunkServer.loadChunk(x, z);
            PlayerChunkMapEntry entry = playerManager.getEntry(x, z);
            if (entry != null) {
                Field fieldPlayers = PlayerChunkMapEntry.class.getDeclaredField("field_187283_c");
                fieldPlayers.setAccessible(true);
                oldWatchers = (List<EntityPlayerMP>) fieldPlayers.get(entry);
                playerManager.removeEntry(entry);
            }
            mcChunk.onUnload();
        }
        try {
            Field droppedChunksSetField = chunkServer.getClass().getDeclaredField("field_73248_b");
            droppedChunksSetField.setAccessible(true);
            Set droppedChunksSet = (Set) droppedChunksSetField.get(chunkServer);
            droppedChunksSet.remove(pos);
        } catch (Throwable e) {
            MainUtil.handleError(e);
        }
        Long2ObjectMap<Chunk> id2ChunkMap = chunkServer.id2ChunkMap;
        id2ChunkMap.remove(pos);
        mcChunk = gen.generateChunk(x, z);
        id2ChunkMap.put(pos, mcChunk);
        if (mcChunk != null) {
            mcChunk.onLoad();
            mcChunk.populate(chunkServer, gen);
        }
        if (oldWatchers != null) {
            for (EntityPlayerMP player : oldWatchers) {
                playerManager.addPlayer(player);
            }
        }
        return true;
    } catch (Throwable t) {
        MainUtil.handleError(t);
        return false;
    } finally {
        BlockFalling.fallInstantly = false;
    }
}
 
Example 15
Source File: SpongeQueue_1_12.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
public boolean regenerateChunk(net.minecraft.world.World world, int x, int z) {
    IChunkProvider provider = world.getChunkProvider();
    if (!(provider instanceof ChunkProviderServer)) {
        return false;
    }
    BlockFalling.fallInstantly = true;
    try {
        ChunkProviderServer chunkServer = (ChunkProviderServer) provider;
        IChunkGenerator gen = (IChunkGenerator) fieldChunkGenerator.get(chunkServer);
        long pos = ChunkPos.asLong(x, z);
        Chunk mcChunk;
        if (chunkServer.chunkExists(x, z)) {
            mcChunk = chunkServer.loadChunk(x, z);
            mcChunk.onUnload();
        }
        PlayerChunkMap playerManager = ((WorldServer) getWorld()).getPlayerChunkMap();
        List<EntityPlayerMP> oldWatchers = null;
        if (chunkServer.chunkExists(x, z)) {
            mcChunk = chunkServer.loadChunk(x, z);
            PlayerChunkMapEntry entry = playerManager.getEntry(x, z);
            if (entry != null) {
                Field fieldPlayers = PlayerChunkMapEntry.class.getDeclaredField("field_187283_c");
                fieldPlayers.setAccessible(true);
                oldWatchers = (List<EntityPlayerMP>) fieldPlayers.get(entry);
                playerManager.removeEntry(entry);
            }
            mcChunk.onUnload();
        }
        try {
            Field droppedChunksSetField = chunkServer.getClass().getDeclaredField("field_73248_b");
            droppedChunksSetField.setAccessible(true);
            Set droppedChunksSet = (Set) droppedChunksSetField.get(chunkServer);
            droppedChunksSet.remove(pos);
        } catch (Throwable e) {
            MainUtil.handleError(e);
        }
        Long2ObjectMap<Chunk> id2ChunkMap = (Long2ObjectMap<Chunk>) fieldId2ChunkMap.get(chunkServer);
        id2ChunkMap.remove(pos);
        mcChunk = gen.generateChunk(x, z);
        id2ChunkMap.put(pos, mcChunk);
        if (mcChunk != null) {
            mcChunk.onLoad();
            mcChunk.populate(chunkServer, gen);
        }
        if (oldWatchers != null) {
            for (EntityPlayerMP player : oldWatchers) {
                playerManager.addPlayer(player);
            }
        }
        return true;
    } catch (Throwable t) {
        MainUtil.handleError(t);
        return false;
    } finally {
        BlockFalling.fallInstantly = false;
    }
}
 
Example 16
Source File: SpongeQueue_1_11.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
public boolean regenerateChunk(net.minecraft.world.World world, int x, int z) {
    IChunkProvider provider = world.getChunkProvider();
    if (!(provider instanceof ChunkProviderServer)) {
        return false;
    }
    BlockFalling.fallInstantly = true;
    try {
        ChunkProviderServer chunkServer = (ChunkProviderServer) provider;
        IChunkGenerator gen = (IChunkGenerator) fieldChunkGenerator.get(chunkServer);
        long pos = ChunkPos.asLong(x, z);
        Chunk mcChunk;
        if (chunkServer.chunkExists(x, z)) {
            mcChunk = chunkServer.loadChunk(x, z);
            mcChunk.onChunkUnload();
        }
        PlayerChunkMap playerManager = ((WorldServer) getWorld()).getPlayerChunkMap();
        List<EntityPlayerMP> oldWatchers = null;
        if (chunkServer.chunkExists(x, z)) {
            mcChunk = chunkServer.loadChunk(x, z);
            PlayerChunkMapEntry entry = playerManager.getEntry(x, z);
            if (entry != null) {
                Field fieldPlayers = PlayerChunkMapEntry.class.getDeclaredField("field_187283_c");
                fieldPlayers.setAccessible(true);
                oldWatchers = (List<EntityPlayerMP>) fieldPlayers.get(entry);
                playerManager.removeEntry(entry);
            }
            mcChunk.onChunkUnload();
        }
        try {
            Field droppedChunksSetField = chunkServer.getClass().getDeclaredField("field_73248_b");
            droppedChunksSetField.setAccessible(true);
            Set droppedChunksSet = (Set) droppedChunksSetField.get(chunkServer);
            droppedChunksSet.remove(pos);
        } catch (Throwable e) {
            MainUtil.handleError(e);
        }
        Long2ObjectMap<Chunk> id2ChunkMap = (Long2ObjectMap<Chunk>) fieldId2ChunkMap.get(chunkServer);
        id2ChunkMap.remove(pos);
        mcChunk = gen.provideChunk(x, z);
        id2ChunkMap.put(pos, mcChunk);
        if (mcChunk != null) {
            mcChunk.onChunkLoad();
            mcChunk.populateChunk(chunkServer, gen);
        }
        if (oldWatchers != null) {
            for (EntityPlayerMP player : oldWatchers) {
                playerManager.addPlayer(player);
            }
        }
        return true;
    } catch (Throwable t) {
        MainUtil.handleError(t);
        return false;
    } finally {
        BlockFalling.fallInstantly = false;
    }
}
 
Example 17
Source File: SalsaIterationsTest.java    From GraphJet with Apache License 2.0 4 votes vote down vote up
@Test
public void testFinalLeftIteration() throws Exception {
  SalsaIterations<BipartiteGraph> salsaIterations = new SalsaIterations<BipartiteGraph>(
      salsaInternalState,
      new LeftSalsaIteration(salsaInternalState),
      new RightSalsaIteration(salsaInternalState),
      new FinalSalsaIteration(salsaInternalState)
  );
  salsaIterations.resetWithRequest(salsaRequest, random);
  SingleSalsaIteration leftSalsaIteration =
      new FinalSalsaIteration(salsaInternalState);
  leftSalsaIteration.resetWithRequest(salsaRequest, random);

  salsaIterations.seedLeftSideForFirstIteration();
  leftSalsaIteration.runSingleIteration();

  Long2ObjectMap<NodeInfo> expectedVisitedRightNodesMap =
      new Long2ObjectOpenHashMap<NodeInfo>(9);
  NodeInfo node2 = new NodeInfo(2, 167, 1);
  node2.addToSocialProof(3, (byte) 0, 0L, 1.0);
  expectedVisitedRightNodesMap.put(2, node2);
  NodeInfo node3 = new NodeInfo(3, 168, 1);
  expectedVisitedRightNodesMap.put(3, node3);
  NodeInfo node4 = new NodeInfo(4, 167, 1);
  expectedVisitedRightNodesMap.put(4, node4);
  NodeInfo node5 = new NodeInfo(5, 177, 1);
  node5.addToSocialProof(3, (byte) 0, 0L, 1.0);
  node5.addToSocialProof(2, (byte) 0, 0L, 1.0);
  expectedVisitedRightNodesMap.put(5, node5);
  NodeInfo node6 = new NodeInfo(6, 22, 1);
  node6.addToSocialProof(2, (byte) 0, 0L, 1.0);
  expectedVisitedRightNodesMap.put(6, node6);
  NodeInfo node7 = new NodeInfo(7, 2, 1);
  node7.addToSocialProof(3, (byte) 0, 0L, 1.0);
  expectedVisitedRightNodesMap.put(7, node7);
  NodeInfo node9 = new NodeInfo(9, 1, 1);
  node9.addToSocialProof(3, (byte) 0, 0L, 1.0);
  expectedVisitedRightNodesMap.put(9, node9);
  NodeInfo node10 = new NodeInfo(10, 25, 1);
  node10.addToSocialProof(3, (byte) 0, 0L, 1.0);
  node10.addToSocialProof(2, (byte) 0, 0L, 1.0);
  expectedVisitedRightNodesMap.put(10, node10);
  NodeInfo node11 = new NodeInfo(11, 1, 1);
  node11.addToSocialProof(3, (byte) 0, 0L, 1.0);
  expectedVisitedRightNodesMap.put(11, node11);

  assertEquals(expectedVisitedRightNodesMap, salsaInternalState.getVisitedRightNodes());
}
 
Example 18
Source File: AgreeSetGenerator.java    From metanome-algorithms with Apache License 2.0 4 votes vote down vote up
public Set<IntList> computeMaximumSetsAlternative(List<StrippedPartition> partitions) {

        if (this.debugSysout) {
            System.out.println("\tstartet calculation of maximal partitions");
        }
        long start = System.currentTimeMillis();

        Set<IntList> sortedPartitions = new TreeSet<IntList>(new ListComparator());
        for (StrippedPartition p : partitions) {
            sortedPartitions.addAll(p.getValues());
        }
        Iterator<IntList> it = sortedPartitions.iterator();
        Long2ObjectMap<Set<IntList>> maxSets = new Long2ObjectOpenHashMap<Set<IntList>>();
        long remainingPartitions = sortedPartitions.size();
        if (this.debugSysout) {
            System.out.println("\tNumber of Partitions: " + remainingPartitions);
        }
        if (it.hasNext()) {
            IntList actuelList = it.next();
            long minSize = actuelList.size();
            Set<IntList> set = new HashSet<IntList>();
            set.add(actuelList);
            while ((actuelList = it.next()) != null && (actuelList.size() == minSize)) {
                if (this.debugSysout) {
                    System.out.println("\tremaining: " + --remainingPartitions);
                }
                set.add(actuelList);
            }
            maxSets.put(minSize, set);
            if (actuelList != null) {
                maxSets.put(actuelList.size(), new HashSet<IntList>());
                if (this.debugSysout) {
                    System.out.println("\tremaining: " + --remainingPartitions);
                }
                this.handleList(actuelList, maxSets, true);
                while (it.hasNext()) {
                    actuelList = it.next();
                    if (this.debugSysout) {
                        System.out.println("\tremaining: " + --remainingPartitions);
                    }
                    if (!maxSets.containsKey(actuelList.size()))
                        maxSets.put(actuelList.size(), new HashSet<IntList>());
                    this.handleList(actuelList, maxSets, true);
                }
            }
        }

        long end = System.currentTimeMillis();
        if (this.debugSysout)
            System.out.println("\tTime needed: " + (end - start));

        Set<IntList> max = this.mergeResult(maxSets);
        maxSets.clear();
        sortedPartitions.clear();

        return max;
    }
 
Example 19
Source File: KnowledgeBase.java    From fasten with Apache License 2.0 2 votes vote down vote up
/**
 * Adds a given revision index to the set associated to the given gid.
 *
 * @param map the map associating gids to sets revision indices.
 * @param gid the gid whose associated set should be modified.
 * @param revIndex the revision index to be added.
 *
 * @return true iff the revision index was not present.
 */
protected static boolean addGidRev(final Long2ObjectMap<LongSet> map, final long gid, final long revIndex) {
	LongSet set = map.get(gid);
	if (set == LongSets.EMPTY_SET) map.put(gid, set = new LongOpenHashSet());
	return set.add(revIndex);
}