开发者

Suggestion of datastructure for a business requirement

开发者 https://www.devze.com 2023-04-12 03:58 出处:网络
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

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.

Sample Records

ABC,X,2,14,1

ADE,X,3,8,0

AEF,Y,1,12,2

ERF,X,12,13,17

There could be:

  1. 250-300 Names

  2. For each Name 20-30 Options

  3. For each Option 1-45 StartNum

  4. For each StartNum 1-14 EndNum

  5. 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

Fast operations to support

  1. Search on the composite key i.e. (Name+Option+StartNum+EndNum) and fetch it's Vacancy record value
  2. For a given Name,Option and 开发者_JAVA百科a Number, search and delete records having the given Name,Option and StartNum<=Number<=EndNum

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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号