private Bucket smallestBucket() { check(HASH_OK); Iterator<Bucket> bit = table.values().iterator(); Bucket smallB = null; int smallest = Integer.MAX_VALUE; while ( bit.hasNext() ) { Bucket b = bit.next(); int sz = b.size(); if ( sz < smallest ) { smallB = b; smallest = sz; } } return smallB; } private Bucket matchBucket(Bucket key) {
private Iterator<Bucket> scanBuckets() { // Looks through buckets, // if has single member then return in iterator. // Otherwise if some member of the bucket has friends // we can refine the hash, and we set refinableHash. check(HASH_OK); return new FilterIterator<Bucket>( new Filter<Bucket>() { @Override public boolean accept(Bucket o) { Bucket b = o; if (b.size()==1) return true; if (!refinableHash) { Iterator<AnonResource> it = b.members(); while ( it.hasNext() ) if (!it.next() .friends.isEmpty()) { refinableHash = true; break; } } return false; } },table.values().iterator()); } private void unbindAll(Set<AnonResource> s) {
private Bucket matchBucket(Bucket key) { check(HASH_OK); Integer hash = new Integer(key.aMember().myHash); Bucket rslt = table.get(hash); if ( rslt != null ) { if ( key.size() != rslt.size() ) return null; } return rslt; }
private boolean bind() { Set<AnonResource> locallyBound = obligBindings(); if (locallyBound==null) // Contradiction reached - fail. return false; check(HASH_OK); Bucket bkt = smallestBucket(); if ( bkt == null ) return true; // No smallest bucket - we are finished. Bucket otherBkt = other.matchBucket(bkt); if ( otherBkt != null ) { AnonResource v = bkt.aMember(); Iterator<AnonResource> candidates = otherBkt.members(); // System.out.println("Guessing"); while ( candidates.hasNext() ) { check(HASH_OK|HASH_BAD); AnonResource otherV = candidates.next(); trace(true,"Guess: "); if (!bkt.bind(v,otherBkt,otherV)) continue; if (bind()) return true; v.unbind(); } } unbindAll(locallyBound); return false; } /*
boolean newBinding; Set<AnonResource> rslt = CollectionFactory.createHashedSet(); check(HASH_OK|HASH_BAD); do { if ( rehash(hashLevel) != other.rehash(hashLevel) ){