/*TITLE supermarket pricing include file */ /****keyword-flag*** "%v %f %n" */ /* "11 20-Mar-98,20:29:58 SUPERM.H" */ #include #include #include "radix40.h" #include "bcdconv.h" const int DESCRIPTION_WORDS = 7; const int DESCRIPTION_CHARS = (CPW*DESCRIPTION_WORDS); const int FILE_CAPACITY = 1000; const unsigned FILE_SIZE = ((unsigned)(FILE_CAPACITY*1.25)); const int BCD_KEY_SIZE = 5; const int ASCII_KEY_SIZE = (BCD_KEY_SIZE*2); const unsigned char INVALID_BCD_VALUE = 0xFF; const unsigned char DELETED_BCD_VALUE = 0xFE; const unsigned INVALID_RECORD_NUMBER = 0xFFFF; const int MAPPING_FACTOR = 8; /* how many slots can be used by any one record */ const double CACHE_FACTOR = .20; const int APPROXIMATE_CACHE_SIZE = (max(int(FILE_CAPACITY*CACHE_FACTOR),MAPPING_FACTOR)); const unsigned CACHE_SIZE = ((unsigned)(APPROXIMATE_CACHE_SIZE/MAPPING_FACTOR)*MAPPING_FACTOR); typedef struct // ItemRecord struct { BCD upc[BCD_KEY_SIZE]; Radix40 description[DESCRIPTION_WORDS]; unsigned price; } ItemRecord; typedef struct // PriceFile struct { FILE *dos_file_stream; ItemRecord **item_cache; unsigned *file_record_number; } PriceFile; const int QUESTIONABLE = 0; const int FOUND = 1; const int NOT_IN_FILE = 2; const int FILE_FULL = 3; const int INPUT_MODE = 0; const int LOOKUP_MODE = 1; const int CLEAR_FILE = 0; const int KEEP_FILE = 1; unsigned compute_hash(char *key_value); unsigned compute_file_hash(char *key_value); unsigned compute_cache_hash(char *key_value); int lookup_record(PriceFile* price_file, char *ascii_key_value, ItemRecord **item_record); int lookup_record_number(PriceFile* price_file, char *ascii_key_value, unsigned *record_number); int write_record(PriceFile* price_file, ItemRecord new_record); unsigned compute_starting_cache_hash(unsigned cache_index); unsigned compute_ending_cache_hash(unsigned cache_index); PriceFile* initialize_price_file(char *price_file_name, int file_mode); void terminate_price_file(PriceFile* price_file); void position_record(PriceFile* price_file, unsigned record_number); int lookup_record_and_number(PriceFile* price_file, char *ascii_key_value, ItemRecord **item_record, unsigned *record_number);