hashaccess2.c
来自「著名的Parser库Spirit在VC6上的Port」· C语言 代码 · 共 41 行
C
41 行
/* -*- mode: c -*-
* $Id: HashAccess2.c,v 1.3 2001/10/20 15:43:19 nuffer Exp $
* http://www.bagley.org/~doug/shootout/
*/
/*
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "../../Include/simple_hash.h"
*/
int main(int argc, char *argv[]) {
int i, n = ((argc == 2) ? atoi(argv[1]) : 1);
char buf[32];
struct ht_ht *ht1 = ht_create(10000);
struct ht_ht *ht2 = ht_create(10000);
struct ht_node *node;
for (i=0; i<=9999; ++i) {
sprintf(buf, "foo_%d", i);
ht_find_new(ht1, buf)->val = i;
}
for (i=0; i<n; ++i) {
for (node=ht_first(ht1); node; node=ht_next(ht1)) {
ht_find_new(ht2, node->key)->val += node->val;
}
}
printf("%d %d %d %d\n",
(ht_find(ht1, "foo_1"))->val,
(ht_find(ht1, "foo_9999"))->val,
(ht_find(ht2, "foo_1"))->val,
(ht_find(ht2, "foo_9999"))->val);
ht_destroy(ht1);
ht_destroy(ht2);
return(0);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?