Ejemplo n.º 1
0
  @Override
  public IndexIterator iter(final IndexToken token) {
    final int id = values.id(token.get());
    if (id == 0) return IndexIterator.EMPTY;

    final int len = lenList.get(id);
    final int[] ids = idsList.get(id), pres;
    if (data.meta.updindex) {
      final IntList tmp = new IntList();
      for (int i = 0; i < len; ++i) tmp.add(data.pre(ids[i]));
      pres = tmp.sort().finish();
    } else {
      pres = ids;
    }

    return new IndexIterator() {
      int p;

      @Override
      public boolean more() {
        return p < len;
      }

      @Override
      public int pre() {
        return pres[p++];
      }

      @Override
      public int size() {
        return len;
      }
    };
  }
Ejemplo n.º 2
0
 /**
  * Removes values from the index.
  *
  * @param key key
  * @param vals sorted values
  */
 void delete(final byte[] key, final int... vals) {
   final int id = values.id(key), vl = vals.length, l = lenList.get(id), s = l - vl;
   final int[] ids = idsList.get(id);
   for (int i = 0, n = 0, v = 0; i < l; i++) {
     if (v == vl || ids[i] != vals[v]) ids[n++] = ids[i];
     else v++;
   }
   lenList.set(id, s);
   if (s == 0) idsList.set(id, null);
 }
Ejemplo n.º 3
0
 /**
  * Checks compatibility of dependency version with installed version.
  *
  * @param dep dependency
  * @param currentVers current versions - either currently installed versions for a package or
  *     current version of BaseX
  * @return available appropriate version
  */
 private byte[] availVersion(final Dependency dep, final TokenSet currentVers) {
   if (currentVers.size() == 0) return null;
   if (dep.versions != null) {
     // get acceptable versions for secondary package/processor
     final TokenSet versList = new TokenSet(split(dep.versions, ' '));
     // check if any acceptable version is already installed
     for (final byte[] v : versList) if (currentVers.id(v) != 0) return v;
   } else if (dep.semver != null) {
     // version template - version of secondary package or BaseX version must
     // be compatible with the defined template
     final PkgVersion semVer = new PkgVersion(dep.semver);
     for (final byte[] v : currentVers) if (new PkgVersion(v).isCompatible(semVer)) return v;
   } else if (dep.semverMin != null && dep.semverMax != null) {
     // version templates for minimal and maximal acceptable version - version
     // of secondary package or BaseX version must be equal or above
     // the minimal and strictly below the maximal
     final PkgVersion min = new PkgVersion(dep.semverMin);
     final PkgVersion max = new PkgVersion(dep.semverMax);
     for (final byte[] nextVer : currentVers) {
       final PkgVersion v = new PkgVersion(nextVer);
       if (v.compareTo(min) >= 0 && v.compareTo(max) < 0) return nextVer;
     }
   } else if (dep.semverMin != null) {
     // version template for minimal acceptable version - version of secondary
     // package or BaseX version must be either compatible with this template
     // or greater than it
     final PkgVersion semVer = new PkgVersion(dep.semverMin);
     for (final byte[] nextVer : currentVers) {
       final PkgVersion v = new PkgVersion(nextVer);
       if (v.isCompatible(semVer) || v.compareTo(semVer) >= 0) return nextVer;
     }
   } else if (dep.semverMax != null) {
     // version template for maximal acceptable version - version of secondary
     // package or BaseX version must be either compatible with this template
     // or smaller than it
     final PkgVersion semVer = new PkgVersion(dep.semverMax);
     for (final byte[] nextVer : currentVers) {
       final PkgVersion v = new PkgVersion(nextVer);
       if (v.isCompatible(semVer) || v.compareTo(semVer) <= 0) return nextVer;
     }
   } else {
     // no versioning attribute is specified => any version of the secondary
     // package is acceptable
     return currentVers.keys()[0];
   }
   return null;
 }
Ejemplo n.º 4
0
  /**
   * Adds values to the index.
   *
   * @param key key to be indexed
   * @param vals sorted values
   */
  void add(final byte[] key, final int... vals) {
    // token index: add values. otherwise, reference existing values
    final int id = type == IndexType.TOKEN ? values.put(key) : values.id(key), vl = vals.length;
    // updatable index: if required, resize existing arrays
    while (idsList.size() < id + 1) idsList.add(null);
    if (lenList.size() < id + 1) lenList.set(id, 0);

    final int len = lenList.get(id), size = len + vl;
    int[] ids = idsList.get(id);
    if (ids == null) {
      ids = vals;
    } else {
      if (ids.length < size) ids = Arrays.copyOf(ids, Array.newSize(size));
      System.arraycopy(vals, 0, ids, len, vl);
      if (ids[len - 1] > vals[0]) {
        if (reorder == null) reorder = new BoolList(values.size());
        reorder.set(id, true);
      }
    }
    idsList.set(id, ids);
    lenList.set(id, size);
  }
Ejemplo n.º 5
0
 @Override
 public int costs(final IndexToken it) {
   return lenList.get(values.id(it.get()));
 }