Show More
@@ -49,7 +49,7 b' static uint32_t htonl(uint32_t x)' | |||||
49 | #include "util.h" |
|
49 | #include "util.h" | |
50 |
|
50 | |||
51 | struct line { |
|
51 | struct line { | |
52 | int h, len, n, e; |
|
52 | int hash, len, n, e; | |
53 | const char *l; |
|
53 | const char *l; | |
54 | }; |
|
54 | }; | |
55 |
|
55 | |||
@@ -65,7 +65,7 b' struct hunk {' | |||||
65 |
|
65 | |||
66 | static int splitlines(const char *a, int len, struct line **lr) |
|
66 | static int splitlines(const char *a, int len, struct line **lr) | |
67 | { |
|
67 | { | |
68 | unsigned h; |
|
68 | unsigned hash; | |
69 | int i; |
|
69 | int i; | |
70 | const char *p, *b = a; |
|
70 | const char *p, *b = a; | |
71 | const char * const plast = a + len - 1; |
|
71 | const char * const plast = a + len - 1; | |
@@ -82,14 +82,14 b' static int splitlines(const char *a, int' | |||||
82 | return -1; |
|
82 | return -1; | |
83 |
|
83 | |||
84 | /* build the line array and calculate hashes */ |
|
84 | /* build the line array and calculate hashes */ | |
85 | h = 0; |
|
85 | hash = 0; | |
86 | for (p = a; p < a + len; p++) { |
|
86 | for (p = a; p < a + len; p++) { | |
87 | /* Leonid Yuriev's hash */ |
|
87 | /* Leonid Yuriev's hash */ | |
88 | h = (h * 1664525) + (unsigned char)*p + 1013904223; |
|
88 | hash = (hash * 1664525) + (unsigned char)*p + 1013904223; | |
89 |
|
89 | |||
90 | if (*p == '\n' || p == plast) { |
|
90 | if (*p == '\n' || p == plast) { | |
91 | l->h = h; |
|
91 | l->hash = hash; | |
92 | h = 0; |
|
92 | hash = 0; | |
93 | l->len = p - b + 1; |
|
93 | l->len = p - b + 1; | |
94 | l->l = b; |
|
94 | l->l = b; | |
95 | l->n = INT_MAX; |
|
95 | l->n = INT_MAX; | |
@@ -99,7 +99,7 b' static int splitlines(const char *a, int' | |||||
99 | } |
|
99 | } | |
100 |
|
100 | |||
101 | /* set up a sentinel */ |
|
101 | /* set up a sentinel */ | |
102 | l->h = 0; |
|
102 | l->hash = 0; | |
103 | l->len = 0; |
|
103 | l->len = 0; | |
104 | l->l = a + len; |
|
104 | l->l = a + len; | |
105 | return i - 1; |
|
105 | return i - 1; | |
@@ -107,7 +107,7 b' static int splitlines(const char *a, int' | |||||
107 |
|
107 | |||
108 | static inline int cmp(struct line *a, struct line *b) |
|
108 | static inline int cmp(struct line *a, struct line *b) | |
109 | { |
|
109 | { | |
110 | return a->h != b->h || a->len != b->len || memcmp(a->l, b->l, a->len); |
|
110 | return a->hash != b->hash || a->len != b->len || memcmp(a->l, b->l, a->len); | |
111 | } |
|
111 | } | |
112 |
|
112 | |||
113 | static int equatelines(struct line *a, int an, struct line *b, int bn) |
|
113 | static int equatelines(struct line *a, int an, struct line *b, int bn) | |
@@ -140,7 +140,7 b' static int equatelines(struct line *a, i' | |||||
140 | /* add lines to the hash table chains */ |
|
140 | /* add lines to the hash table chains */ | |
141 | for (i = bn - 1; i >= 0; i--) { |
|
141 | for (i = bn - 1; i >= 0; i--) { | |
142 | /* find the equivalence class */ |
|
142 | /* find the equivalence class */ | |
143 | for (j = b[i].h & buckets; h[j].pos != INT_MAX; |
|
143 | for (j = b[i].hash & buckets; h[j].pos != INT_MAX; | |
144 | j = (j + 1) & buckets) |
|
144 | j = (j + 1) & buckets) | |
145 | if (!cmp(b + i, b + h[j].pos)) |
|
145 | if (!cmp(b + i, b + h[j].pos)) | |
146 | break; |
|
146 | break; | |
@@ -158,7 +158,7 b' static int equatelines(struct line *a, i' | |||||
158 | /* match items in a to their equivalence class in b */ |
|
158 | /* match items in a to their equivalence class in b */ | |
159 | for (i = 0; i < an; i++) { |
|
159 | for (i = 0; i < an; i++) { | |
160 | /* find the equivalence class */ |
|
160 | /* find the equivalence class */ | |
161 | for (j = a[i].h & buckets; h[j].pos != INT_MAX; |
|
161 | for (j = a[i].hash & buckets; h[j].pos != INT_MAX; | |
162 | j = (j + 1) & buckets) |
|
162 | j = (j + 1) & buckets) | |
163 | if (!cmp(a + i, b + h[j].pos)) |
|
163 | if (!cmp(a + i, b + h[j].pos)) | |
164 | break; |
|
164 | break; |
General Comments 0
You need to be logged in to leave comments.
Login now