Examples of PageInputStream


Examples of lupos.datastructures.buffermanager.PageInputStream

      final TripleKey maximum) {
    if (filename < 0) {
      return -1;
    }
    try {
      final InputStream in = new PageInputStream(filename, this.pageManager);
      final boolean leaf = InputHelper.readLuposBoolean(in);
      Triple lastTriple = null;
      if (leaf) { // leaf node reached!
        while (true) {
          DBBPTreeEntry<TripleKey, Triple> e = this.getNextLeafEntry(in,
              (lastTriple == null) ? null : new TripleKey(
                  lastTriple, this.order), lastTriple);
          if (e == null || e.key == null) {
            in.close();
            return -1;
          }
          if (e.value != null) {
            lastTriple = e.value;
          }
          final TripleKey key = e.key;
          final int compare = this.comparator.compare(key, minimum);
          if (compare >= 0) {
            // now find maximum already here or reach the end of
            // this leaf node...
            int dist = -1;
            while (e != null && e.key != null
                && this.comparator.compare(e.key, maximum) <= 0) {
              dist++;
              e = this.getNextLeafEntry(in,
                  (lastTriple == null) ? null
                      : new TripleKey(lastTriple, this.order),
                  lastTriple);
              if (e!=null && e.value != null) {
                lastTriple = e.value;
              }
            }
            in.close();
            return dist;
          }
        }
      } else {
        TripleKey lastKey = null;
        while (true) {
          InnerNodeEntry nextEntry = this.getNextInnerNodeEntryStatistics(
              lastKey, in);
          if (nextEntry == null || nextEntry.fileName <= 0) {
            in.close();
            return -1;
          }
          lastKey = nextEntry.key;
          if (nextEntry.key == null) {
            // the maximum is already found and the distance has
            // been calculated
            // or there are no elements between minimum and maximum
            // or for finding the maximum, ancestor inner nodes must
            // be considered
            // as this inner node has already ended...
            return this.getDistance(nextEntry.fileName, minimum, maximum);
          }
          final int compare = this.comparator.compare(nextEntry.key,
              minimum);
          if (compare >= 0) {
            int dist = this.getDistance(nextEntry.fileName, minimum,
                maximum);
            if (dist < 0) {
              return -1;
            } else {
              // now find maximum (already in this inner
              // node?)
              if (this.comparator.compare(nextEntry.key, maximum) <= 0) {
                while (this.comparator.compare(nextEntry.key,
                    maximum) <= 0) {
                  nextEntry = this.getNextInnerNodeEntryStatistics(
                      lastKey, in);
                  if (nextEntry == null
                      || nextEntry.fileName <= 0) {
                    in.close();
                    return dist;
                  }
                  lastKey = nextEntry.key;
                  if (nextEntry.key == null) {
                    in.close();
                    return dist;
                  }
                  if (this.comparator.compare(nextEntry.key,
                      maximum) <= 0) {
                    dist += nextEntry.numberOfTriples;
View Full Code Here

Examples of lupos.datastructures.buffermanager.PageInputStream

    if (filename < 0) {
      return dist;
    }
    final InputStream fis;
    try {
      final InputStream in = new PageInputStream(filename, this.pageManager);
      final boolean leaf = InputHelper.readLuposBoolean(in);
      if (leaf) { // leaf node reached!
        Triple lastTriple = null;
        while (true) {
          final DBBPTreeEntry<TripleKey, Triple> e = this.getNextLeafEntry(
              in, (lastTriple == null) ? null : new TripleKey(
                  lastTriple, this.order), lastTriple);
          if (e == null || e.key == null) {
            in.close();
            return dist;
          }
          final TripleKey key = e.key;
          final int compare = this.comparator.compare(key, arg0);
          if (compare > 0) {
            in.close();
            return dist;
          }
          if (e.value != null) {
            lastTriple = e.value;
            dist++;
          }
        }
      } else {
        TripleKey lastKey = null;
        int lastFilename = -1;
        int lastDistance = 0;
        while (true) {
          final InnerNodeEntry nextEntry = this.getNextInnerNodeEntryStatistics(
              lastKey, in);
          if (nextEntry == null || nextEntry.fileName <= 0) {
            in.close();
            return dist + lastDistance;
          }
          if (nextEntry.key == null) {
            in.close();
            return this.getDistanceToFindMaximum(nextEntry.fileName,
                arg0, dist + lastDistance);
          }
          final int compare = this.comparator.compare(nextEntry.key, arg0);
          if (compare > 0) {
            in.close();
            final int interDist = this.getDistanceToFindMaximum(
                nextEntry.fileName, arg0, 0);
            if (interDist > 0) {
              return dist + lastDistance + interDist;
            }
View Full Code Here

Examples of lupos.datastructures.buffermanager.PageInputStream

      if (filename < 0) {
        return null;
      }
      final InputStream fis;
      try {
        final InputStream in = new PageInputStream(filename, LazyLiteralTripleKeyDBBPTreeStatistics.this.pageManager);
        final boolean leaf =  InputHelper.readLuposBoolean(in);
        if (leaf) { // leaf node reached!
          while (true) {
            final DBBPTreeEntry<TripleKey, Triple> e = LazyLiteralTripleKeyDBBPTreeStatistics.this.getNextLeafEntry(
                in, (this.lastTriple == null) ? null
                    : new TripleKey(this.lastTriple, LazyLiteralTripleKeyDBBPTreeStatistics.this.order),
                this.lastTriple);
            if (e == null || e.key == null) {
              this.currentLeafIn = in;
              this.close();
              return null;
            }
            if (e.value != null) {
              this.lastTriple = e.value;
            }
            final TripleKey key = e.key;
            final int compare = LazyLiteralTripleKeyDBBPTreeStatistics.this.comparator.compare(key, this.arg0);
            if (compare == 0) {
              this.currentLeafIn = in;
              return e.value;
            } else if (compare > 0) {
              this.currentLeafIn = in;
              this.close();
              return null;
            }
          }
        } else {
          TripleKey lastKey = null;
          while (true) {
            final Tuple<TripleKey, Integer> nextEntry = LazyLiteralTripleKeyDBBPTreeStatistics.this.getNextInnerNodeEntry(
                lastKey, in);
            if (nextEntry == null || nextEntry.getSecond() == 0
                || nextEntry.getSecond() < 0) {
              in.close();
              this.close();
              return null;
            }
            if (nextEntry.getFirst() == null) {
              this.innerNodes
View Full Code Here

Examples of lupos.datastructures.buffermanager.PageInputStream

    private Triple getFirst(final int filename, final TripleKey triplekey) {
      if (filename < 0) {
        return null;
      }
      try {
        final InputStream in =  new PageInputStream(filename, LazyLiteralTripleKeyDBBPTreeStatistics.this.pageManager);
        final boolean leaf = InputHelper.readLuposBoolean(in);
        this.lastTriple = null;
        if (leaf) { // leaf node reached!
          while (true) {
            final DBBPTreeEntry<TripleKey, Triple> e = LazyLiteralTripleKeyDBBPTreeStatistics.this.getNextLeafEntry(
                in, (this.lastTriple == null) ? null
                    : new TripleKey(this.lastTriple, LazyLiteralTripleKeyDBBPTreeStatistics.this.order),
                this.lastTriple);
            if (e == null || e.key == null) {
              this.currentLeafIn = in;
              this.close();
              return null;
            }
            if (e.value != null) {
              this.lastTriple = e.value;
            }
            final TripleKey key = e.key;
            final int compare = LazyLiteralTripleKeyDBBPTreeStatistics.this.comparator.compare(key, triplekey);
            if (compare == 0) {
              this.currentLeafIn = in;
              return e.value;
            } else if (compare > 0) {
              if (LazyLiteralTripleKeyDBBPTreeStatistics.this.comparator.compare(key, this.arg0) > 0) {
                this.currentLeafIn = in;
                this.close();
                return null;
              } else {
                this.currentLeafIn = in;
                return e.value;
              }
            }
          }
        } else {
          TripleKey lastKey = null;
          while (true) {
            final Tuple<TripleKey, Integer> nextEntry = LazyLiteralTripleKeyDBBPTreeStatistics.this.getNextInnerNodeEntry(
                lastKey, in);
            if (nextEntry == null || nextEntry.getSecond() <= 0) {
              in.close();
              this.close();
              return null;
            }
            lastKey = nextEntry.getFirst();
            if (nextEntry.getFirst() == null) {
View Full Code Here

Examples of lupos.datastructures.buffermanager.PageInputStream

        final int fileName) {
      if (fileName < 0) {
        return null;
      }
      try {
        final InputStream in = new PageInputStream(fileName, LazyLiteralTripleKeyDBBPTreeStatistics.this.pageManager);
        final boolean leaf = InputHelper.readLuposBoolean(in);
        this.lastTriple = null;
        if (leaf) { // leaf node reached!
          this.currentLeafIn = in;
          while (countDown >= 0.0) {
            final DBBPTreeEntry<TripleKey, Triple> e = LazyLiteralTripleKeyDBBPTreeStatistics.this.getNextLeafEntry(
                in, (this.lastTriple == null) ? null
                    : new TripleKey(this.lastTriple, LazyLiteralTripleKeyDBBPTreeStatistics.this.order),
                this.lastTriple);
            if (e == null) {
              this.close();
              this.next = null;
              return null;
            }
            if (e.key == null) {
              // next leaf node, but we do big jumps by going over
              // the inner nodes!
              // this case should never happen!
              if (e.filenameOfNextLeafNode >= 0) {
                this.currentLeafIn.close();
                return this.useInnerNodes(countDown, pos,
                    entry, this.innerNodes.size() - 1);
              } else {
                // should never happen!
                this.currentLeafIn.close();
                this.close();
                this.next = null;
                return null;
              }
            }
            if (LazyLiteralTripleKeyDBBPTreeStatistics.this.comparator.compare(e.key, this.arg0) != 0) {
              this.close();
              this.next = null;
              return null;
            }
            if (this.largest != null) {
              if (LazyLiteralTripleKeyDBBPTreeStatistics.this.comparator.compare(e.key, this.largest) > 0) {
                this.close();
                this.next = null;
                return null;
              }
            }
            entry.selectivity += 1.0;
            countDown -= 1.0;
            if (this.lastTriple == null
                || this.lastTriple
                    .getPos(pos)
                    .compareToNotNecessarilySPARQLSpecificationConform(
                        e.value.getPos(pos)) != 0) {
              entry.distinctLiterals += 1.0;
            }
            this.lastTriple = e.value;
            entry.literal = this.lastTriple.getPos(pos);
          }
          // read over the triples with the same literal at position
          // pos
          return this.readOver(this.lastTriple, entry, pos);
        } else {
          TripleKey lastKey = null;
          while (true) {
            final InnerNodeEntry nextEntry = LazyLiteralTripleKeyDBBPTreeStatistics.this.getNextInnerNodeEntryStatistics(
                lastKey, in);
            if (nextEntry == null || nextEntry.fileName <= 0) {
              in.close();
              this.close();
              this.next = null;
              return null;
            }
            lastKey = nextEntry.key;
View Full Code Here

Examples of lupos.datastructures.buffermanager.PageInputStream

        final int pos, Triple lastTriple, final int fileName) {
      if (fileName < 0) {
        return null;
      }
      try {
        final InputStream in = new PageInputStream(fileName, LazyLiteralTripleKeyDBBPTreeStatistics.this.pageManager);
        final boolean leaf = InputHelper.readLuposBoolean(in);
        lastTriple = null;
        if (leaf) { // leaf node reached!
          this.currentLeafIn = in;
          return this.readOver(lastTriple, entry, pos);
        } else {
          TripleKey lastKey = null;
          InnerNodeEntry nextEntry = LazyLiteralTripleKeyDBBPTreeStatistics.this.getNextInnerNodeEntryStatistics(
              lastKey, in);
          final COMPARE primary = nextEntry.key.getTripleComparator()
              .getPrimary();
          final COMPARE secondary = COMPARE.NONE;
          final COMPARE tertiary = COMPARE.NONE;
          final TripleKey key = new TripleKey(lastTriple,
              new TripleComparator(primary, secondary, tertiary));
          while (true) {
            if (nextEntry == null || nextEntry.fileName <= 0) {
              in.close();
              this.close();
              this.next = null;
              return null;
            }
            lastKey = nextEntry.key;
View Full Code Here

Examples of lupos.datastructures.buffermanager.PageInputStream

        };
        }
        try {
          return new SIPParallelIterator<java.util.Map.Entry<K, V>, K>() {
            private InputStream in =
                new PageInputStream(DBBPTree.this.firstLeafPage,
                    DBBPTree.this.pageManager);
            {
              this.innerNodes = new LinkedList<Tuple<K, InputStream>>();
              InputHelper.readLuposBoolean(this.in);
            }
            private List<Tuple<K, InputStream>> innerNodes;
            private int entrynumber = 0;
            private K lastKey = null;
            private V lastValue = null;

            @Override
            public boolean hasNext() {
              return (this.entrynumber < DBBPTree.this.size());
            }

            private java.util.Map.Entry<K, V> getFirst(
                final int filename, final K k) {
              if (filename < 0) {
                return null;
              }
              try {
                final InputStream in_local = new PageInputStream(filename, DBBPTree.this.pageManager);
                final boolean leaf = InputHelper.readLuposBoolean(in_local);
                if (leaf) { // leaf node reached!
                  this.lastKey = null;
                  this.lastValue = null;
                  while (true) {
                    final DBBPTreeEntry<K, V> e = DBBPTree.this.getNextLeafEntry(in_local, this.lastKey, this.lastValue);
                    if (e == null || e.key == null) {
                      in_local.close();
                      this.close();
                      return null;
                    }
                    final K key = e.key;
                    this.lastKey = key;
                    this.lastValue = e.value;
                    final int compare = DBBPTree.this.comparator
                    .compare(key, k);
                    if (compare == 0) {
                      this.in = in_local;
                      return new MapEntry<K, V>(
                          e.key, e.value);
                    } else if (compare > 0) {
                      this.in = in_local;
                      return new MapEntry<K, V>(
                          e.key, e.value);
                    }
                  }
                } else {
                  K lastKey = null;
                  while (true) {
                    final Tuple<K, Integer> nextEntry = DBBPTree.this.getNextInnerNodeEntry(lastKey, in_local);
                    if (nextEntry == null || nextEntry.getSecond() <= 0) {
                      in_local.close();
                      this.close();
                      return null;
                    }
                    lastKey = nextEntry.getFirst();
                    if (nextEntry.getFirst() == null) {
                      this.innerNodes
                      .add(new Tuple<K, InputStream>(null, in_local));
                      return this.getFirst(nextEntry
                          .getSecond(), k);
                    }
                    final int compare = DBBPTree.this.comparator
                    .compare(nextEntry
                        .getFirst(), k);
                    if (compare >= 0) {
                      this.innerNodes
                      .add(new Tuple<K, InputStream>(nextEntry.getFirst(), in_local));
                      return this.getFirst(nextEntry.getSecond(), k);
                    }
                  }
                }

              } catch (final FileNotFoundException e) {
                e.printStackTrace();
                System.err.println(e);
              } catch (final IOException e) {
                System.err.println("filename:"+filename);
                e.printStackTrace();
                System.err.println(e);
              }
              return null;
            }

            private java.util.Map.Entry<K, V> getFirstUsingCache(
                final int index, final K kkey) {
              if (index < 0) {
                return null;
              }
              try {
                if (this.innerNodes.size() <= index) {
                  this.close();
                  return null;
                  // close();
                  // innerNodes.clear();
                  // return getFirst(rootFilename,
                  // triplekey);
                }
                final Tuple<K, InputStream> current = this.innerNodes.get(index);
                final InputStream in = current
                .getSecond();
                K lastKey = current.getFirst();
                if (lastKey == null
                    || DBBPTree.this.comparator
                    .compare(lastKey, kkey) >= 0) {
                  return this.getFirstUsingCache(index + 1,
                      kkey);
                }
                while (this.innerNodes.size() > index + 1) {
                  final Tuple<K, InputStream> toBeDeleted = this.innerNodes.remove(this.innerNodes.size() - 1);
                  try {
                    toBeDeleted.getSecond().close();
                  } catch (final IOException e) {
                    e.printStackTrace();
                    System.err.println(e);
                  }
                }
                while (true) {
                  final Tuple<K, Integer> nextEntry = DBBPTree.this.getNextInnerNodeEntry(lastKey, in);
                  if (nextEntry == null || nextEntry.getSecond() <= 0) {
                    in.close();
                    this.close();
                    return null;
                  }
                  lastKey = nextEntry.getFirst();
                  if (nextEntry.getFirst() == null) {
                    current.setFirst(null);
                    return this.getFirst(nextEntry
                        .getSecond(), kkey);
                  }
                  final int compare = DBBPTree.this.comparator.compare(
                      nextEntry.getFirst(), kkey);
                  if (compare >= 0) {
                    current.setFirst(nextEntry
                        .getFirst());
                    return this.getFirst(nextEntry
                        .getSecond(), kkey);
                  }
                }

              } catch (final FileNotFoundException e) {
                e.printStackTrace();
                System.err.println(e);
              } catch (final IOException e) {
                e.printStackTrace();
                System.err.println(e);
              }
              return null;
            }

            @Override
            public java.util.Map.Entry<K, V> next() {
              if(!this.hasNext()) {
                return null;
              }
              try {
                final DBBPTreeEntry<K, V> e = DBBPTree.this.getNextLeafEntry(this.in, this.lastKey, this.lastValue);
                if (e != null) {
                  if (e.key == null) {
                    if (e.filenameOfNextLeafNode >= 0) {
                      this.in.close();
                      try{
                        this.in =
                            new PageInputStream(
                                e.filenameOfNextLeafNode,
                                DBBPTree.this.pageManager);
                        InputHelper.readLuposBoolean(this.in);
                        this.lastKey = null;
                        this.lastValue = null;
                        return this.next();
                      } catch(final Exception e1){
                        System.err.println(e1);
                        e1.printStackTrace();
                        return null;
                      }
                    }
                  } else {
                    this.lastKey = e.key;
                    this.lastValue = e.value;
                    this.entrynumber++;
                    return new MapEntry<K, V>(e.key,
                        e.value);
                  }
                }
              } catch (final FileNotFoundException e1) {
                System.err.println(e1);
                e1.printStackTrace();
              } catch (final IOException e1) {
                System.err.println(e1);
                e1.printStackTrace();
              }
              return null;
            }

            @Override
            public void remove() {
              throw (new UnsupportedOperationException(
              "This iterator is ReadOnly."));
            }

            @Override
            protected void finalize() throws Throwable {
              try {
                this.in.close();
              } finally {
                super.finalize();
              }
            }

            @Override
            public void close() {
              for (final Tuple<K, InputStream> tuple : this.innerNodes) {
                try {
                  tuple.getSecond().close();
                } catch (final IOException e) {
                }
              }
              try {
                this.in.close();
              } catch (final IOException e) {
                System.err.println(e);
                e.printStackTrace();
              }
            }

            private java.util.Map.Entry<K, V> getNext(final K k) {
              try {
                final DBBPTreeEntry<K, V> e = DBBPTree.this.getNextLeafEntry(this.in, this.lastKey, this.lastValue);
                if (e != null) {
                  if (e.key == null) {
                    if (e.filenameOfNextLeafNode >= 0) {
                      this.in.close();
                      this.in =
                          new PageInputStream(
                              e.filenameOfNextLeafNode,
                              DBBPTree.this.pageManager);
                      InputHelper.readLuposBoolean(this.in);
                      this.lastKey = null;
                      this.lastValue = null;
View Full Code Here

Examples of lupos.datastructures.buffermanager.PageInputStream

    if (filename < 0 || this.size == 0) {
      return null;
    }
    try {
      final InputStream in =  new PageInputStream(filename, this.pageManager);
      final boolean leaf = InputHelper.readLuposBoolean(in);
      if (leaf) { // leaf node reached!
        K lastKey = null;
        V lastValue = null;
        while (true) {
          final DBBPTreeEntry<K, V> e = this.getNextLeafEntry(in, lastKey,
              lastValue);
          if (e == null || e.key == null) {
            in.close();
            return null;
          }
          final int compare = this.comparator.compare(e.key, (K) arg0);
          lastKey = e.key;
          lastValue = e.value;
          if (compare == 0) {
            in.close();
            return e.value;
          } else if (compare > 0) {
            in.close();
            return null;
          }
        }
      } else {
          K lastKey=null;
          while (true) {

            final Tuple<K, Integer> nextEntry=this.nodeDeSerializer.getNextInnerNodeEntry(lastKey, in);

            if(nextEntry==null){
              in.close();
              return null;
            }

            final int nextFilename=nextEntry.getSecond();

            if(nextEntry.getSecond()<0){
              in.close();
              return null;
            }

            final K nextKey = nextEntry.getFirst();
            if (nextKey == null) {
              in.close();
              return this.get(arg0, nextFilename);
            }
            final int compare = this.comparator.compare(nextKey,
                (K) arg0);
            if (compare >= 0) {
              in.close();
              return this.get(arg0, nextFilename);
            }
            lastKey=nextKey;
          }
      }
View Full Code Here

Examples of lupos.datastructures.buffermanager.PageInputStream

  }

  public Node<K, V> getNode(final int filename) {
    final InputStream fis;
    try {
      final InputStream in = new PageInputStream(filename, this.pageManager);
      final boolean leaf = InputHelper.readLuposBoolean(in);
      if (leaf) {
        final LeafNode<K, V> leafNode = new LeafNode<K, V>(this.keyClass,
            this.valueClass, this.k_, this.pageManager, this.nodeDeSerializer);
        leafNode.filename = filename;
        leafNode.in = in;
        leafNode.readFullLeafNode();
        in.close();
        return leafNode;
      } else {
        final InnerNode<K, V> innerNode = new InnerNode<K, V>(this.keyClass,
            this.valueClass, this.k, this.pageManager, this.nodeDeSerializer);
        innerNode.filename = filename;
        innerNode.in = in;
        innerNode.readFullInnerNode();
        in.close();
        return innerNode;
      }
    } catch (final FileNotFoundException e) {
      System.err.println(e);
      e.printStackTrace();
View Full Code Here

Examples of lupos.datastructures.buffermanager.PageInputStream

      final int filename, final List<Node<K, V>> currentCollection) {
    if (filename < 0) {
      return null;
    }
    try {
      final InputStream in = new PageInputStream(filename, this.pageManager);
      final boolean leaf = InputHelper.readLuposBoolean(in);
      if (leaf) { // leaf node reached!
        final LeafNode<K, V> navigateToClassLeafNode = new LeafNode<K, V>(
            this.keyClass, this.valueClass, this.k_, this.pageManager, this.nodeDeSerializer);
        navigateToClassLeafNode.filename = filename;
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.