Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef struct
- {
- char key[MAX_KEYLEN];
- int rec;
- } KeyRecPair;
- typedef struct
- {
- KeyRecPair *map;
- int numRecs;
- } KeyRecMap;
- int GetRecFromKey(char *key, KeyRecMap *theMap)
- {
- int cmpValue, bottom = 0;
- int half = theMap->numRecs / 2;
- int top = theMap->numRecs - 1;
- while (bottom != top)
- {
- cmpValue = strncmp(key, theMap->map[half].key, MAX_KEY_LEN);
- if (cmpValue > 0)
- {
- /*top stays*/
- bottom = half + 1;
- half = bottom + (top - bottom) / 2;
- continue;
- }
- if (cmpValue < 0)
- {
- /*bottom stays*/
- top = half - 1;
- half = bottom + (top - bottom) / 2;
- continue;
- }
- return theMap->map[half].rec;
- }
- if (0 == strncmp(key, theMap->map[half].key, MAX_KEY_LEN))
- return theMap->map[half].rec;
- return 0;
- }
- if (cmpValue > 0)
- {
- /*top stays*/
- bottom = half + 1;
- half = bottom + (top - bottom) * 3 / 5;
- continue;
- }
- if (cmpValue < 0)
- {
- /*bottom stays*/
- top = half - 1;
- half = bottom + (top - bottom) * 2 / 5;
- continue;
- }
- ; 30 : if (cmpValue > 0)
- test eax, eax
- jle SHORT $LN11@GetRecFrom
- ; 31 : {
- ; omitted inner block for > case.
- $LN11@GetRecFrom:
- ; 37 : if (cmpValue < 0)
- jge SHORT $LN2@GetRecFrom
Add Comment
Please, Sign In to add comment