Пример #1
0
 static int getEstimatedSize(RouteDataObject o) {
   // calculate size
   int sz = 0;
   sz += 8 + 4; // overhead
   if (o.names != null) {
     sz += 12;
     TIntObjectIterator<String> it = o.names.iterator();
     while (it.hasNext()) {
       it.advance();
       String vl = it.value();
       sz += 12 + vl.length();
     }
     sz += 12 + o.names.size() * 25;
   }
   sz += 8; // id
   // coordinates
   sz += (8 + 4 + 4 * o.getPointsLength()) * 4;
   sz += o.types == null ? 4 : (8 + 4 + 4 * o.types.length);
   sz += o.restrictions == null ? 4 : (8 + 4 + 8 * o.restrictions.length);
   sz += 4;
   if (o.pointTypes != null) {
     sz += 8 + 4 * o.pointTypes.length;
     for (int i = 0; i < o.pointTypes.length; i++) {
       sz += 4;
       if (o.pointTypes[i] != null) {
         sz += 8 + 8 * o.pointTypes[i].length;
       }
     }
   }
   // Standard overhead?
   return (int) (sz * 3.5);
 }
 /* (non-Javadoc)
  * @see org.excitement.distsim.storage.CountableIdentifiableStorage#resetCounts()
  */
 @Override
 public void resetCounts() {
   TIntObjectIterator<T> it = id2item.iterator();
   while (it.hasNext()) {
     it.advance();
     it.value().setCount(0);
   }
 }
Пример #3
0
 /**
  * Replaces the contents of this vertex data by the provided one. This is a deep copy. The vertex
  * attribute are each individually cloned.
  *
  * @param data The data to copy.
  */
 public void copy(VertexData data) {
   clear();
   indices.addAll(data.indices);
   final TIntObjectIterator<VertexAttribute> iterator = data.attributes.iterator();
   while (iterator.hasNext()) {
     iterator.advance();
     attributes.put(iterator.key(), iterator.value().clone());
   }
   nameToIndex.putAll(data.nameToIndex);
 }
Пример #4
0
  public void run() {
    int total = 0;

    for (int i = 0; i < 5; i++) {
      TIntObjectIterator<Integer> iterator = map.iterator();
      while (iterator.hasNext()) {
        iterator.advance();
        total += iterator.key();
      }
    }
  }
  public static void main(String[] args) {

    if (args.length != 2) {
      System.err.println(
          "Usage: MemoryBasedLeft2Right <in score file> <out aggregated scores redis file>");
      System.exit(0);
    }

    String infile = args[0];
    String redisSimilarityFile = args[1];

    try {

      BufferedReader reader = new BufferedReader(new FileReader(new File(infile)));
      String line;
      TIntObjectMap<TIntDoubleMap> scoresMap = new TIntObjectHashMap<TIntDoubleMap>();

      while ((line = reader.readLine()) != null) {
        String[] toks = line.split("\t");

        int id1 = Integer.parseInt(toks[0]);
        int id2 = Integer.parseInt(toks[1]);
        double score = Double.parseDouble(toks[2]);
        TIntDoubleMap scores = scoresMap.get(id1);
        if (scores == null) {
          scores = new TIntDoubleHashMap();
          scoresMap.put(id1, scores);
        }
        scores.put(id2, score);
      }
      reader.close();

      RedisBasedIDKeyPersistentBasicMap<LinkedHashMap<Integer, Double>> redis =
          new RedisBasedIDKeyPersistentBasicMap<LinkedHashMap<Integer, Double>>(
              redisSimilarityFile, false);
      redis.clear();
      TIntObjectIterator<TIntDoubleMap> it = scoresMap.iterator();
      while (it.hasNext()) {
        it.advance();
        int id1 = it.key();
        TIntDoubleMap scores = it.value();
        redis.put(id1, SortUtil.sortMapByValue(scores, true));
      }

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Пример #6
0
 @Override
 public boolean initialisationComplete(
     TIndexedCollection<DAGNode> nodes, TIndexedCollection<DAGEdge> edges, boolean forceRebuild) {
   if (taggedNodes_ == null) {
     taggedNodes_ = MultiMap.createSortedSetMultiMap();
     TIntObjectIterator<DAGNode> iter = nodes.iterator();
     for (int i = nodes.size(); i-- > 0; ) {
       iter.advance();
       DAGNode n = iter.value();
       String[] props = n.getProperties();
       for (String prop : props) {
         if (prop.startsWith(TAG_PREFIX)) {
           taggedNodes_.put(prop, n);
         }
       }
     }
   }
   return super.initialisationComplete(nodes, edges, forceRebuild);
 }
 protected void dumpMap() {
   try {
     tmpFileIndex++;
     String outfile = tmpDIR + "/" + tmpFileIndex + ".tmp";
     logger.info("dumping memory to file: " + outfile);
     PrintStream tmpContentFile = new PrintStream(outfile);
     TIntObjectIterator<T> it = id2item.iterator();
     while (it.hasNext()) {
       it.advance();
       T item = it.value();
       tmpContentFile.print(item.getID());
       tmpContentFile.print("\t");
       tmpContentFile.print(Serialization.serialize(item));
       tmpContentFile.print("\n");
       it.remove();
     }
     tmpContentFile.close();
   } catch (Exception e) {
     logger.error(e.toString());
   }
 }
  public void randomize() {
    for (TIntObjectIterator<int[]> it = offsets.iterator(); it.hasNext(); ) {
      it.advance();
      int[] newVal = new int[it.value().length];

      RaptorWorkerTimetable tt = data.timetablesForPattern.get(it.key());

      for (int i = 0; i < newVal.length; i++) {
        newVal[i] = mt.nextInt(tt.headwaySecs[i]);
      }

      it.setValue(newVal);
    }
  }