saoj
Joined: 05/09/2008 13:26:12
Messages: 15
Offline
|
When your collection becomes too big, even in-memory searches can become expensive. Imagine a Java collection with 1 million users and you need to find all users with the last name equals to "Smith". Iterating through all elements is clearly not an option. What you need is INDEXES.
Space4J supports 4 different types of indexes through maps, in other words, when you create an index a new Java Map is created to store the index.
The four types of index are:
Index.TYPE.REGULAR = Unique index non-sorted. This is used to get an user by its id for example, where each user has an unique id.
Index.TYPE.SORTED = Unique index sorted. This is used to get a list of users in a range of ids (ex: 4000 < id < 5000). Also used when you need to fetch users sorted by the indexed field.
Index.TYPE.MULTI = Non-unique index non-sorted. This is used to get all users with age equal to 23.
Index.TYPE.MULT_SORTED = Non-unique index sorted. This is used to get all users with age >= 23 and age <= 40. Also used when you need to fech users sorted by the indexed field.
The PhoneBookIndexing.java program provides examples of how to create and user indexes for your collections in memory. Below is the source code:
This message was edited 5 times. Last update was at 05/09/2008 16:19:12
|