Is it possible to use hash function but with File instead of Array, and it’s gonna be saving the record in a file position and then search will fseek to that position, but I’m not sure how to open a file with let’s say 1000 line, do you think that method could work?
4
Sure, if you have a hashing function that can neatly map your data. Two things to keep an eye on:
- Does your OS/file system support sparse files? Can you seek beyond the end of the file and write a new record without intervening data?
- How are you going to handle hash collisions? Will each record have some kind of header that contains a pointer to the next bucket in an overflow chain, or will you just overflow into the next available slot? If you just go to the next slot, how will you tell if it’s available?
I’d recommend reading up on ISAM files, they’re pretty close to what you’re looking to do.
1