9a281915a40815783de9dc608a1cca3413403c5b
5 static constmap_hash
hash(s
,len
)
15 if (ch
<= 'Z' - 'A') ch
+= 'a' - 'A';
16 h
= ((h
<< 5) + h
) ^ ch
;
22 char *constmap(cm
,s
,len
)
30 pos
= cm
->first
[h
& cm
->mask
];
33 if (h
== cm
->hash
[pos
])
34 if (len
== cm
->inputlen
[pos
])
35 if (!case_diffb(cm
->input
[pos
],len
,s
))
36 return cm
->input
[pos
] + cm
->inputlen
[pos
] + 1;
42 int constmap_init(cm
,s
,len
,flagcolon
)
55 for (j
= 0;j
< len
;++j
) if (!s
[j
]) ++cm
->num
;
58 while (h
&& (h
< cm
->num
)) h
+= h
;
61 cm
->first
= (int *) alloc(sizeof(int) * h
);
64 cm
->input
= (char **) alloc(sizeof(char *) * cm
->num
);
67 cm
->inputlen
= (int *) alloc(sizeof(int) * cm
->num
);
70 cm
->hash
= (constmap_hash
*) alloc(sizeof(constmap_hash
) * cm
->num
);
73 cm
->next
= (int *) alloc(sizeof(int) * cm
->num
);
76 for (h
= 0;h
<= cm
->mask
;++h
)
80 for (j
= 0;j
< len
;++j
)
89 if (k
>= j
) { i
= j
+ 1; continue; }
92 cm
->input
[pos
] = s
+ i
;
93 cm
->inputlen
[pos
] = k
;
97 cm
->next
[pos
] = cm
->first
[h
];
104 alloc_free(cm
->hash
);
106 alloc_free(cm
->inputlen
);
108 alloc_free(cm
->input
);
110 alloc_free(cm
->first
);
115 void constmap_free(cm
)
118 alloc_free(cm
->next
);
119 alloc_free(cm
->hash
);
120 alloc_free(cm
->inputlen
);
121 alloc_free(cm
->input
);
122 alloc_free(cm
->first
);