Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > HashMap implementation question

Reply
Thread Tools

HashMap implementation question

 
 
hal@no_spam_statsbiblioteket.dk
Guest
Posts: n/a
 
      07-07-2004
I have a HashMap containing references to rather large value objects (
Vector objects containing > 1000 other objects each )
I rarely need to actually access these values -> and performance in
accessing them is not an issue.
Therefore I have made my own implementation of the HashMap where I
overwrite get and put and instead of putting in a reference to the
objects I serialize the values and store a String with a path to the
serialized object ( get reads the object - so the implementation is
somewhat transparent though any object stored now is immutable ).

Now in rare cases I need to loop through the entire Map using the
Map.Entity collection.
How do I control when the objects are deserialized in the loop in a way
that is transparent to the user of the HashMap? What implementing method
is called when calling getValue() on a Map.Entity object?

Regards
Hans Lund
 
Reply With Quote
 
 
 
 
Chris Smith
Guest
Posts: n/a
 
      07-07-2004
hal@no_spam_statsbiblioteket.dk wrote:
> I have a HashMap containing references to rather large value objects (
> Vector objects containing > 1000 other objects each )
> I rarely need to actually access these values -> and performance in
> accessing them is not an issue.
> Therefore I have made my own implementation of the HashMap where I
> overwrite get and put and instead of putting in a reference to the
> objects I serialize the values and store a String with a path to the
> serialized object ( get reads the object - so the implementation is
> somewhat transparent though any object stored now is immutable ).


A better implementation would be to write your own class implementing
the Map interface (possibly by extending java.util.AbstractMap), and use
a HashMap internally to store the path names, never exposing that
HashMap to your client. You'd then just return a Set from entrySet that
also knows to deserialize objects, and in turn it would return an
Iterator that returns Map.Entry objects that know how to deserialize
objects. Same for the Collection returned by values().

If you still want to extend HashMap, you'll still need to override
entrySet() and values() to return something that knows how to
deserialize your objects.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
Reply With Quote
 
 
 
 
Mark McConnell
Guest
Posts: n/a
 
      07-07-2004
hal@no_spam_statsbiblioteket.dk wrote in message news:<ccgslu$tjj$(E-Mail Removed)-c.dk>...
> How do I control when the objects are deserialized in the loop in a way
> that is transparent to the user of the HashMap? What implementing method
> is called when calling getValue() on a Map.Entity object?


You might want to look at the source code for HashMap and Map.Entry.
It is usually in src.zip in the top directory where Java is installed.
 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      07-08-2004
On 7 Jul 2004 15:03:18 -0700, Mark McConnell wrote:

> You might want to look at the source code for HashMap and Map.Entry.


<http://www.physci.org/source.jsp?class=java.util.HashMap>
<http://www.physci.org/source.jsp?class=java.util.Map>

HTH

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insertion Sort : C++ implementation 100 times slower than C implementation sanket C++ 7 11-03-2011 05:00 AM
Knowing the implementation, are all undefined behaviours become implementation-defined behaviours? Michael Tsang C Programming 54 03-30-2010 07:46 AM
reuse HashMap$Entry (or HashMap in total) to avoid millions of allocations Vince Darley Java 4 03-02-2010 07:48 AM
Knowing the implementation, are all undefined behaviours become implementation-defined behaviours? Michael Tsang C++ 32 03-01-2010 09:15 PM
java.util.Properties extending from HashMap<Object, Object> insteadof HashMap<String, String> Rakesh Java 10 04-08-2008 04:22 AM



Advertisments