int xhash (key, rowfile, rowkey)
keystruct *key;
rowstruct rowfile;
rowstruct rowkey;
int shash (key, rowfile, rowkey)
keystruct *key;
rowstruct rowfile;
rowstruct rowkey;
xhash creates a hash index table with a single `Offset' column and twice as many rows as the table being indexed. xhash calls hash to compute the hash value or index table row number of the key columns in each row of the table. It stores the offset of the table row at this row number in the index table. Rows in the index table which are not used are initialized to zero. Key column names are passed to xhash in the rowkey->p_heads array of the rowkey structure. Table column names are passed to xhash in the rowfile->p_heads array of the rowfile structure. It is important that the element rowfile->headlength be set correctly prior to invocation of xhash.
shash opens the hash index table associated with the table or list named by key->p_filename and searches it for key column values found in rowkey->p_columns. shash calls hash to formulate the hash index table row number and seeks to that row to retrieve the offset of the possible matching row in the table or list. The rowfile structure is used to store the rows from this table as they are examined. The key columns from rowkey are compared using keymatch() with the keycolumns from rowfile to determine if a match has been found.
If shash finds a match, and key->flags&SINGLEROW is not set, it continues to read offsets sequentially from the index table and to retrieve rows for comparison with rowkey until it hits an empty slot in the hash index table (zero offset), or it reaches the end of the table. Row offsets of matches are stored in the key->rowoffsets[] array. If key->flags&SINGLEROW is set, shash returns immediately after finding the first match.
xhash returns 0 if it successfully creates the index table and generates and stores a key for each key column found; otherwise, it returns -1.
shash returns the number of matching rows it finds or -1 if it encounters an error reading or seeking.