| 1 |
/* Copyright (c) 1987, 1989, 2012 University of Maryland Department of |
| 2 |
Computer Science. |
| 3 |
|
| 4 |
Permission is hereby granted, free of charge, to any person obtaining |
| 5 |
a copy of this software and associated documentation files (the |
| 6 |
"Software"), to deal in the Software without restriction, including |
| 7 |
without limitation, the rights to use, copy, modify, merge, publish, |
| 8 |
distribute, sublicense, and/or sell copies of the Software, and to |
| 9 |
permit persons to whom the Software is furnished to do so, subject to |
| 10 |
the following conditions: The above copyright notice, this permission |
| 11 |
notice and the disclaimer statement shall be included in all copies |
| 12 |
or substantial portions of the Software. |
| 13 |
|
| 14 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 15 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 16 |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 17 |
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 18 |
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 19 |
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 20 |
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 21 |
*/ |
| 22 |
|
| 23 |
/* search structures and routines for 32-bit key, arbitrary data */ |
| 24 |
|
| 25 |
struct search { |
| 26 |
unsigned s_dsize; /* data object size (includes key size) */ |
| 27 |
unsigned s_space; /* space left (in terms of objects) */ |
| 28 |
unsigned s_n; /* number of objects in the table */ |
| 29 |
char *s_data; /* data area */ |
| 30 |
}; |
| 31 |
|
| 32 |
/* returns a pointer to the search table (for future search/installs) */ |
| 33 |
struct search *SCreate(unsigned int dsize); /* create a search table */ |
| 34 |
|
| 35 |
/* returns a pointer to the data object found or created */ |
| 36 |
char *SSearch(struct search *s, i32 key, int *disp); /* search for a data object */ |
| 37 |
|
| 38 |
/* clears a search table (wipes out all entries) */ |
| 39 |
#define SClear(s) ((s)->s_space += (s)->s_n, (s)->s_n = 0) |
| 40 |
|
| 41 |
/* the third argument to SSearch controls operation as follows: */ |
| 42 |
#define S_LOOKUP 0x00 /* pseudo flag */ |
| 43 |
#define S_CREATE 0x01 /* create object if not found */ |
| 44 |
#define S_EXCL 0x02 /* complain if already exists */ |
| 45 |
|
| 46 |
/* in addition, it is modified before return to hold status: */ |
| 47 |
#define S_COLL 0x04 /* collision (occurs iff S_EXCL set) */ |
| 48 |
#define S_FOUND 0x08 /* found (occurs iff existed already) */ |
| 49 |
#define S_NEW 0x10 /* created (occurs iff S_CREATE && !S_EXCL) */ |
| 50 |
#define S_ERROR 0x20 /* problem creating (out of memory) */ |
| 51 |
|
| 52 |
void SEnumerate(struct search *s, void(*f)(char*,i32)); |