本文整理汇总了Java中gnu.trove.set.TLongSet.add方法的典型用法代码示例。如果您正苦于以下问题:Java TLongSet.add方法的具体用法?Java TLongSet.add怎么用?Java TLongSet.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gnu.trove.set.TLongSet
的用法示例。
在下文中一共展示了TLongSet.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: distinct
import gnu.trove.set.TLongSet; //导入方法依赖的package包/类
@Override
public Array<T> distinct(int limit) {
final int capacity = limit < Integer.MAX_VALUE ? limit : 100;
final TLongSet set = new TLongHashSet(capacity);
final ArrayBuilder<T> builder = ArrayBuilder.of(capacity, type());
for (int i=0; i<length(); ++i) {
final long code = getLong(i);
if (set.add(code)) {
final T value = getValue(i);
builder.add(value);
if (set.size() >= limit) {
break;
}
}
}
return builder.toArray();
}
示例2: distinct
import gnu.trove.set.TLongSet; //导入方法依赖的package包/类
@Override
public final Array<Long> distinct(int limit) {
final int capacity = limit < Integer.MAX_VALUE ? limit : 100;
final TLongSet set = new TLongHashSet(capacity);
final ArrayBuilder<Long> builder = ArrayBuilder.of(capacity, Long.class);
for (int i=0; i<length(); ++i) {
final long value = getLong(i);
if (set.add(value)) {
builder.addLong(value);
if (set.size() >= limit) {
break;
}
}
}
return builder.toArray();
}
示例3: trivia
import gnu.trove.set.TLongSet; //导入方法依赖的package包/类
@Command(
name = "trivia",
description = "Play trivia",
usage = "`>>trivia`: Play trivia",
permission = CommandPermission.USER,
category = CommandCategory.GAME
)
public static void trivia(@Argument("channel") TextChannel channel, @Argument("author") User author) {
if(check(channel)) return;
OpenTriviaDatabase.Question q = OpenTriviaDatabase.random();
if(q == null) {
channel.sendMessage("Error getting a question from open trivia database").queue();
return;
}
TLongSet players = new TLongHashSet();
players.add(author.getIdLong());
EventManagerThread.current().newThread(()->{
try {
Thread.sleep(100);
} catch(InterruptedException e) {
return;
}
InteractiveOperations.create(channel.getIdLong(), 120, new Trivia(channel, players, q));
}, "Game Starter").start();
}
示例4: friends
import gnu.trove.set.TLongSet; //导入方法依赖的package包/类
@Command(
name = "pokemonguess",
description = "Guess which pokemon it is",
usage = "`>>pokemonguess`: Play pokemon guess solo\n" +
"`>>pokemonguess @Someone @SomeoneElse ...`: Play pokemon guess with your friends (if you have any)",
permission = CommandPermission.USER,
category = CommandCategory.GAME
)
public static void pokemonguess(@Argument("channel") TextChannel channel, @Argument("author") User author, @Argument("message") Message message) {
if(check(channel)) return;
TLongSet players = new TLongHashSet();
players.add(author.getIdLong());
for(User u : message.getMentionedUsers()) players.add(u.getIdLong());
EventManagerThread.current().newThread(()->{
try {
Thread.sleep(100);
} catch(InterruptedException e) {
return;
}
InteractiveOperations.create(channel.getIdLong(), 120, new Pokemon(channel, players));
}, "Game Starter").start();
}
示例5: hasNodeIntersections
import gnu.trove.set.TLongSet; //导入方法依赖的package包/类
/**
* Return whether this ring has intersections in terms of node ids appearing
* multiple times.
*/
public boolean hasNodeIntersections() {
int size = this.nodeIds.size();
// Keep a set of already encountered ids
TLongSet before = new TLongHashSet();
// The first id can't be there already because the set is empty
before.add(this.nodeIds.get(0));
// Check all nodes except the last one which gets special care
for (int i = 1; i < size - 1; i++) {
long id = this.nodeIds.get(i);
// Is it already on the set -> there is an intersection
if (before.contains(id)) {
return true;
}
// Add to the set of encountered ids
before.add(id);
}
// If this ring is closed, the last node intersects the first one, but
// that is okay
if (this.isClosed()) {
return false;
}
// If the ring is not closed, the last node might be an intersection
// with one of the others
return before.contains(this.nodeIds.get(size - 1));
}
示例6: findMemberRelationsRecursively
import gnu.trove.set.TLongSet; //导入方法依赖的package包/类
private void findMemberRelationsRecursively(Deque<OsmRelation> queue,
Set<OsmRelation> outRelations) throws EntityNotFoundException {
TLongSet ids = new TLongHashSet();
while (!queue.isEmpty()) {
OsmRelation relation = queue.remove();
for (OsmRelationMember member : OsmModelUtil
.membersAsList(relation)) {
if (member.getType() != EntityType.Relation) {
continue;
}
long id = member.getId();
if (ids.contains(id)) {
continue;
}
ids.add(id);
OsmRelation child = this.entityProvider.getRelation(id);
outRelations.add(child);
queue.add(child);
}
}
}
示例7: findMemberRelationsRecursively
import gnu.trove.set.TLongSet; //导入方法依赖的package包/类
private void findMemberRelationsRecursively(Deque<OsmRelation> queue,
Set<OsmRelation> outRelations) {
TLongSet ids = new TLongHashSet();
while (!queue.isEmpty()) {
OsmRelation relation = queue.remove();
for (OsmRelationMember member : OsmModelUtil
.membersAsList(relation)) {
if (member.getType() != EntityType.Relation) {
continue;
}
long id = member.getId();
if (ids.contains(id)) {
continue;
}
ids.add(id);
try {
OsmRelation child = this.entityProvider.getRelation(id);
outRelations.add(child);
queue.add(child);
} catch (EntityNotFoundException e) {
// ignore silently
}
}
}
}
示例8: findMemberRelationsRecursively
import gnu.trove.set.TLongSet; //导入方法依赖的package包/类
private void findMemberRelationsRecursively(Deque<OsmRelation> queue,
Set<OsmRelation> outRelations) {
TLongSet ids = new TLongHashSet();
while (!queue.isEmpty()) {
OsmRelation relation = queue.remove();
for (OsmRelationMember member : OsmModelUtil
.membersAsList(relation)) {
if (member.getType() != EntityType.Relation) {
continue;
}
long id = member.getId();
if (ids.contains(id)) {
continue;
}
ids.add(id);
try {
OsmRelation child = this.entityProvider.getRelation(id);
outRelations.add(child);
queue.add(child);
} catch (EntityNotFoundException e) {
this.logRelationNotFound(id);
}
}
}
}
示例9: computeRemoveBlockLight
import gnu.trove.set.TLongSet; //导入方法依赖的package包/类
private void computeRemoveBlockLight(Vector3i loc, byte currentLight, Queue<LightRemoveData> removalQueue, Queue<Vector3i> spreadQueue, TLongSet removalVisited, TLongSet spreadVisited) {
if (loc.getY() >= 256) {
return;
}
ChunkSection section = getOrCreateSection(loc.getY() / 16);
byte presentLight = section.getBlockLight(loc.getX(), loc.getY() % 16, loc.getZ());
long idx = xyzIdx(loc.getX(), loc.getY(), loc.getZ());
if (presentLight != 0 && presentLight < currentLight) {
section.setBlockLight(loc.getX(), loc.getY() % 16, loc.getZ(), (byte) 0);
if (removalVisited.add(idx)) {
if (presentLight > 1) {
removalQueue.add(new LightRemoveData(loc, presentLight));
}
}
} else if (presentLight >= currentLight) {
if (spreadVisited.add(idx)) {
spreadQueue.add(loc);
}
}
}
示例10: computeSpreadBlockLight
import gnu.trove.set.TLongSet; //导入方法依赖的package包/类
private void computeSpreadBlockLight(Vector3i loc, byte currentLight, Queue<Vector3i> spreadQueue, TLongSet spreadVisited) {
if (loc.getY() >= 256) {
return;
}
ChunkSection section = getOrCreateSection(loc.getY() / 16);
byte presentLight = section.getBlockLight(loc.getX(), loc.getY() % 16, loc.getZ());
long idx = xyzIdx(loc.getX(), loc.getY(), loc.getZ());
if (presentLight < currentLight) {
section.setBlockLight(loc.getX(), loc.getY() % 16, loc.getZ(), currentLight);
if (spreadVisited.add(idx)) {
if (presentLight > 1) {
spreadQueue.add(loc);
}
}
}
}
示例11: encodePosSet
import gnu.trove.set.TLongSet; //导入方法依赖的package包/类
public static TLongSet encodePosSet(Collection<?> vectors) {
TLongSet encoded = new TLongHashSet(vectors.size());
for(Object o : vectors) {
if(o instanceof BlockVector) {
encoded.add(encodePos((BlockVector) o));
}
}
return encoded;
}
示例12: testValueCollectionContainsAll
import gnu.trove.set.TLongSet; //导入方法依赖的package包/类
public void testValueCollectionContainsAll() {
int[] keys = {1138, 42, 86, 99, 101, 727, 117};
long[] vals = new long[keys.length];
TIntLongMap map = new TIntLongHashMap();
for ( int i = 0; i < keys.length; i++ ) {
vals[i] = keys[i] * 2;
map.put( keys[i], vals[i] );
}
TLongCollection values = map.valueCollection();
assertEquals( map.size(), values.size() );
assertFalse( values.isEmpty() );
// test with a java.util.Map
Set<Number> java_set = new HashSet<Number>();
for ( int i = 0; i < vals.length; i++ ) {
java_set.add( Long.valueOf( vals[i] ) );
}
assertTrue( values.containsAll( java_set ) );
java_set.add( Integer.valueOf( 12 ) );
assertFalse( values.containsAll( java_set ) );
java_set.remove( Integer.valueOf( 12 ) );
assertTrue( values.containsAll( java_set ) );
java_set.add( Long.valueOf( 12 ) );
assertFalse( values.containsAll( java_set ) );
// test with a TCollection
TLongSet tintset = new TLongHashSet( vals );
assertTrue( values.containsAll( tintset ) );
tintset.add( 12 );
assertFalse( values.containsAll( tintset ) );
// test raw array
assertTrue( values.containsAll( vals ) );
vals[3] = vals[3] + 1;
assertFalse( values.containsAll( vals ) );
}
示例13: testValueCollectionContainsAll
import gnu.trove.set.TLongSet; //导入方法依赖的package包/类
public void testValueCollectionContainsAll() {
int[] keys = {1138, 42, 86, 99, 101, 727, 117};
long[] vals = new long[keys.length];
TIntLongMap map = new TIntLongOffheapHashMap();
for ( int i = 0; i < keys.length; i++ ) {
vals[i] = keys[i] * 2;
map.put( keys[i], vals[i] );
}
TLongCollection values = map.valueCollection();
assertEquals( map.size(), values.size() );
assertFalse( values.isEmpty() );
// test with a java.util.Map
Set<Number> java_set = new HashSet<Number>();
for ( int i = 0; i < vals.length; i++ ) {
java_set.add( Long.valueOf( vals[i] ) );
}
assertTrue( values.containsAll( java_set ) );
java_set.add( Integer.valueOf( 12 ) );
assertFalse( values.containsAll( java_set ) );
java_set.remove( Integer.valueOf( 12 ) );
assertTrue( values.containsAll( java_set ) );
java_set.add( Long.valueOf( 12 ) );
assertFalse( values.containsAll( java_set ) );
// test with a TCollection
TLongSet tintset = new TLongHashSet( vals );
assertTrue( values.containsAll( tintset ) );
tintset.add( 12 );
assertFalse( values.containsAll( tintset ) );
// test raw array
assertTrue( values.containsAll( vals ) );
vals[3] = vals[3] + 1;
assertFalse( values.containsAll( vals ) );
}
示例14: read
import gnu.trove.set.TLongSet; //导入方法依赖的package包/类
public static InMemorySetIdDataSet read(OsmIdIterator iterator)
throws IOException {
InMemorySetIdDataSet dataSet = new InMemorySetIdDataSet();
TLongSet nodeIds = dataSet.getNodeIds();
TLongSet wayIds = dataSet.getWayIds();
TLongSet relationIds = dataSet.getRelationIds();
if (iterator.hasBounds()) {
dataSet.setBounds(iterator.getBounds());
}
while (iterator.hasNext()) {
IdContainer container = iterator.next();
switch (container.getType()) {
case Node:
nodeIds.add(container.getId());
break;
case Way:
wayIds.add(container.getId());
break;
case Relation:
relationIds.add(container.getId());
break;
}
}
return dataSet;
}
示例15: benchmarkItemMostSimilar
import gnu.trove.set.TLongSet; //导入方法依赖的package包/类
public void benchmarkItemMostSimilar() throws ConfigurationException, DaoException {
System.out.println("Start ItemMostSimilar");
long start = System.currentTimeMillis();
for (Item item : items) {
TLongSet set = new TLongHashSet();
SimilarResultList<Item> list = iSim.mostSimilar(item, MAX_RESULTS);
for (SimilarResult<Item> result : list) {
set.add(result.getLongId());
}
}
long end = System.currentTimeMillis();
System.out.println("Ellapsed time: " + (end-start));
System.out.println("Unit time: " + (end-start)/SIZE);
}