diff options
author | Ori Bernstein <ori@eigenstate.org> | 2021-05-16 18:49:45 -0700 |
---|---|---|
committer | Ori Bernstein <ori@eigenstate.org> | 2021-05-16 18:49:45 -0700 |
commit | 1ee1bfaa8c5644092e0c1ca3985ee74813bbfb1d (patch) | |
tree | 9be6163e8bcd0bd43b4016e2bfeb9571a548536e /sys/src/cmd/git/objset.c | |
parent | 013b2cad191eef50fd4e69c38f1544c5083b640d (diff) |
git: got git?
Add a snapshot of git9 to 9front.
Diffstat (limited to 'sys/src/cmd/git/objset.c')
-rw-r--r-- | sys/src/cmd/git/objset.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/sys/src/cmd/git/objset.c b/sys/src/cmd/git/objset.c new file mode 100644 index 000000000..d0c656c53 --- /dev/null +++ b/sys/src/cmd/git/objset.c @@ -0,0 +1,67 @@ +#include <u.h> +#include <libc.h> + +#include "git.h" + +void +osinit(Objset *s) +{ + s->sz = 16; + s->nobj = 0; + s->obj = eamalloc(s->sz, sizeof(Hash)); +} + +void +osclear(Objset *s) +{ + free(s->obj); +} + +void +osadd(Objset *s, Object *o) +{ + u32int probe; + Object **obj; + int i, sz; + + probe = GETBE32(o->hash.h) % s->sz; + while(s->obj[probe]){ + if(hasheq(&s->obj[probe]->hash, &o->hash)){ + s->obj[probe] = o; + return; + } + probe = (probe + 1) % s->sz; + } + assert(s->obj[probe] == nil); + s->obj[probe] = o; + s->nobj++; + if(s->sz < 2*s->nobj){ + sz = s->sz; + obj = s->obj; + + s->sz *= 2; + s->nobj = 0; + s->obj = eamalloc(s->sz, sizeof(Hash)); + for(i = 0; i < sz; i++) + if(obj[i]) + osadd(s, obj[i]); + free(obj); + } +} + +Object* +osfind(Objset *s, Hash h) +{ + u32int probe; + + for(probe = GETBE32(h.h) % s->sz; s->obj[probe]; probe = (probe + 1) % s->sz) + if(hasheq(&s->obj[probe]->hash, &h)) + return s->obj[probe]; + return 0; +} + +int +oshas(Objset *s, Hash h) +{ + return osfind(s, h) != nil; +} |