5 static constmap_hash
hash(s
,len
)
14 if (ch
<= 'Z' - 'A') ch
+= 'a' - 'A';
15 h
= ((h
<< 5) + h
) ^ ch
;
21 char *constmap(cm
,s
,len
)
29 pos
= cm
->first
[h
& cm
->mask
];
31 if (h
== cm
->hash
[pos
])
32 if (len
== cm
->inputlen
[pos
])
33 if (!case_diffb(cm
->input
[pos
],len
,s
))
34 return cm
->input
[pos
] + cm
->inputlen
[pos
] + 1;
40 int constmap_init(cm
,s
,len
,flagcolon
)
53 for (j
= 0;j
< len
;++j
) if (!s
[j
]) ++cm
->num
;
56 while (h
&& (h
< cm
->num
)) h
+= h
;
59 cm
->first
= (int *) alloc(sizeof(int) * h
);
61 cm
->input
= (char **) alloc(sizeof(char *) * cm
->num
);
63 cm
->inputlen
= (int *) alloc(sizeof(int) * cm
->num
);
65 cm
->hash
= (constmap_hash
*) alloc(sizeof(constmap_hash
) * cm
->num
);
67 cm
->next
= (int *) alloc(sizeof(int) * cm
->num
);
69 for (h
= 0;h
<= cm
->mask
;++h
)
73 for (j
= 0;j
< len
;++j
)
80 if (k
>= j
) { i
= j
+ 1; continue; }
83 cm
->input
[pos
] = s
+ i
;
84 cm
->inputlen
[pos
] = k
;
88 cm
->next
[pos
] = cm
->first
[h
];
97 alloc_free(cm
->inputlen
);
99 alloc_free(cm
->input
);
101 alloc_free(cm
->first
);
106 void constmap_free(cm
)
109 alloc_free(cm
->next
);
110 alloc_free(cm
->hash
);
111 alloc_free(cm
->inputlen
);
112 alloc_free(cm
->input
);
113 alloc_free(cm
->first
);