Reputation: 7959
My record structure is as below:- (Name,Option,StartNum,EndNum,Vacancy)
Name,Option,StartNum,EndNum form the composite keys of the sturcture/table. So for a given combination of these, there would be only one Vacancy record.
ABC,X,2,14,1
ADE,X,3,8,0
AEF,Y,1,12,2
ERF,X,12,13,17
There could be:
250-300 Names
For each Name 20-30 Options
For each Option 1-45 StartNum
For each StartNum 1-14 EndNum
For each combination of above entries, there would be only one entry for Vacancy.
So there could be maximum of 5,670,000 (300*30*45*14) entries
Can anyone please suggest the appropriate datastructure for my above requirement. The data structure building operation can be slow as its done offline, but the above mentioned two operations should be very very fast.
Thanks,
Harish
Upvotes: 0
Views: 59
Reputation: 244848
I would create a hash-map based on the tuple (Name, Option). For each of the combinations of those two, there could be a simple list, ordered by (StartNum, EndNum). Inserting into that list would be O(N) in its size, but you know that size is quite small. Another option would be some balanced binary search tree or a skip list.
If you had a good hash (which shouldn't be hard, the standard ones should work), the time complexity for retrieval would be O(1 + log(|StartNum| * |EndNum|)).
When searching as per 2., you check all values that have StartNum <= Number whether they have matching EndNum.
Upvotes: 2
Reputation: 76828
A hash-map should serve your purposes pretty well. You just have to figure out how to create a good hash for the composite key. If you already have hashes for the individual items, you can combine these using a simple XOR.
Upvotes: 0