Examples of IntArrayList


Examples of it.unimi.dsi.fastutil.ints.IntArrayList

   * @param vals
   * @return the array of order indices of the values.
   */
  public static <T> int[] convert(FacetDataCache<T> dataCache, T[] vals) {
    if (vals != null && (vals instanceof String[])) return convertString(dataCache, (String[]) vals);
    IntList list = new IntArrayList(vals.length);
    for (int i = 0; i < vals.length; ++i) {
      int index = dataCache.valArray.indexOfWithType(vals[i]);
      if (index >= 0) {
        list.add(index);
      }
    }
    return list.toIntArray();
  }
View Full Code Here

Examples of it.unimi.dsi.fastutil.ints.IntArrayList

    BufferedLoader loader = getBufferedLoader(maxdoc, workArea);

    @SuppressWarnings("unchecked")
    TermValueList<T> list = (listFactory == null ? (TermValueList<T>) new TermStringList()
        : listFactory.createTermList());
    IntArrayList minIDList = new IntArrayList();
    IntArrayList maxIDList = new IntArrayList();
    IntArrayList freqList = new IntArrayList();
    OpenBitSet bitset = new OpenBitSet(maxdoc + 1);
    int negativeValueCount = getNegativeValueCount(reader, field);
    int t = 1; // valid term id starts from 1
    list.add(null);
    minIDList.add(-1);
    maxIDList.add(-1);
    freqList.add(0);

    _overflow = false;

    Terms terms = reader.terms(field);
    if (terms != null) {
      TermsEnum termsEnum = terms.iterator(null);
      BytesRef text;
      while ((text = termsEnum.next()) != null) {
        String strText = text.utf8ToString();
        list.add(strText);

        Term term = new Term(field, strText);
        DocsEnum docsEnum = reader.termDocsEnum(term);
        int df = 0;
        int minID = -1;
        int maxID = -1;
        int docID = -1;
        int valId = (t - 1 < negativeValueCount) ? (negativeValueCount - t + 1) : t;
        while ((docID = docsEnum.nextDoc()) != DocsEnum.NO_MORE_DOCS) {
          df++;
          if (!loader.add(docID, valId)) logOverflow(fieldName);
          minID = docID;
          bitset.fastSet(docID);
          while (docsEnum.nextDoc() != DocsEnum.NO_MORE_DOCS) {
            docID = docsEnum.docID();
            df++;
            if (!loader.add(docID, valId)) logOverflow(fieldName);
            bitset.fastSet(docID);
          }
          maxID = docID;
        }
        freqList.add(df);
        minIDList.add(minID);
        maxIDList.add(maxID);
        t++;
      }
    }

    list.seal();
    // Process minIDList and maxIDList for negative number
    for (int i = 1; i < negativeValueCount/2 + 1; ++i) {
      int top = i;
      int tail = negativeValueCount - i + 1;
      int topValue = minIDList.getInt(top);
      int tailValue = minIDList.getInt(tail);
      minIDList.set(top, tailValue);
      minIDList.set(tail, topValue);
      topValue = maxIDList.getInt(top);
      tailValue = maxIDList.getInt(tail);
      maxIDList.set(top, tailValue);
      maxIDList.set(tail, topValue);
    }

    try {
      _nestedArray.load(maxdoc + 1, loader);
    } catch (IOException e) {
      throw e;
    } catch (Exception e) {
      throw new RuntimeException("failed to load due to " + e.toString(), e);
    }

    this.valArray = list;
    this.freqs = freqList.toIntArray();
    this.minIDs = minIDList.toIntArray();
    this.maxIDs = maxIDList.toIntArray();

    int doc = 0;
    while (doc < maxdoc && !_nestedArray.contains(doc, 0, true)) {
View Full Code Here

Examples of it.unimi.dsi.fastutil.ints.IntArrayList

    }

    @SuppressWarnings("unchecked")
    TermValueList<T> list = (listFactory == null ? (TermValueList<T>) new TermStringList()
        : listFactory.createTermList());
    IntArrayList minIDList = new IntArrayList();
    IntArrayList maxIDList = new IntArrayList();
    IntArrayList freqList = new IntArrayList();
    OpenBitSet bitset = new OpenBitSet(maxdoc + 1);

    int t = 1; // valid term id starts from 1
    list.add(null);
    minIDList.add(-1);
    maxIDList.add(-1);
    freqList.add(0);

    _overflow = false;

    Terms terms = reader.terms(field);
    if (terms != null) {
      TermsEnum termsEnum = terms.iterator(null);
      BytesRef text;
      while ((text = termsEnum.next()) != null) {
        String strText = text.utf8ToString();
        list.add(strText);

        Term term = new Term(field, strText);
        DocsEnum docsEnum = reader.termDocsEnum(term);

        int df = 0;
        int minID = -1;
        int maxID = -1;
        int docID = -1;
        while ((docID = docsEnum.nextDoc()) != DocsEnum.NO_MORE_DOCS) {
          df++;
          if (!_nestedArray.addData(docID, t)) logOverflow(fieldName);
          minID = docID;
          bitset.fastSet(docID);
          int valId = (t - 1 < negativeValueCount) ? (negativeValueCount - t + 1) : t;
          while (docsEnum.nextDoc() != DocsEnum.NO_MORE_DOCS) {
            docID = docsEnum.docID();
            df++;
            if (!_nestedArray.addData(docID, valId)) logOverflow(fieldName);
            bitset.fastSet(docID);
          }
          maxID = docID;
        }
        freqList.add(df);
        minIDList.add(minID);
        maxIDList.add(maxID);
        t++;
      }
    }

    list.seal();
    // Process minIDList and maxIDList for negative number
    for (int i = 1; i < negativeValueCount/2 + 1; ++i) {
      int top = i;
      int tail = negativeValueCount - i + 1;
      int topValue = minIDList.getInt(top);
      int tailValue = minIDList.getInt(tail);
      minIDList.set(top, tailValue);
      minIDList.set(tail, topValue);
      topValue = maxIDList.getInt(top);
      tailValue = maxIDList.getInt(tail);
      maxIDList.set(top, tailValue);
      maxIDList.set(tail, topValue);
    }

    this.valArray = list;
    this.freqs = freqList.toIntArray();
    this.minIDs = minIDList.toIntArray();
    this.maxIDs = maxIDList.toIntArray();

    int doc = 0;
    while (doc < maxdoc && !_nestedArray.contains(doc, 0, true)) {
View Full Code Here

Examples of jodd.util.collection.IntArrayList

    }
  }

  public void setNull(String param, int type) {
    init();
    IntArrayList positions = query.getNamedParameterIndices(param);
    try {
      for (int i = 0; i < positions.size(); i++) {
        preparedStatement.setNull(positions.get(i), type);
      }
    } catch (SQLException sex) {
      throw new DbSqlException(this, "Failed to set null to parameter: " + param, sex);
    }
View Full Code Here

Examples of org.apache.flink.runtime.util.IntArrayList

      }
      int hashOffset = 0;
      int hash = 0;
      int pointerOffset = 0;
      long pointer = 0;
      IntArrayList hashList = new IntArrayList(NUM_ENTRIES_PER_BUCKET);
      LongArrayList pointerList = new LongArrayList(NUM_ENTRIES_PER_BUCKET);
      IntArrayList overflowHashes = new IntArrayList(64);
      LongArrayList overflowPointers = new LongArrayList(64);
      // go over all buckets and split them between old and new buckets
      for(int i = 0; i < numPartitions; i++) {
        InMemoryPartition<T> partition = this.partitions.get(i);
        final MemorySegment[] overflowSegments = partition.overflowSegments;
        int posHashCode = 0;
        for (int j = 0, bucket = i; j < this.buckets.length && bucket < oldNumBuckets; j++) {
          MemorySegment segment = this.buckets[j];
          // go over all buckets in the segment belonging to the partition
          for (int k = bucket % bucketsPerSegment; k < bucketsPerSegment && bucket < oldNumBuckets; k += numPartitions, bucket += numPartitions) {
            int bucketOffset = k * HASH_BUCKET_SIZE;
            if((int)segment.get(bucketOffset + HEADER_PARTITION_OFFSET) != i) {
              throw new IOException("Accessed wrong bucket! wanted: " + i + " got: " + segment.get(bucketOffset + HEADER_PARTITION_OFFSET));
            }
            // loop over all segments that are involved in the bucket (original bucket plus overflow buckets)
            int countInSegment = segment.getInt(bucketOffset + HEADER_COUNT_OFFSET);
            int numInSegment = 0;
            pointerOffset = bucketOffset + BUCKET_POINTER_START_OFFSET;
            hashOffset = bucketOffset + BUCKET_HEADER_LENGTH;
            while (true) {
              while (numInSegment < countInSegment) {
                hash = segment.getInt(hashOffset);
                if((hash % this.numBuckets) != bucket && (hash % this.numBuckets) != (bucket+oldNumBuckets)) {
                  throw new IOException("wanted: " + bucket + " or " + (bucket + oldNumBuckets) + " got: " + hash%this.numBuckets);
                }
                pointer = segment.getLong(pointerOffset);
                hashList.add(hash);
                pointerList.add(pointer);
                pointerOffset += POINTER_LEN;
                hashOffset += HASH_CODE_LEN;
                numInSegment++;
              }
              // this segment is done. check if there is another chained bucket
              final long forwardPointer = segment.getLong(bucketOffset + HEADER_FORWARD_OFFSET);
              if (forwardPointer == BUCKET_FORWARD_POINTER_NOT_SET) {
                break;
              }
              final int overflowSegNum = (int) (forwardPointer >>> 32);
              segment = overflowSegments[overflowSegNum];
              bucketOffset = (int)(forwardPointer & 0xffffffff);
              countInSegment = segment.getInt(bucketOffset + HEADER_COUNT_OFFSET);
              pointerOffset = bucketOffset + BUCKET_POINTER_START_OFFSET;
              hashOffset = bucketOffset + BUCKET_HEADER_LENGTH;
              numInSegment = 0;
            }
            segment = this.buckets[j];
            bucketOffset = k * HASH_BUCKET_SIZE;
            // reset bucket for re-insertion
            segment.putInt(bucketOffset + HEADER_COUNT_OFFSET, 0);
            segment.putLong(bucketOffset + HEADER_FORWARD_OFFSET, BUCKET_FORWARD_POINTER_NOT_SET);
            // refill table
            if(hashList.size() != pointerList.size()) {
              throw new IOException("Pointer and hash counts do not match. hashes: " + hashList.size() + " pointer: " + pointerList.size());
            }
            int newSegmentIndex = (bucket + oldNumBuckets) / bucketsPerSegment;
            MemorySegment newSegment = this.buckets[newSegmentIndex];
            // we need to avoid overflows in the first run
            int oldBucketCount = 0;
            int newBucketCount = 0;
            while(!hashList.isEmpty()) {
              hash = hashList.removeInt(hashList.size()-1);
              pointer = pointerList.removeLong(pointerList.size()-1);
              posHashCode = hash % this.numBuckets;
              if(posHashCode == bucket && oldBucketCount < NUM_ENTRIES_PER_BUCKET) {
                bucketOffset = (bucket % bucketsPerSegment) * HASH_BUCKET_SIZE;
                insertBucketEntryFromStart(partition, segment, bucketOffset, hash, pointer);
                oldBucketCount++;
              } else if(posHashCode == (bucket + oldNumBuckets) && newBucketCount < NUM_ENTRIES_PER_BUCKET) {
                bucketOffset = ((bucket + oldNumBuckets) % bucketsPerSegment) * HASH_BUCKET_SIZE;
                insertBucketEntryFromStart(partition, newSegment, bucketOffset, hash, pointer);
                newBucketCount++;
              } else if(posHashCode == (bucket + oldNumBuckets) || posHashCode == bucket) {
                overflowHashes.add(hash);
                overflowPointers.add(pointer);
              } else {
                throw new IOException("Accessed wrong bucket. Target: " + bucket + " or " + (bucket + oldNumBuckets) + " Hit: " + posHashCode);
              }
            }
            hashList.clear();
            pointerList.clear();
          }
        }
        // reset partition's overflow buckets and reclaim their memory
        this.availableMemory.addAll(partition.resetOverflowBuckets());
        // clear overflow lists
        int bucketArrayPos = 0;
        int bucketInSegmentPos = 0;
        MemorySegment bucket = null;
        while(!overflowHashes.isEmpty()) {
          hash = overflowHashes.removeInt(overflowHashes.size()-1);
          pointer = overflowPointers.removeLong(overflowPointers.size()-1);
          posHashCode = hash % this.numBuckets;
          bucketArrayPos = posHashCode >>> this.bucketsPerSegmentBits;
          bucketInSegmentPos = (posHashCode & this.bucketsPerSegmentMask) << NUM_INTRA_BUCKET_BITS;
          bucket = this.buckets[bucketArrayPos];
          insertBucketEntryFromStart(partition, bucket, bucketInSegmentPos, hash, pointer);
        }
        overflowHashes.clear();
        overflowPointers.clear();
      }
      this.isResizing = false;
      return true;
    }
