/** The longest dep set of the sub-sequence s[0..idx]. */
 public static BitSet longestDepSet(Sequence s, int idx) {
   if (s.size() == 0) throw new IllegalArgumentException("size must be greater than 0.");
   if (idx < 0 || idx >= s.size()) throw new IllegalArgumentException();
   assert s.size() <= maxlength;
   int max = -1;
   int maxidx = -1;
   for (int i = 0; i <= idx; i++) {
     BitSet set = sets[i];
     set.clear();
     set.set(i);
     lastuse[i] = i;
     for (Variable invar : s.getInputs(i)) {
       set.or(sets[lastuse[invar.index]]);
       lastuse[invar.index] = i;
     }
     int size = set.cardinality();
     if (size > max) {
       max = size;
       maxidx = i;
     }
   }
   for (int i = 0; i < s.size(); i++) {
     // System.out.println("@ " + sets[i]);
   }
   return sets[maxidx];
 }
 @Test
 public void testWithMarkupsNullAdditionalMarkups() {
   Sequence withMarkups = sequence.withMarkups(null);
   assertNotNull(withMarkups.getMarkups());
   assertEquals(1, withMarkups.getMarkups().size());
   assertEquals(24, withMarkups.getMarkups().get(0).getStart());
 }
 /**
  * Get the list of ids of sequences in this sequence database
  *
  * @return the list of sequence ids.
  */
 public Set<Integer> getSequenceIDs() {
   Set<Integer> set = new HashSet<Integer>();
   for (Sequence sequence : getSequences()) {
     set.add(sequence.getId());
   }
   return set;
 }
Esempio n. 4
0
  /**
   * @return all the id Sequences that are missing from this set that are not in between the range
   *     provided.
   */
  public List<Sequence> getMissing(long first, long last) {
    ArrayList<Sequence> rc = new ArrayList<Sequence>();
    if (first > last) {
      throw new IllegalArgumentException("First cannot be more than last");
    }
    if (isEmpty()) {
      // We are missing all the messages.
      rc.add(new Sequence(first, last));
      return rc;
    }

    Sequence sequence = getHead();
    while (sequence != null && first <= last) {
      if (sequence.contains(first)) {
        first = sequence.last + 1;
      } else {
        if (first < sequence.first) {
          if (last < sequence.first) {
            rc.add(new Sequence(first, last));
            return rc;
          } else {
            rc.add(new Sequence(first, sequence.first - 1));
            first = sequence.last + 1;
          }
        }
      }
      sequence = sequence.getNext();
    }

    if (first <= last) {
      rc.add(new Sequence(first, last));
    }
    return rc;
  }
  @Override
  public void addSequence(
      Sequence candidate,
      int candidateIndex,
      int depth,
      HashTreeNode father,
      ArrayList<Sequence> allCandidates) {
    candidateIndicesSize++;
    if (candidateIndicesSize > candidateIndices.length) {
      if (depth < candidate.size() - 1) {
        // exchange this leaf node by inner node if it could become inner node
        HashTreeInnerNode newInner = new HashTreeInnerNode();
        father.replaceNode(candidate.getItem(depth - 1), newInner);

        // and adding all sequences and last candidate
        for (int i = 0; i < candidateIndices.length; i++) {
          newInner.addSequence(
              allCandidates.get(candidateIndices[i]),
              candidateIndices[i],
              depth,
              father,
              allCandidates);
        }
        newInner.addSequence(
            allCandidates.get(candidateIndex), candidateIndex, depth, father, allCandidates);
      } else {
        int[] newIndices = new int[candidateIndices.length * 2];
        System.arraycopy(candidateIndices, 0, newIndices, 0, candidateIndices.length);
        candidateIndices = newIndices;
        candidateIndices[candidateIndicesSize - 1] = candidateIndex;
      }
    } else {
      candidateIndices[candidateIndicesSize - 1] = candidateIndex;
    }
  }
