I am having troubles conceptualizing an algorithm to be used to transform any information or data into a specific appropriate and reasonable memory location in any data structure that I will be devising.
To give you an idea, I have a JPanel object instance and I created another Container type object instance of any subtype (note this is in Java because I love this language), then I collected those instances into a data structure not specifically just for those instances but also applicable to any type of object. Now my procedure for fetching those data again is to extract the object specific features similar in category to all object in that data structure and transform it into a integer data memory location (specifically as much as possible) or any type of data that will pertain to this transformation. And I can already access that memory location without further sorting or applications of O(n) time complex algorithms (which I think preferable but I wanted to do my own way XD). The data structure is of any type either binary tree, linked list, arrays or sets (and the like XD). What is important is I don't need to have successive comparing and analysis of data just to locate information in big structures.
To give you a technical idea, I have to an array DS that contains JLabel object instance with a specific name "HelloWorld". But array DS contains other types of object (in multitude). Now this JLabel object has a location in the array at index [124324] (which is if you do any type of searchin开发者_StackOverflow社区g algorithm just to arrive at that location is conceivably slow because added to it the data structure used was an array *note please disregard the efficiency of the data structure to be used I just want to explain to you my concept XD). Now I want to equate "HelloWorld" to 124324 by using a conceptually made function applicable to all data types. So that I can do a direct search by doing this DS[extractLocation("HelloWorld")] just to get that JLabel instance.
I know this may sound crazy but I want to test my concept of non-sorting feature extracting search algorithm for any data structure wherein my main problem is how to transform information to be stored into memory location of where it was stored.
I think you are asking for a Map
. A map doesn't use indices like array, but stores each value with an associated key, or identifier.
A map, will store multiple items of different types and allow you to associate them with identifiers for later retrieval.
Like this:
JLabel label = new JLabel("Hello world");
Map map = new HashMap();
// store the lable in the map, using it's text as the key.
map.put("Hello world", label);
// or equivalently,
map.put(label.getText(), label);
// ... later on, when you want the label
JLabel helloWorldLabel = (JLabel)map.get("Hello world");
assert hellowWorldLabel==label; // true
If you must use an array, you still use a map and add the index as the value, and the identifier as the key,
Object[] DS = ...; your array, with JLabel in 124324
// When you add the object to the array, also add it's index to the map
map.put("Hello world", 124324);
//.. later when you need the value
Integer index = map.get("Hello World");
JLabel label = (JLabel)DS[index.intValue()];
Unless you have a very specific need for the array, I would just use the Map.
I hope this is what you are looking for. If not, please clarify.
精彩评论