[jboss-dev-forums] [Design of JBossCache] - Re: Possible optimization of CachedSetImpl

ben.wang@jboss.com do-not-reply at jboss.com
Wed Nov 8 04:04:32 EST 2006


"genman" wrote : 1. I actually don't know the difference ... I may have copied that from the original implementation. The tests seemed to pass. What's the sematic difference?

attach/detach/find will go through the proper PojoCache interceptors (e.g., tx lock and rollback). See pojocache-aop.xml for the corresponding stack.

anonymous wrote : 
  | 2. I'm not sure how this would work better?
  | 
  | The need for offsetting the hashcode is to deal with a typically rare edge condition. If the hash function is reasonably distributed, then the chances of hash code collision (and therefore the need to do the hash code+1 trick) would be at best 1 in 2^32 and likely only a few orders of magnitude worse otherwise.
  | 
  | I think people expect hash collisions would happen more often, but that's because in ordinary hash tables, collisions happen from evaluating (hash code % some small number).

I am not talking about offsetting the hashcode. I like your implementation! What I was referring to is the need to loop through the cache index consecutively, e.g.,  for remove(), you have:

  | 	  for (int i = 0; i < size; i++)
  | 	  {
  | 		 Object key = toLong(hashCode, i);
  | 		 Object o2 = getNoUnmask(key);
  | 		 if (o2 == null)
  | 			break;
  | 		 if (removed)
  | 		 {
  | 			// move o2 to old key 
  | 			pCache_.detach(AopUtil.constructFqn(getFqn(), key));
  | 			pCache_.attach(AopUtil.constructFqn(getFqn(), oldkey), o2);
  | 		 }
  | 		 if (o.equals(o2))
  | 		 {
  | 			pCache_.detach(AopUtil.constructFqn(getFqn(), key));
  | 			removed = true;
  | 		 }
  | 		 oldkey = key;
  | 	  }
  | 	  return removed;
  | 
insead of index looping, I could have like in pseudo code:

  | // This is assumed to consist of only set objects.
  | Collection list = cache.getNode(getFqn()).getChildren();
  | for(Collection c: list)
  | {
  | // check if o is present
  | Object o2 = cache.find(c);
  | if(o == o2) cache.detach(c);
  | return;
  | }
  | 
This way, we don't maintain odered list of index.

BTW, the unit tests have some failure from the Set tests. I will probably need to look into to see where they go wrong.

Thanks,

-Ben

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3984022#3984022

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3984022



More information about the jboss-dev-forums mailing list