Пример #1
0
 public Link find(int key) {
   Link current = first;
   while (current != null && current.getKey() <= key) { // or key too small,
     if (current.getKey() == key) // found, return link
     return current;
     current = current.next; // go to next item
   }
   return null; // cannot find it
 }
Пример #2
0
  public void setWithLink(OCPUser user, Content data, Link link) throws Exception {
    // if a link already exists with the same key, then delete it.
    Key key = link.getKey();
    if (exists(key)) {
      // remove both the link and its targets recursively
      remove(user, key);
    }

    Key targetKey = link.getTargetKey();
    if (exists(targetKey)) {
      remove(user, targetKey);
    }

    // check that the link targetKey is the data key
    checkLink(data, link);

    Address[] address = getAddressList(key);
    for (byte i = 0; i < address.length; i++) {
      store(address[i], link);
    }

    address = getAddressList(targetKey);
    for (byte i = 0; i < address.length; i++) {
      store(address[i], data);
    }
  }
Пример #3
0
 public void insert(Link theLink) {
   int key = theLink.getKey();
   Link previous = null; // start at first
   Link current = first;
   // until end of list,
   // or current bigger than key,
   while (current != null && key > current.getKey()) {
     previous = current;
     current = current.next; // go to next item
   }
   if (previous == null) // if beginning of list,
   first = theLink;
   else
     // not at beginning,
     previous.next = theLink;
   theLink.next = current;
 }
Пример #4
0
  public void delete(int key) {
    Link previous = null;
    Link current = first;

    while (current != null && key != current.getKey()) {
      previous = current;
      current = current.next;
    }
    // disconnect link
    if (previous == null) //   if beginning of list delete first link
    first = first.next;
    else
      //   not at beginning
      previous.next = current.next; // delete current link
  }
Пример #5
0
 // 向hash表中插入一个Link元素
 public void insert(Link theLink) {
   int hashVal = hashFun(theLink.getKey());
   hashArray[hashVal].insert(theLink);
 }
Пример #6
0
 public void insert(Link theLink) {
   int key = theLink.getKey();
   int hashVal = hashFunc(key);
   hashArray[hashVal].insert(theLink);
 }
 public void insert(Link link) {
   int key = link.getKey();
   int hashVal = hash(key);
   array[hashVal].insert(link);
 }