Package gnu.trove.set

Examples of gnu.trove.set.TIntSet


        assertEquals(set, deserialized);
    }


    public void testToArray() {
        TIntSet set = new TIntHashSet();
        int[] ints = {42, 1138, 13, 86, 99};
        set.addAll(ints);
        int[] res = set.toArray();
        Arrays.sort(ints);
        Arrays.sort(res);
        assertTrue(Arrays.equals(ints, res));
    }
View Full Code Here


        assertTrue(Arrays.equals(ints, res));
    }


    public void testToArrayMatchesIteratorOrder() {
        TIntSet set = new TIntHashSet();
        int[] ints = {42, 1138, 13, 86, 99};
        set.addAll(ints);
        int[] toarray_ints = set.toArray();

        int[] iter_ints = new int[5];
        TIntIterator iter = set.iterator();

        int index = 0;
        while (iter.hasNext()) {
            iter_ints[index++] = iter.next();
        }
View Full Code Here

    }


    public void testToArrayWithParams() {
        int no_entry_value = Integer.MIN_VALUE;
        TIntSet set = new TIntHashSet(10, 0.5f, no_entry_value);
        assertEquals(no_entry_value, set.getNoEntryValue());

        int[] ints = {42, 1138, 13, 86, 99};
        set.addAll(ints);

        int[] sink = new int[ints.length + 2];
        sink[sink.length - 1] = -1;
        sink[sink.length - 2] = -2;

        int[] res = set.toArray(sink);
        assertEquals(set.getNoEntryValue(), res[set.size()]);

        Set<Integer> copy = new HashSet<Integer>();
        for (int element : sink) {
            copy.add(Integer.valueOf(element));
        }
View Full Code Here

    }


    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);
    }
View Full Code Here

    }


    public void testIterator() {

        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(Integer.valueOf(next).toString(),
                    next >= 1 && next <= 4);
            assertTrue(Integer.valueOf(next).toString(), next != last);
            last = next;
        }

        assertFalse("iterator should not have a next item", iter.hasNext());

        assertTrue("set should contain 1", set.contains(1));
        assertTrue("set should contain 2", set.contains(2));
        assertTrue("set should contain 3", set.contains(3));
        assertTrue("set should contain 4", set.contains(4));
        assertEquals(4, set.size());
    }
View Full Code Here

  }


  public void testUnmodifiableSet() {
    final TIntSet one = new TIntHashSet( new int[]{ 1, 2, 3, 4 } );
    final TIntSet two = new TIntHashSet( new int[]{ 1, 2, 3, 4 } );
    TIntSet uOne = TCollections.unmodifiableSet( one );
    TIntSet uTwo = TCollections.unmodifiableSet( two );

    assertEquals( one, two );
    assertEquals( uOne, uTwo );
  }
View Full Code Here

        }

        @Override
        public void submit(TIntSet removed, TIntSet added) {
            insureInitialized();
            TIntSet parentRemoved = null, parentAdded;
            //Calculating really removed indices set
            TIntIterator iterator = removed.iterator();
            int iIndex, index;
            while (iterator.hasNext()) {
                iIndex = Arrays.binarySearch(allDummyIndices, index = iterator.next());
                usedArrays[iIndex].clear(position.currentIndex());

                if (usedArrays[iIndex].bitCount() == 0) {
                    if (parentRemoved == null)
                        parentRemoved = new TIntHashSet(removed.size());
                    parentRemoved.add(index);
                }
            }
            if (parentRemoved == null)
                parentRemoved = EMPTY_INT_SET;
View Full Code Here

                if (!(pn instanceof ParseTokenScalarFunction))
                    getAllIndices1(pn, set);
    }

    public static TIntSet getAllIndicesT(ParseToken node) {
        TIntSet set = new TIntHashSet();
        getAllIndicesT1(node, set);
        return set;
    }
View Full Code Here

  }

  @Override
  @SuppressWarnings("unchecked")
  public TIntSet getRXNORMCuis() {
    TIntSet cuis = new TIntHashSet();
    for (String cui : (List<String>) sessionFactory.getCurrentSession()
        .getNamedQuery("getRXNORMCuis").list()) {
      Matcher m = UMLSDao.cuiPattern.matcher(cui);
      if (m.find()) {
        cuis.add(Integer.parseInt(m.group(1)));
      }
    }
    return cuis;
  }
View Full Code Here

    SoftReference<TIntSet> refLeaves = leafCache[concept.getNodeIndex()];
    if (refLeaves != null && refLeaves.get() != null) {
      return refLeaves.get();
    }
    // not in cache - compute recursively
    TIntSet leaves = new TIntHashSet();
    leafCache[concept.getNodeIndex()] = new SoftReference<TIntSet>(leaves);
    if (concept.isLeaf()) {
      // for leaves, just add the concept id
      leaves.add(concept.getNodeIndex());
    } else {
      IntrinsicICInfo icInfo = icInfoMap.get(concept.getConceptID());
      // have we already computed the leaf count for this node?
      // if yes, then we can ignore previously visited nodes
      // if no, then compute it now and revisit previously visited nodes
      // if we have to
      boolean needLeaves = (icInfo != null && icInfo.getLeafCount() == 0);
      TIntSet visitedNodesLocal = visitedNodes;
      if (needLeaves || visitedNodesLocal == null) {
        // allocate a set to keep track of nodes we've already visited
        // so that we don't revisit them. if we have already computed
        // this node's leaf count then we reuse whatever the caller gave
        // us if non null, else allocate a new one.
        // if we haven't already computed this node's leaf count,
        // allocate a new set to avoid duplications in the traversal for
        // this node
        visitedNodesLocal = new TIntHashSet();
      }
      // for inner nodes, recurse
      for (ConcRel child : concept.getChildren()) {
        // if we've already visited a node, then don't bother adding
        // that node's leaves - we already have them
        if (!visitedNodesLocal.contains(child.getNodeIndex())) {
          leaves.addAll(getLeaves(child, leafCache, icInfoMap, cg, w,
              visitedNodesLocal));
        }
      }
      // add this node to the set of visited nodes so we know not to
View Full Code Here

TOP

Related Classes of gnu.trove.set.TIntSet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.