Hi, first of all, a big thanks to anyone for helping me with this. I've been pulling…
- User
Hi, first of all, a big thanks to anyone for helping me with this. I've been pulling all-nighters 3 days in a row to no avail. The problem stems from my not understanding of how hashing and relative acces works (direct access files). I'm not quite sure how to explain what I need to do briefly, so here is what I'm supposed to do completely: "Write a set of programs to add, delete, and print records from a direct access file. Each record will contain: a 50 character name, a 9 character string containing a social security number, and a double containing a salary. In addition there will be a code indicating the presence or absence of a record in the physical record and an overflow flag, which will be off if there is no record for this key in the overflow area and on if there is. The hashing algorithim will be to use the social security number mod 400. This will involve using a conversion function on the last 4 digits and then using mod. The overflow area should contain 50 records. Records will be placed in the first available place in the overflow area." Ok, well, I've gotten a handle of how to add and delete records to the file using the hash function and I even know how to look up the particular file by using its hashed address location and then printing it out. However, what I don't understand is how to designate an area of the file to be the overflow area. My professor said that the overflow area would be the area after the 400th record. I understand that the hash function will generate the addresses 0 to 399 if I mod the key by 400. My question is, generally, how does hashing work? The number generated by the hash function is the address in the file, right? So if I do something like (not quite the code I've got, but close): /* algorithim 1 / address = (social_security % 10000) % 400; and then fseek(file, address, SEEK_SET); Then that will set the file marker to that particular address in my file, right? However, I've since learned that the actual whole hashing algorithim looks something like this (from a similar sample in my book): / algorithim 2 */ address = (social_security % 10000) % 400 * RECORD_SIZE; address = (address + RECORD_SIZE) % (RECORD_SIZE * FILE_SIZE); fseek(file, address, SEEK_SET); I'd explain what the #defines are, but I'm at a bit of a loss as well. The RECORD_SIZE is the size of the character strings and the double combined. Not quite sure about FILE_SIZE. Regardless, I'm just really confused about how this direct access works. I've got a hunch on something, but it may just be totally wrong. What I did was I made a loop using the second algorithim up there that ran through all the possible ssn#s (well, not really, I just modified it so that it would take a 4 digit number so I just ran from 0 to 9999) and then I recorded the highest address generated. I figure that this highest address would be the 400th record in the file and if I go beyond that address, then that could be my overflow area. Is this correct? Sorry for the long post and also how vague it may be. But I'd really appreciate any help on this! Thanks in advance!
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.