Show More
@@ -117,17 +117,24 int inline cmp(struct line *a, struct li | |||
|
117 | 117 | static int equatelines(struct line *a, int an, struct line *b, int bn) |
|
118 | 118 | { |
|
119 | 119 | int i, j, buckets = 1, t; |
|
120 | int scale = 32; | |
|
120 | 121 | struct pos *h; |
|
121 | 122 | |
|
122 | 123 | /* build a hash table of the next highest power of 2 */ |
|
123 | 124 | while (buckets < bn + 1) |
|
124 | 125 | buckets *= 2; |
|
125 | 126 | |
|
126 | h = (struct pos *)malloc(buckets * sizeof(struct pos)); | |
|
127 | buckets = buckets - 1; | |
|
127 | /* try to allocate a large hash table to avoid collisions */ | |
|
128 | do { | |
|
129 | scale /= 2; | |
|
130 | h = (struct pos *)malloc(scale * buckets * sizeof(struct pos)); | |
|
131 | } while (!h && scale != 1); | |
|
132 | ||
|
128 | 133 | if (!h) |
|
129 | 134 | return 0; |
|
130 | 135 | |
|
136 | buckets = buckets * scale - 1; | |
|
137 | ||
|
131 | 138 | /* clear the hash table */ |
|
132 | 139 | for (i = 0; i <= buckets; i++) { |
|
133 | 140 | h[i].pos = -1; |
General Comments 0
You need to be logged in to leave comments.
Login now