コード例 #1
0
ファイル: HashSet.java プロジェクト: sqrlab/VisMAn
 public boolean add(java.lang.Object x) {
   int h = x.hashCode();
   if (h < 0) {
     h = -h;
   }
   h = ~h % buckets.length;
   hashset.HashSet.Node current = buckets[h];
   while (current != null) {
     if (current.data.equals(x)) {
       return false;
     }
     current = current.next;
   }
   hashset.HashSet.Node newNode = new hashset.HashSet.Node();
   newNode.data = x;
   newNode.next = buckets[h];
   buckets[h] = newNode;
   currentSize++;
   return true;
 }
コード例 #2
0
ファイル: HashSet.java プロジェクト: sqrlab/VisMAn
 public boolean remove(java.lang.Object x) {
   int h = x.hashCode();
   if (h < 0) {
     h = -h;
   }
   h = h % buckets.length;
   hashset.HashSet.Node current = buckets[h];
   hashset.HashSet.Node previous = null;
   while (current != null) {
     if (current.data.equals(x)) {
       if (previous == null) {
         buckets[h] = current.next;
       } else {
         previous.next = current.next;
       }
       currentSize--;
       return true;
     }
     previous = current;
     current = current.next;
   }
   return false;
 }