Dword VMachine::InputDword(Word address) { //0x01f0 - 0x01f7: IDE controller if(address >= 0x01f0 && address < 0x01f8) return ideController->ReadPortDword(0x01f0, static_cast<Byte>(address - 0x01f0)); //0x03f6 & 0x03f7: IDE controller if(address == 0x3f6) return ideController->ReadPortDword(0x03f0, 6); if(address == 0x3f7) return ideController->ReadPortDword(0x03f0, 7); //Otherwise, split into 2 word inputs return static_cast<Dword>(InputWord(address + 2)) << 16 | InputWord(address); }
int main(void) { size_t temp_buf = 50; // 临时单词变量长度 size_t buf_times = 1; // 哈希表表长倍数 size_t max_count = 0, max_position = 0; // 用于最后顺序查找最大值 char *temp = (char *)malloc(temp_buf); HashTable *table = (HashTable *)malloc(sizeof(HashTable) * MAX_BUF * buf_times); HashTable *curr; int strLength, i; // 单词长度 InitHashTable(table, 0, MAX_BUF * buf_times); for (i = 0; i < 50; i++) putchar('a'); while ( (strLength = InputWord(temp, temp_buf)) != 0) { if (*temp == '\0') // 如果单词为空,丢弃这个单词并继续 { continue; } i = Locate(temp, &table, strLength, &buf_times); curr = table + i; if (curr->word == NULL) { curr->word = (char *)malloc(strLength); // 根据单词长度开辟空间 strcpy(curr->word, temp); // 拷贝到目标位置 // printf("%s %s", temp, (table+i)->word); } curr->count++; } for (i = 0; i < MAX_BUF * buf_times; i++) { curr = table + i; if (curr->count > max_count) { max_position = i; max_count = curr->count; } } printf("Max Word: %s, Count: %ld\n", (table + max_position)->word, max_count); return 0; }