Circular data structures

M

misrar.mouad

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.
 
M

Matt Humphrey

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 ??

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 (e-mail address removed) http://www.iviz.com/
 
Z

zero

(e-mail address removed) wrote in @g43g2000cwa.googlegroups.com:
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.

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)
 
S

Stefan Schulz

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 ??

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.
 
R

Roedy Green

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top