View Full Code Here

Examples of org.apache.mahout.math.list.IntArrayList

    }
   
    Map<String,Long> gList = PFPGrowth.deserializeMap(params, "gList", context.getConfiguration());
   
    for (Entry<String,Long> entry : gList.entrySet()) {
      IntArrayList groupList = groupFeatures.get(entry.getValue());
      Integer itemInteger = fMap.get(entry.getKey());
      if (groupList != null) {
        groupList.add(itemInteger);
      } else {
        groupList = new IntArrayList();
        groupList.add(itemInteger);
        groupFeatures.put(entry.getValue(), groupList);
      }
     
    }
    maxHeapSize = Integer.valueOf(params.get("maxHeapSize", "50"));
View Full Code Here

Examples of org.apache.mahout.math.list.IntArrayList

  public void setQuick(int row, int column, double value) {
    int i = row;
    int j = column;

    int k = -1;
    IntArrayList indexList = indexes[i];
    if (indexList != null) {
      k = indexList.binarySearch(j);
    }

    if (k >= 0) { // found
      if (value == 0) {
        DoubleArrayList valueList = values[i];
        indexList.remove(k);
        valueList.remove(k);
        int s = indexList.size();
        if (s > 2 && s * 3 < indexList.elements().length) {
          indexList.setSize(s * 3 / 2);
          indexList.trimToSize();
          indexList.setSize(s);

          valueList.setSize(s * 3 / 2);
          valueList.trimToSize();
          valueList.setSize(s);
        }
      } else {
        values[i].setQuick(k, value);
      }
    } else { // not found
      if (value == 0) {
        return;
      }

      k = -k - 1;

      if (indexList == null) {
        indexes[i] = new IntArrayList(3);
        values[i] = new DoubleArrayList(3);
      }
      indexes[i].beforeInsert(k, j);
      values[i].beforeInsert(k, value);
    }
View Full Code Here

Examples of org.apache.mahout.math.list.IntArrayList

  /** Not yet commented. */
  public static void test(int weight, int size) {
    WeightedRandomSampler sampler = new WeightedRandomSampler();
    sampler.setWeight(weight);

    IntArrayList sample = new IntArrayList();
    for (int i = 0; i < size; i++) {
      if (sampler.sampleNextElement()) {
        sample.add(i);
      }
    }
  }
View Full Code Here

Examples of org.apache.mahout.math.list.IntArrayList

   *
   * @param condition The condition to be matched.
   * @return the new view.
   */
  public DoubleMatrix1D viewSelection(DoubleProcedure condition) {
    IntArrayList matches = new IntArrayList();
    for (int i = 0; i < size; i++) {
      if (condition.apply(getQuick(i))) {
        matches.add(i);
      }
    }
    matches.trimToSize();
    return viewSelection(matches.elements());
  }
View Full Code Here

Examples of org.apache.mahout.math.list.IntArrayList

   *
   * @param condition The condition to be matched.
   * @return the new view.
   */
  public DoubleMatrix3D viewSelection(DoubleMatrix2DProcedure condition) {
    IntArrayList matches = new IntArrayList();
    for (int i = 0; i < slices; i++) {
      if (condition.apply(viewSlice(i))) {
        matches.add(i);
      }
    }

    matches.trimToSize();
    return viewSelection(matches.elements(), null, null); // take all rows and columns
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.