// Done !!! :D :D :D
  public void addSingleIndex(String column, float loadFactor, int bucketSize)
      throws IOException, ClassNotFoundException, DBAppException {

    if (!ColNameType.containsKey(column)) throw new DBAppException();

    singleIndexedColumns.add(column);

    LinearHashTable LHT = new LinearHashTable(tableName, column, loadFactor, bucketSize);

    for (int i = 1; i <= numberOfPages; i++) {
      Page p = (Page) DBApp.readObj("src/classes/Datei/" + tableName + i + ".class");
      for (int j = 0; j < p.length(); j++) {
        String val = p.getValue(j, column);
        if (val != null) LHT.put(p.getValue(j, column), p.getPageNumber() + "#" + j);
      }
    }

    DBApp.writeObj(LHT, "src/classes/Datei/Hashtable#" + tableName + "#" + column + ".class");
  }
示例#2
0
 /**
  * Get the value for the given key, or null if not found.
  *
  * @param p the page
  * @param key the key
  * @return the value or null
  */
 protected Object binarySearch(Page p, Object key) {
   int x = p.binarySearch(key);
   if (!p.isLeaf()) {
     if (x < 0) {
       x = -x - 1;
     } else {
       x++;
     }
     p = p.getChildPage(x);
     return binarySearch(p, key);
   }
   if (x >= 0) {
     return p.getValue(x);
   }
   return null;
 }
示例#3
0
 /**
  * Remove a key-value pair.
  *
  * @param p the page (may not be null)
  * @param writeVersion the write version
  * @param key the key
  * @return the old value, or null if the key did not exist
  */
 protected Object remove(Page p, long writeVersion, Object key) {
   int index = p.binarySearch(key);
   Object result = null;
   if (p.isLeaf()) {
     if (index >= 0) {
       result = p.getValue(index);
       p.remove(index);
       if (p.getKeyCount() == 0) {
         removePage(p.getPos());
       }
     }
     return result;
   }
   // node
   if (index < 0) {
     index = -index - 1;
   } else {
     index++;
   }
   Page cOld = p.getChildPage(index);
   Page c = copyOnWrite(cOld, writeVersion);
   result = remove(c, writeVersion, key);
   if (result == null) {
     return null;
   }
   if (c.getTotalCount() == 0) {
     // this child was deleted
     if (p.getKeyCount() == 0) {
       p.setChild(index, c);
       p.setCounts(index, c);
       removePage(p.getPos());
     } else {
       p.remove(index);
     }
   } else {
     p.setChild(index, c);
     p.setCounts(index, c);
   }
   return result;
 }