Hi all,
In a mediation chain, I am checking for duplicated messages, once found
the chain will stop and proceed to the next message.
In case the message (Any data structure) is new, I add it to a Map
(Hastable) using a key that I generate to identify this message, and
then the chain continue to the next operations/command.
And life goes on.
My question : if I let got that way the Map will reach its max size.
So I want to make it circular is there a way... to make Map (Hashtable)
a circular structure ??
Thank in advance for your help.
Matt Humphrey - 04 Jan 2006 13:34 GMT
> Hi all,
>
[quoted text clipped - 11 lines]
> So I want to make it circular is there a way... to make Map (Hashtable)
> a circular structure ??
Map is an interface, so I suppose you're talking about the HashMap, TreeMap,
Hashtable or other structure that provides the actual storage. All these
structures automatically increase in size so there is no problem with them
reaching a "max size".
Cheers,
Matt Humphrey matth@ivizNOSPAM.com http://www.iviz.com/
zero - 04 Jan 2006 13:44 GMT
misrar.mouad@gmail.com wrote in news:1136377175.956239.275210
@g43g2000cwa.googlegroups.com:
> Hi all,
>
[quoted text clipped - 13 lines]
>
> Thank in advance for your help.
Are there really that many different messages?
A circular data structure will by definition overwrite older data. If you
use LinkedHashMap instead of Hashtable, the order in which the elements
have been added is also the iteration order. So, you can just remove the
first element in the list when you add a new element.
Have a look at LinkedHashMap:removeEldestEntry(Map.Entry eldest)

Signature
Beware the False Authority Syndrome
Stefan Schulz - 04 Jan 2006 14:30 GMT
> Hi all,
>
[quoted text clipped - 11 lines]
> So I want to make it circular is there a way... to make Map (Hashtable)
> a circular structure ??
You can just generate keys from some periodic function, thereby
replacing messages after some time, when the function has "wrapped
around" and reached that key again.
Roedy Green - 04 Jan 2006 14:57 GMT
>My question : if I let got that way the Map will reach its max size.
It does not have a max size. You just eventually run out of RAM. That
size you give is just an estimate. If you overflow, it will rebuild
the HashMap with twice as big a lookup table.
By circular, I presume you mean you drop the oldest element every time
you add a new one to keep the map from growing too big?
LinkedHashMap maintains a link through the elements in age order.
Presumably could used that to find the oldest element and delete it if
the size is too big.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.