-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bisect: refactor sha1_array into a generic sha1 list
This is a generally useful abstraction, so let's let others make use of it. The refactoring is more or less a straight copy; however, functions and struct members have had their names changed to match string_list, which is the most similar data structure. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
- v2.3.0
- v2.3.0-rc2
- v2.3.0-rc1
- v2.3.0-rc0
- v2.2.2
- v2.2.1
- v2.2.0
- v2.2.0-rc3
- v2.2.0-rc2
- v2.2.0-rc1
- v2.2.0-rc0
- v2.1.4
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1.0
- v2.1.0-rc2
- v2.1.0-rc1
- v2.1.0-rc0
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v2.0.0-rc4
- v2.0.0-rc3
- v2.0.0-rc2
- v2.0.0-rc1
- v2.0.0-rc0
- v1.9.5
- v1.9.4
- v1.9.3
- v1.9.2
- v1.9.1
- v1.9.0
- v1.9.0-rc3
- v1.9-rc2
- v1.9-rc1
- v1.9-rc0
- v1.8.5.6
- v1.8.5.5
- v1.8.5.4
- v1.8.5.3
- v1.8.5.2
- v1.8.5.1
- v1.8.5
- v1.8.5-rc3
- v1.8.5-rc2
- v1.8.5-rc1
- v1.8.5-rc0
- v1.8.4.5
- v1.8.4.4
- v1.8.4.3
- v1.8.4.2
- v1.8.4.1
- v1.8.4
- v1.8.4-rc4
- v1.8.4-rc3
- v1.8.4-rc2
- v1.8.4-rc1
- v1.8.4-rc0
- v1.8.3.4
- v1.8.3.3
- v1.8.3.2
- v1.8.3.1
- v1.8.3
- v1.8.3-rc3
- v1.8.3-rc2
- v1.8.3-rc1
- v1.8.3-rc0
- v1.8.2.3
- v1.8.2.2
- v1.8.2.1
- v1.8.2
- v1.8.2-rc3
- v1.8.2-rc2
- v1.8.2-rc1
- v1.8.2-rc0
- v1.8.1.6
- v1.8.1.5
- v1.8.1.4
- v1.8.1.3
- v1.8.1.2
- v1.8.1.1
- v1.8.1
- v1.8.1-rc3
- v1.8.1-rc2
- v1.8.1-rc1
- v1.8.1-rc0
- v1.8.0.3
- v1.8.0.2
- v1.8.0.1
- v1.8.0
- v1.8.0-rc3
- v1.8.0-rc2
- v1.8.0-rc1
- v1.8.0-rc0
- v1.7.12.4
- v1.7.12.3
- v1.7.12.2
- v1.7.12.1
- v1.7.12
- v1.7.12-rc3
- v1.7.12-rc2
- v1.7.12-rc1
- v1.7.12-rc0
- v1.7.11.7
- v1.7.11.6
- v1.7.11.5
- v1.7.11.4
- v1.7.11.3
- v1.7.11.2
- v1.7.11.1
- v1.7.11
- v1.7.11-rc3
- v1.7.11-rc2
- v1.7.11-rc1
- v1.7.11-rc0
- v1.7.10.5
- v1.7.10.4
- v1.7.10.3
- v1.7.10.2
- v1.7.10.1
- v1.7.10
- v1.7.10-rc4
- v1.7.10-rc3
- v1.7.10-rc2
- v1.7.10-rc1
- v1.7.10-rc0
- v1.7.9.7
- v1.7.9.6
- v1.7.9.5
- v1.7.9.4
- v1.7.9.3
- v1.7.9.2
- v1.7.9.1
- v1.7.9
- v1.7.9-rc2
- v1.7.9-rc1
- v1.7.9-rc0
- v1.7.8.6
- v1.7.8.5
- v1.7.8.4
- v1.7.8.3
- v1.7.8.2
- v1.7.8.1
- v1.7.8
- v1.7.8-rc4
- v1.7.8-rc3
- v1.7.8-rc2
- v1.7.8-rc1
- v1.7.8-rc0
- v1.7.7.7
- v1.7.7.6
- v1.7.7.5
- v1.7.7.4
- v1.7.7.3
- v1.7.7.2
- v1.7.7.1
- v1.7.7
- v1.7.7-rc3
- v1.7.7-rc2
- v1.7.7-rc1
- v1.7.7-rc0
- v1.7.6.6
- v1.7.6.5
- v1.7.6.4
- v1.7.6.3
- v1.7.6.2
- v1.7.6.1
- v1.7.6
- v1.7.6-rc3
- v1.7.6-rc2
- v1.7.6-rc1
- v1.7.6-rc0
Showing
4 changed files
with
78 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include "cache.h" | ||
#include "sha1-array.h" | ||
#include "sha1-lookup.h" | ||
|
||
void sha1_array_append(struct sha1_array *array, const unsigned char *sha1) | ||
{ | ||
ALLOC_GROW(array->sha1, array->nr + 1, array->alloc); | ||
hashcpy(array->sha1[array->nr++], sha1); | ||
array->sorted = 0; | ||
} | ||
|
||
static int void_hashcmp(const void *a, const void *b) | ||
{ | ||
return hashcmp(a, b); | ||
} | ||
|
||
void sha1_array_sort(struct sha1_array *array) | ||
{ | ||
qsort(array->sha1, array->nr, sizeof(*array->sha1), void_hashcmp); | ||
array->sorted = 1; | ||
} | ||
|
||
static const unsigned char *sha1_access(size_t index, void *table) | ||
{ | ||
unsigned char (*array)[20] = table; | ||
return array[index]; | ||
} | ||
|
||
int sha1_array_lookup(struct sha1_array *array, const unsigned char *sha1) | ||
{ | ||
if (!array->sorted) | ||
sha1_array_sort(array); | ||
return sha1_pos(sha1, array->sha1, array->nr, sha1_access); | ||
} | ||
|
||
void sha1_array_clear(struct sha1_array *array) | ||
{ | ||
free(array->sha1); | ||
array->sha1 = NULL; | ||
array->nr = 0; | ||
array->alloc = 0; | ||
array->sorted = 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#ifndef SHA1_ARRAY_H | ||
#define SHA1_ARRAY_H | ||
|
||
struct sha1_array { | ||
unsigned char (*sha1)[20]; | ||
int nr; | ||
int alloc; | ||
int sorted; | ||
}; | ||
|
||
#define SHA1_ARRAY_INIT { NULL, 0, 0, 0 } | ||
|
||
void sha1_array_append(struct sha1_array *array, const unsigned char *sha1); | ||
void sha1_array_sort(struct sha1_array *array); | ||
int sha1_array_lookup(struct sha1_array *array, const unsigned char *sha1); | ||
void sha1_array_clear(struct sha1_array *array); | ||
|
||
#endif /* SHA1_ARRAY_H */ |