Esempio n. 6
0
    @Override
    public String getAccessibleName() {
      String name = super.getAccessibleName();

      if (seqs.size() > 0 && seqs.get(0).size > 0) {
        String keyValueList = "";
        for (Sequence seq : seqs) {
          if (seq.isPlotted) {
            String value = "null";
            if (seq.size > 0) {
              if (unit == Unit.BYTES) {
                value = Resources.format(Messages.SIZE_BYTES, seq.value(seq.size - 1));
              } else {
                value =
                    getFormattedValue(seq.value(seq.size - 1), false)
                        + ((unit == Unit.PERCENT) ? "%" : "");
              }
            }
            // Assume format string ends with newline
            keyValueList +=
                Resources.format(Messages.PLOTTER_ACCESSIBLE_NAME_KEY_AND_VALUE, seq.key, value);
          }
        }
        name += "\n" + keyValueList + ".";
      } else {
        name += "\n" + Messages.PLOTTER_ACCESSIBLE_NAME_NO_DATA;
      }
      return name;
    }
Esempio n. 7
0
  @Test
  public void testGetReadBucketEmpty() throws Exception {
    work = new File(System.getProperty("java.io.tmpdir", "."), "Puma");

    try {
      FileUtils.deleteDirectory(work);
    } catch (IOException e1) {
      e1.printStackTrace();
    }

    this.localBucketIndex.start();

    try {
      Bucket bucket = this.localBucketIndex.getReadBucket(-1, true);

      Assert.assertEquals(null, bucket);
      bucket = this.localBucketIndex.getReadBucket(-2, true);
      Assert.assertEquals(null, bucket);

      Sequence seq = new Sequence(120710, 0);
      bucket = this.localBucketIndex.getReadBucket(seq.longValue(), true);
      Assert.assertEquals(null, bucket);

    } catch (StorageClosedException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Esempio n. 8
0
 /*
  * Returns a parser that for the grammar rule:
  *
  *     minusTerm = '-' term;
  *
  * This parser has an assembler that will pop two
  * numbers from the stack and push their difference.
  */
 protected Parser minusTerm() {
   Sequence s = new Sequence();
   s.add(new Symbol('-').discard());
   s.add(term());
   s.setAssembler(new MinusAssembler());
   return s;
 }
Esempio n. 9
0
  /**
   * get all k-1 candidate sequences
   *
   * @param seq - parent sequence
   * @return a list of sequences
   */
  public static ArrayList<ItemSet> getsubSequences(Sequence seq) {

    int n = seq.getAllItems().size();
    int[] masks = new int[n];
    ArrayList<ItemSet> subSequences = new ArrayList<ItemSet>();

    for (int i = 0; i < n; i++) {
      masks[i] = (1 << i);
    }

    for (int i = 0; i < (1 << n); i++) {

      ArrayList<Integer> newList = new ArrayList<Integer>();

      for (int j = 0; j < n; j++) {
        if ((masks[j] & i) != 0) {
          newList.add(seq.getAllItems().get(j));
        }
      }

      if (newList.size() == n - 1) {

        ItemSet is = new ItemSet();

        is.setItems(newList);

        subSequences.add(is);
      }
    }

    return subSequences;
  }
  private void addSegs(List segs, Sequence output) {
    int segtype = -1;
    int startidx = -1;

    for (int j = 0; j < output.size(); j++) {
      //      System.out.println("addSegs j="+j);
      Object tag = output.get(j);
      segtype = ArrayUtils.indexOf(segmentTags, tag.toString());

      if (segtype > -1) {
        //        System.out.println("...found segment "+tag);
        // A new segment is starting
        startidx = j;
        while (j < output.size() - 1) {
          //          System.out.println("...inner addSegs j="+j);
          j++;
          Object nextTag = output.get(j);
          if (!nextTag.equals(tag)) {
            j--;
            segs.add(new Segment(segtype, startidx, j));
            segtype = startidx = -1;
            break;
          }
        }
      }
    }

    // Handle end-of-sequence
    if (startidx > -1) {
      segs.add(new Segment(segtype, startidx, output.size() - 1));
    }
  }
Esempio n. 11
0
 /**
  * Returns a parser that will recognize a Midimath expression.
  *
  * @return a parser that will recognize a Midimath expression
  */
 public Parser expression() {
   if (expression == null) {
     expression = new Sequence();
     expression.add(term());
     expression.add(new Repetition(minusTerm()));
   }
   return expression;
 }
 @Override
 public void publish(final long sequence, final Sequence upperCursor) {
   final long expectedSequence = sequence - 1L;
   while (expectedSequence != upperCursor.get()) {
     // busy spin
   }
   upperCursor.set(sequence);
 }
 @Test
 public void testWithMarkupsEmptyAdditionalMarkups() {
   List<Markup> empty = Collections.emptyList();
   Sequence withMarkups = sequence.withMarkups(empty);
   assertNotNull(withMarkups.getMarkups());
   assertEquals(1, withMarkups.getMarkups().size());
   assertEquals(24, withMarkups.getMarkups().get(0).getStart());
 }
Esempio n. 14
0
 @PostConstruct
 private void sequenceChecker() {
   for (Sequence sequence : getSequences()) {
     if (!isExists(sequence.getSequenceName())) {
       hamesDataStore.insert(sequence, COLLECTION_NAME);
     }
   }
 }
 @Test
 public void testDeepCopyOptionsNullBaseUrl() {
   Options options = new Options();
   options.setBaseUrl(null);
   sequence.setOptions(options);
   Sequence copy = sequence.deepCopy();
   assertNotNull(copy.getOptions());
   assertNull(copy.getOptions().getBaseUrl());
 }
Esempio n. 16
0
 public SequenceSet deepCopy(SequenceSet value) {
   SequenceSet rc = new SequenceSet();
   Sequence sequence = value.getHead();
   while (sequence != null) {
     rc.add(new Sequence(sequence.first, sequence.last));
     sequence = sequence.getNext();
   }
   return rc;
 }
Esempio n. 17
0
 /**
  * Computes the size of this Sequence by summing the values of all the contained sequences.
  *
  * @return the total number of values contained in this set if it were to be iterated over like an
  *     array.
  */
 public long rangeSize() {
   long result = 0;
   Sequence sequence = getHead();
   while (sequence != null) {
     result += sequence.range();
     sequence = sequence.getNext();
   }
   return result;
 }
Esempio n. 18
0
 /** @return all the Sequence that are in this list */
 public List<Sequence> getReceived() {
   ArrayList<Sequence> rc = new ArrayList<Sequence>(size());
   Sequence sequence = getHead();
   while (sequence != null) {
     rc.add(new Sequence(sequence.first, sequence.last));
     sequence = sequence.getNext();
   }
   return rc;
 }
Esempio n. 19
0
  /**
   * Removes and returns the last sequence from this list.
   *
   * @return the last sequence from this list or null if the list is empty.
   */
  public Sequence removeLastSequence() {
    if (isEmpty()) {
      return null;
    }

    Sequence rc = getTail();
    rc.unlink();
    return rc;
  }
 public static void main(String[] args) {
   Sequence sequence = new Sequence(10);
   for (int i = 0; i < 10; i++) sequence.add(new StringHolder(Integer.toString(i)));
   Selector selector = sequence.selector();
   while (!selector.end()) {
     System.out.print(selector.current() + " ");
     selector.next();
   }
 }
Esempio n. 21
0
  public void testEventSequence() throws Exception {
    Sequence seq = lookup(Sequence.class, "event");

    int value = seq.getCurrentValue();

    assertEquals(value + 1, seq.getNextValue());
    assertEquals(value + 1, seq.getCurrentValue());
    assertEquals(value + 2, seq.getNextValue());
  }
Esempio n. 22
0
  /**
   * Finding next sequence id using key
   *
   * @param key
   * @return
   */
  public Long findNextSequenceId(String key) {

    // Building query
    Query query = new Query();
    query.addCriteria(Criteria.where("_id").is(key));

    Sequence sequence = findByQuery(query);

    return sequence.getSequence();
  }
 @Override
 public void publishInterruptibly(final long sequence, final Sequence upperCursor)
     throws InterruptedException {
   final long expectedSequence = sequence - 1L;
   while (expectedSequence != upperCursor.get()) {
     if (Thread.interrupted()) throw new InterruptedException();
     // busy spin
   }
   upperCursor.set(sequence);
 }
Esempio n. 24
0
 public static Sequence atomize(Sequence input) throws XPathException {
   if (input.hasOne()) return input.itemAt(0).atomize();
   Item next;
   ValueSequence result = new ValueSequence();
   for (SequenceIterator i = input.iterate(); i.hasNext(); ) {
     next = i.nextItem();
     result.add(next.atomize());
   }
   return result;
 }
  @Test
  public void singleFlatMap() {
    assertEquals(
        Sequence.emptySequence(), Sequence.of(1, 2, 3, 4, 5, 6, 7, 8, 9).flatMap(emptySeqFunc));

    assertEquals(Sequence.emptySequence(), Sequence.emptySequence().flatMap(identSeqFunc));

    assertArrayEquals(
        new Integer[] {},
        Sequence.of(1, 2, 3, 4, 5, 6, 7, 8, 9).flatMap(emptySeqFunc).toTypedArray());

    assertArrayEquals(
        new Integer[] {
          1, 2, 3, 2, 4, 6, 3, 6, 9, 4, 8, 12, 5, 10, 15, 6, 12, 18, 7, 14, 21, 8, 16, 24, 9, 18, 27
        },
        Sequence.of(1, 2, 3, 4, 5, 6, 7, 8, 9)
            .flatMap(i -> Sequence.of(i, i * 2, i * 3))
            .toTypedArray());

    assertArrayEquals(
        new String[] {"1", "2", "2", "3", "3", "4"},
        Sequence.of(1, 2, 3)
            .flatMap(i -> Sequence.of(String.valueOf(i), String.valueOf(i + 1)))
            .toTypedArray());
  }
Esempio n. 26
0
  public void createSequence(String key, String name, Color color, boolean isPlotted) {
    Sequence seq = getSequence(key);
    if (seq == null) {
      seq = new Sequence(key);
    }
    seq.name = name;
    seq.color = (color != null) ? color : defaultColor;
    seq.isPlotted = isPlotted;

    seqs.add(seq);
  }
Esempio n. 27
0
 /**
  * Get a string representation of this sequence database
  *
  * @return the string representation
  */
 @Override
 public String toString() {
   StringBuilder r = new StringBuilder();
   for (Sequence sequence : sequences) {
     r.append(sequence.getId());
     r.append(":  ");
     r.append(sequence.toString());
     r.append('\n');
   }
   return r.toString();
 }
 @Test
 public void testWithMarkups() {
   Markup markup = new Markup();
   markup.setStart(13);
   Sequence withMarkups = sequence.withMarkups(ImmutableList.of(markup));
   assertNotNull(withMarkups.getMarkups());
   assertEquals(2, withMarkups.getMarkups().size());
   for (Markup m : withMarkups.getMarkups()) {
     assertTrue(m.getStart() == 13 || m.getStart() == 24);
   }
 }
Esempio n. 29
0
 /* (non-Javadoc)
  * @see org.exist.xquery.value.AbstractSequence#addAll(org.exist.xquery.value.Sequence)
  */
 public void addAll(Sequence other) throws XPathException {
   if (other.hasOne()) {
     add(other.itemAt(0));
   } else if (!other.isEmpty()) {
     for (final SequenceIterator i = other.iterate(); i.hasNext(); ) {
       final Item next = i.nextItem();
       if (next != null) {
         add(next);
       }
     }
   }
 }
Esempio n. 30
0
  /*
   * Returns a parser that for the grammar rule:
   *
   *    term = '(' expression ')' | Num;
   *
   * This parser adds an assembler to Num, that will
   * replace the top token in the stack with the token's
   * Double value.
   */
  protected Parser term() {

    Sequence s = new Sequence();
    s.add(new Symbol('(').discard());
    s.add(expression());
    s.add(new Symbol(')').discard());

    Alternation a = new Alternation();
    a.add(s);
    a.add(new Num().setAssembler(new NumAssembler()));
    return a;
  }