2 * Copyright (C) 1995, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.1 1995-09-04 09:10:37 adam
8 * More work on index add/del/update.
9 * Merge sort implemented.
10 * Initial work on z39 server.
22 #define KEY_SIZE (1+sizeof(struct it_key))
23 #define INP_NAME_MAX 8192
24 #define INP_BUF_START 60000
25 #define INP_BUF_ADD 400000
27 static int no_diffs = 0;
28 static int no_updates = 0;
29 static int no_insertions = 0;
30 static int no_iterations = 0;
32 static int read_one (FILE *inf, char *name, char *key)
39 if ((c=getc(inf)) == EOF)
43 for (i = 0; i<KEY_SIZE; i++)
44 ((char *)key)[i] = getc (inf);
49 static int inp (Dict dict, ISAM isam, const char *name)
53 char next_name[INP_NAME_MAX+1];
54 char cur_name[INP_NAME_MAX+1];
55 int key_buf_size = INP_BUF_START;
60 next_key = xmalloc (KEY_SIZE);
61 key_buf = xmalloc (key_buf_size * (KEY_SIZE));
62 if (!(inf = fopen (name, "r")))
64 log (LOG_FATAL|LOG_ERRNO, "cannot open `%s'", name);
67 read_one (inf, cur_name, key_buf);
68 while (cur_name[0]) /* EOF ? */
71 key_buf_ptr = KEY_SIZE;
74 if (!read_one (inf, next_name, next_key))
76 if (strcmp (next_name, cur_name))
78 memcpy (key_buf + key_buf_ptr, next_key, KEY_SIZE);
79 key_buf_ptr += KEY_SIZE;
80 if (key_buf_ptr+KEY_SIZE >= key_buf_size)
83 new_key_buf = xmalloc (key_buf_size + INP_BUF_ADD);
84 memcpy (new_key_buf, key_buf, key_buf_size);
85 key_buf_size += INP_BUF_ADD;
87 key_buf = new_key_buf;
91 nmemb = key_buf_ptr / KEY_SIZE;
92 assert (nmemb*KEY_SIZE == key_buf_ptr);
93 if ((info = dict_lookup (dict, cur_name)))
95 ISAM_P isam_p, isam_p2;
96 log (LOG_DEBUG, "updating %s", cur_name);
98 memcpy (&isam_p, info+1, sizeof(ISAM_P));
99 isam_p2 = is_merge (isam, isam_p, nmemb, key_buf);
100 if (isam_p2 != isam_p)
101 dict_insert (dict, cur_name, sizeof(ISAM_P), &isam_p2);
106 log (LOG_DEBUG, "inserting %s", cur_name);
108 isam_p = is_merge (isam, 0, nmemb, key_buf);
109 dict_insert (dict, cur_name, sizeof(ISAM_P), &isam_p);
111 memcpy (key_buf, next_key, KEY_SIZE);
112 strcpy (cur_name, next_name);
118 void key_input (const char *dict_fname, const char *isam_fname,
119 const char *key_fname, int cache)
124 dict = dict_open (dict_fname, cache, 1);
127 log (LOG_FATAL, "dict_open fail of `%s'", dict_fname);
130 isam = is_open (isam_fname, key_compare, 1);
133 log (LOG_FATAL, "is_open fail of `%s'", isam_fname);
136 inp (dict, isam, key_fname);
139 log (LOG_LOG, "Iterations . . .%7d", no_iterations);
140 log (LOG_LOG, "Distinct words .%7d", no_diffs);
141 log (LOG_LOG, "Updates. . . . .%7d", no_updates);
142 log (LOG_LOG, "Insertions . . .%7d", no_insertions);