summaryrefslogtreecommitdiffstats
path: root/src/blob.c
diff options
context:
space:
mode:
authorTimo Teras <timo.teras@iki.fi>2008-11-27 20:25:01 +0200
committerTimo Teras <timo.teras@iki.fi>2008-11-27 20:25:01 +0200
commitf0609951b9fd2938c0f30853e0aa6b08b8698a88 (patch)
tree3b1f72cbaad90d715d60643c0fac98b7aaedd37e /src/blob.c
parent1a7f3e3678844165d2660ebff09da26b9ba01576 (diff)
downloadapk-tools-f0609951b9fd2938c0f30853e0aa6b08b8698a88.tar.bz2
apk-tools-f0609951b9fd2938c0f30853e0aa6b08b8698a88.tar.xz
hash, db: use apk_blob_t and list_*
Diffstat (limited to 'src/blob.c')
-rw-r--r--src/blob.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/blob.c b/src/blob.c
index f166a7a..4fea730 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -71,6 +71,26 @@ int apk_blob_splitstr(apk_blob_t blob, const char *split, apk_blob_t *l, apk_blo
}
}
+unsigned long apk_blob_hash(apk_blob_t blob)
+{
+ unsigned long hash = 5381;
+ int i;
+
+ for (i = 0; i < blob.len; i++)
+ hash = hash * 33 + blob.ptr[i];
+
+ return hash;
+}
+
+int apk_blob_compare(apk_blob_t a, apk_blob_t b)
+{
+ if (a.len == b.len)
+ return memcmp(a.ptr, b.ptr, a.len);
+ if (a.len < b.len)
+ return -1;
+ return 1;
+}
+
int apk_blob_for_each_segment(apk_blob_t blob, const char *split,
int (*cb)(void *ctx, apk_blob_t blob), void *ctx)
{