The best data structure

  • Thread starter Gregor =?ISO-8859-2?Q?Kova=E8?=
  • Start date
G

Gregor =?ISO-8859-2?Q?Kova=E8?=

Hi!

What is the best data structure in Java for the next example:
I want to store different properties with their values in a structure that
is fast for inserts and even faster for retrival. It should also provide
the ability to search for only a fraction of the property.
Example:
- MASK_NAME.MASK_FIELD_NAME1.PROPERTY_NAME1 = VALUE1
- MASK_NAME.MASK_FIELD_NAME1.PROPERTY_NAME2 = VALUE2
- MASK_NAME.MASK_FIELD_NAME2.PROPERTY_NAME3 = VALUE3
- MASK_NAME.MASK_FIELD_NAME2.PROPERTY_NAME4 = VALUE4

So I want to store them into a structre and search over them like this:
- get me value for property MASK_NAME.MASK_FIELD_NAME1.PROPERTY_NAME1. This
returns VALUE1.
- get me all the properties for MASK_NAME.MASK_FIELD_NAME1 (specific field
on a form) and their values. This returns PROPERTY_NAME1 = VALUE1 and
PROPERTY_NAME2 = VALUE2
- who has a property named PROPERTY_NAME3. This returns
MASK_NAME.MASK_FIELD_NAME2.

Basically I want to do somekind of SQL queries over this structure.

Best regards,
Kovi

--
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
| Gregor Kovac | (e-mail address removed) |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| In A World Without Fences Who Needs Gates? |
| Experience Linux. |
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
 
H

Hendrik Maryns

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
NotDashEscaped: You need GnuPG to verify this message

Gregor Kova? schreef:
Hi!

What is the best data structure in Java for the next example:
I want to store different properties with their values in a structure that
is fast for inserts and even faster for retrival. It should also provide
the ability to search for only a fraction of the property.
Example:
- MASK_NAME.MASK_FIELD_NAME1.PROPERTY_NAME1 = VALUE1
- MASK_NAME.MASK_FIELD_NAME1.PROPERTY_NAME2 = VALUE2
- MASK_NAME.MASK_FIELD_NAME2.PROPERTY_NAME3 = VALUE3
- MASK_NAME.MASK_FIELD_NAME2.PROPERTY_NAME4 = VALUE4

So I want to store them into a structre and search over them like this:
- get me value for property MASK_NAME.MASK_FIELD_NAME1.PROPERTY_NAME1. This
returns VALUE1.
- get me all the properties for MASK_NAME.MASK_FIELD_NAME1 (specific field
on a form) and their values. This returns PROPERTY_NAME1 = VALUE1 and
PROPERTY_NAME2 = VALUE2
- who has a property named PROPERTY_NAME3. This returns
MASK_NAME.MASK_FIELD_NAME2.

Basically I want to do somekind of SQL queries over this structure.

Multiple nested hash maps? Solves insertion speed and querying of the
first two kinds. To get the third kind of query efficient, you will
need an additional hash with inverted values. You can use values() for
the answer to query 2.

H.
--
Hendrik Maryns

==================
www.lieverleven.be
http://aouw.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQFD/E/Te+7xMGD3itQRAtDzAJ4tf1FOa153uTKB/75Ag70FTFqpGwCfYUqF
3RQW/vjafesqXTRausK+tIY=
=BKE5
-----END PGP SIGNATURE-----
 
J

Jacob

Gregor said:
What is the best data structure in Java for the next example:
I want to store different properties with their values in a structure that
is fast for inserts and even faster for retrival. It should also provide
the ability to search for only a fraction of the property.
Example:
- MASK_NAME.MASK_FIELD_NAME1.PROPERTY_NAME1 = VALUE1
- MASK_NAME.MASK_FIELD_NAME1.PROPERTY_NAME2 = VALUE2
- MASK_NAME.MASK_FIELD_NAME2.PROPERTY_NAME3 = VALUE3
- MASK_NAME.MASK_FIELD_NAME2.PROPERTY_NAME4 = VALUE4

So I want to store them into a structre and search over them like this:
- get me value for property MASK_NAME.MASK_FIELD_NAME1.PROPERTY_NAME1. This
returns VALUE1.
- get me all the properties for MASK_NAME.MASK_FIELD_NAME1 (specific field
on a form) and their values. This returns PROPERTY_NAME1 = VALUE1 and
PROPERTY_NAME2 = VALUE2
- who has a property named PROPERTY_NAME3. This returns
MASK_NAME.MASK_FIELD_NAME2.

Basically I want to do somekind of SQL queries over this structure.

The java.util.prefs.Preferences class looks very much like
this. It is basically a properties (key = value) type inside
a tree structure. I am sure you can use it as your backend
and provide a suitable public API on top of it.
 
T

tom fredriksen

Gregor said:
Hi!

What is the best data structure in Java for the next example:
I want to store different properties with their values in a structure that
is fast for inserts and even faster for retrival. It should also provide
the ability to search for only a fraction of the property.
Example:
- MASK_NAME.MASK_FIELD_NAME1.PROPERTY_NAME1 = VALUE1
- MASK_NAME.MASK_FIELD_NAME1.PROPERTY_NAME2 = VALUE2
- MASK_NAME.MASK_FIELD_NAME2.PROPERTY_NAME3 = VALUE3
- MASK_NAME.MASK_FIELD_NAME2.PROPERTY_NAME4 = VALUE4

Basically I want to do somekind of SQL queries over this structure.

I dont think there is any thing out there that contains exactly what you
want so I think you have to create/extend some stuff yourself.

What you can do is create indexes for the data parts you are looking for
and store those parts in a hashmap or a RedBlack tree, then use an array
or ArrayList for the data it self which the indexes point to.
Example:

index 1 (hashmap):
key: MASK_FIELD_NAME1
value: LinkedList of array entries

index 2 (hashmap):
key: PROPERTY_NAME1
value: LinkedList of array entries

and so on.

/tom
 

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
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top