本文整理匯總了Java中gnu.trove.set.TIntSet.add方法的典型用法代碼示例。如果您正苦於以下問題:Java TIntSet.add方法的具體用法?Java TIntSet.add怎麽用?Java TIntSet.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類gnu.trove.set.TIntSet
的用法示例。
在下文中一共展示了TIntSet.add方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: distinct
import gnu.trove.set.TIntSet; //導入方法依賴的package包/類
@Override
public final Array<Integer> distinct(int limit) {
final int capacity = limit < Integer.MAX_VALUE ? limit : 100;
final TIntSet set = new TIntHashSet(capacity);
final ArrayBuilder<Integer> builder = ArrayBuilder.of(capacity, Integer.class);
for (int i=0; i<length(); ++i) {
final int value = getInt(i);
if (set.add(value)) {
builder.addInt(value);
if (set.size() >= limit) {
break;
}
}
}
return builder.toArray();
}
示例2: distinct
import gnu.trove.set.TIntSet; //導入方法依賴的package包/類
@Override
public Array<T> distinct(int limit) {
final int capacity = limit < Integer.MAX_VALUE ? limit : 100;
final TIntSet set = new TIntHashSet(capacity);
final ArrayBuilder<T> builder = ArrayBuilder.of(capacity, type());
for (int i=0; i<length(); ++i) {
final int code = getInt(i);
if (set.add(code)) {
final T value = getValue(i);
builder.add(value);
if (set.size() >= limit) {
break;
}
}
}
return builder.toArray();
}
示例3: testEquals
import gnu.trove.set.TIntSet; //導入方法依賴的package包/類
public void testEquals() {
int[] ints = {1138, 42, 86, 99, 101};
TIntSet set = new TIntOffheapHashSet();
set.addAll(ints);
TIntSet other = new TIntOffheapHashSet();
other.addAll(ints);
assertTrue("sets incorrectly not equal: " + set + ", " + other,
set.equals(other));
int[] mismatched = {72, 49, 53, 1024, 999};
TIntSet unequal = new TIntOffheapHashSet();
unequal.addAll(mismatched);
assertFalse("sets incorrectly equal: " + set + ", " + unequal,
set.equals(unequal));
// Change length, different code branch
unequal.add(1);
assertFalse("sets incorrectly equal: " + set + ", " + unequal,
set.equals(unequal));
}
示例4: encodeMaterialSet
import gnu.trove.set.TIntSet; //導入方法依賴的package包/類
public static TIntSet encodeMaterialSet(Collection<?> materials) {
TIntSet set = new TIntHashSet(materials.size());
for(Object material : materials) {
if(material instanceof MaterialData) {
set.add(encodeMaterial((MaterialData) material));
}
}
return set;
}
示例5: testKeySetEqual
import gnu.trove.set.TIntSet; //導入方法依賴的package包/類
public void testKeySetEqual() {
int element_count = 20;
int[] keys = new int[element_count];
String[] vals = new String[element_count];
TIntObjectMap<String> map = new TIntObjectHashMap<String>();
for ( int i = 0; i < element_count; i++ ) {
keys[i] = i + 1;
vals[i] = Integer.toString( i + 1 );
map.put( keys[i], vals[i] );
}
assertEquals( element_count, map.size() );
TIntSet keyset = map.keySet();
for ( int i = 0; i < keyset.size(); i++ ) {
assertTrue( keyset.contains( keys[i] ) );
}
assertFalse( keyset.isEmpty() );
TIntSet other = new TIntHashSet();
other.addAll( keys );
assertTrue( "sets incorrectly not equal: " + keyset + ", " + other,
keyset.equals( other ) );
int[] mismatched = {72, 49, 53, 1024, 999};
TIntSet unequal = new TIntHashSet();
unequal.addAll( mismatched );
assertFalse( "sets incorrectly equal: " + keyset + ", " + unequal,
keyset.equals( unequal ) );
// Change length, different code branch
unequal.add( 1 );
assertFalse( "sets incorrectly equal: " + keyset + ", " + unequal,
keyset.equals( unequal ) );
//noinspection ObjectEqualsNull
assertFalse( keyset.equals( null ) );
}
示例6: testRemove
import gnu.trove.set.TIntSet; //導入方法依賴的package包/類
public void testRemove() throws Exception {
TIntSet set = new TIntHashSet();
set.add(1);
set.add(2);
assertTrue("One was not added", set.contains(1));
assertTrue("One was not removed", set.remove(1));
assertFalse("One was not removed", set.contains(1));
assertTrue("Two was also removed", set.contains(2));
}
示例7: testKeySetContainsAll
import gnu.trove.set.TIntSet; //導入方法依賴的package包/類
public void testKeySetContainsAll() {
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] );
}
TIntSet set = map.keySet();
assertEquals( map.size(), set.size() );
assertFalse( set.isEmpty() );
// test with a java.util.Map
Set<Number> java_set = new HashSet<Number>();
for ( int i = 0; i < keys.length; i++ ) {
java_set.add( Integer.valueOf( keys[i] ) );
}
assertTrue( set.containsAll( java_set ) );
java_set.add( Integer.valueOf( 12 ) );
assertFalse( set.containsAll( java_set ) );
java_set.remove( Integer.valueOf( 12 ) );
assertTrue( set.containsAll( java_set ) );
java_set.add( Long.valueOf( 12 ) );
assertFalse( set.containsAll( java_set ) );
// test with a TCollection
TIntSet tintset = new TIntHashSet( keys );
assertTrue( set.containsAll( tintset ) );
tintset.add( 12 );
assertFalse( set.containsAll( tintset ) );
// test raw array
assertTrue( set.containsAll( keys ) );
keys[3] = keys[3] + 1;
assertFalse( set.containsAll( keys ) );
}
示例8: testKeySetEquals
import gnu.trove.set.TIntSet; //導入方法依賴的package包/類
public void testKeySetEquals() {
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] );
}
TIntSet set = map.keySet();
assertEquals( map.size(), set.size() );
assertFalse( set.isEmpty() );
TIntSet other = new TIntHashSet();
other.addAll( keys );
assertTrue( "sets incorrectly not equal: " + set + ", " + other,
set.equals( other ) );
int[] mismatched = {72, 49, 53, 1024, 999};
TIntSet unequal = new TIntHashSet();
unequal.addAll( mismatched );
assertFalse( "sets incorrectly equal: " + set + ", " + unequal,
set.equals( unequal ) );
// Change length, different code branch
unequal.add( 1 );
assertFalse( "sets incorrectly equal: " + set + ", " + unequal,
set.equals( unequal ) );
assertFalse( "set incorrectly equals a random object",
set.equals( new Object() ) );
}
示例9: testRehashing
import gnu.trove.set.TIntSet; //導入方法依賴的package包/類
public void testRehashing() throws Exception {
int size = 10000;
TIntSet set = new TIntHashSet( 10 );
for ( int i = 0; i < size; i++ ) {
set.add( i );
}
assertEquals( set.size(), size );
}
示例10: testKeySetEquals
import gnu.trove.set.TIntSet; //導入方法依賴的package包/類
public void testKeySetEquals() {
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] );
}
TIntSet set = map.keySet();
assertEquals( map.size(), set.size() );
assertFalse( set.isEmpty() );
TIntSet other = new TIntHashSet();
other.addAll( keys );
assertTrue( "sets incorrectly not equal: " + set + ", " + other,
set.equals( other ) );
int[] mismatched = {72, 49, 53, 1024, 999};
TIntSet unequal = new TIntHashSet();
unequal.addAll( mismatched );
assertFalse( "sets incorrectly equal: " + set + ", " + unequal,
set.equals( unequal ) );
// Change length, different code branch
unequal.add( 1 );
assertFalse( "sets incorrectly equal: " + set + ", " + unequal,
set.equals( unequal ) );
assertFalse( "set incorrectly equals a random object",
set.equals( new Object() ) );
}
示例11: testIsEmpty
import gnu.trove.set.TIntSet; //導入方法依賴的package包/類
public void testIsEmpty() throws Exception {
TIntSet s = new TIntHashSet();
assertTrue("new set wasn't empty", s.isEmpty());
s.add(1);
assertTrue("set with element reports empty", !s.isEmpty());
s.clear();
assertTrue("cleared set reports not-empty", s.isEmpty());
}
示例12: testRemove
import gnu.trove.set.TIntSet; //導入方法依賴的package包/類
public void testRemove() throws Exception {
TIntSet set = new TIntOffheapHashSet();
set.add(1);
set.add(2);
assertTrue("One was not added", set.contains(1));
assertTrue("One was not removed", set.remove(1));
assertFalse("One was not removed", set.contains(1));
assertTrue("Two was also removed", set.contains(2));
}
示例13: testRemoveNonExistant
import gnu.trove.set.TIntSet; //導入方法依賴的package包/類
public void testRemoveNonExistant() throws Exception {
TIntSet set = new TIntHashSet();
set.add(1);
set.add(2);
assertTrue("One was not added", set.contains(1));
assertTrue("One was not removed", set.remove(1));
assertFalse("One was not removed", set.contains(1));
assertTrue("Two was also removed", set.contains(2));
assertFalse("Three was removed (non-existant)", set.remove(3));
}
示例14: testIteratorRemove
import gnu.trove.set.TIntSet; //導入方法依賴的package包/類
public void testIteratorRemove() {
TIntSet set = new TIntHashSet();
set.add(1);
set.add(2);
set.add(3);
set.add(4);
TIntIterator iter = set.iterator();
assertTrue("iterator should have a next item", iter.hasNext());
int last = -1;
while (iter.hasNext()) {
int next = iter.next();
assertTrue(next >= 1 && next <= 4);
assertTrue(next != last);
last = next;
if (next == 3) {
iter.remove();
}
}
assertFalse("iterator should not have a next item", iter.hasNext());
assertFalse("set should not contain 3", set.contains(3));
assertTrue("set should contain 1", set.contains(1));
assertTrue("set should contain 2", set.contains(2));
assertTrue("set should contain 4", set.contains(4));
assertEquals(3, set.size());
}
示例15: testIteratorRemove
import gnu.trove.set.TIntSet; //導入方法依賴的package包/類
public void testIteratorRemove() {
TIntSet set = new TIntOffheapHashSet();
set.add(1);
set.add(2);
set.add(3);
set.add(4);
TIntIterator iter = set.iterator();
assertTrue("iterator should have a next item", iter.hasNext());
int last = -1;
while (iter.hasNext()) {
int next = iter.next();
assertTrue(next >= 1 && next <= 4);
assertTrue(next != last);
last = next;
if (next == 3) {
iter.remove();
}
}
assertFalse("iterator should not have a next item", iter.hasNext());
assertFalse("set should not contain 3", set.contains(3));
assertTrue("set should contain 1", set.contains(1));
assertTrue("set should contain 2", set.contains(2));
assertTrue("set should contain 4", set.contains(4));
assertEquals(3, set.size());
}