Files
2026-06-25 00:09:09 +08:00

36 lines
1.0 KiB
C

#include "HashFile.h"
#define RECORDLEN 32
struct jtRecord {
int key;
char other[RECORDLEN - sizeof(int)];
};
#define KEYOFFSET 0
#define KEYLEN sizeof(int)
#define FILENAME "jing.hash"
void showHashFile() {
int fd = open(FILENAME, O_RDWR);
lseek(fd, sizeof(struct HashFileHeader), SEEK_SET);
struct jtRecord jt;
struct CFTag tag;
while (1) {
if (read(fd, &tag, sizeof(struct CFTag)) <= 0) break;
printf("Tag is <%d,%d>\t", tag.collision, tag.free);
if (read(fd, &jt, sizeof(struct jtRecord)) <= 0) break;
printf("Record is {%d,%s}\n", jt.key, jt.other);
}
close(fd);
}
int main() {
struct jtRecord rec[6] = {
{1,"jing"},{2,"wang"},{3,"li"},{4,"zhang"},{5,"qing"},{6,"yuan"}
};
int fd = hashfile_creat(FILENAME, O_RDWR | O_CREAT, RECORDLEN, 6);
fd = hashfile_open(FILENAME, O_RDWR, 0);
for (int i = 0; i < 6; i++)
hashfile_saverec(fd, KEYOFFSET, KEYLEN, &rec[i]);
hashfile_close(fd);
showHashFile();
return 0;
}