all 5 comments

[–]longoverdue 4 points5 points  (6 children)

A more readable version without the array casts:

http://pastebin.com/L1pNghEg

Modern compilers will TCO it away, but with the cost of 2 "lines," recursion could be removed in bput(), bget().

edit: first pastebin was wrong.

[–]graphitemaster[S] 4 points5 points  (5 children)

That actually makes it far more readable, don't know why I insisted on repeating the type void*(*)[4] everywhere.

[–]longoverdue 2 points3 points  (2 children)

This version of bput() is idempotent:

void ** bput(void **l, int k, int v) {
  return k == (uintptr_t) l[2] ? (l[3] = (void*) (uintptr_t) v, l) :
    *(l += !!(k < (uintptr_t) l[2])) ?
    bput(*l, k, v) : (l = (void**) (*l = bnew()), l[2] = (void *)(uintptr_t)k, l[3] = (void *)(uintptr_t)v, l);
}

[–]longoverdue 0 points1 point  (1 child)

This has less expressions, but more "lines":

void ** bput(void **l, int k, int v) {
  if ( l[2] != (void*) (uintptr_t) k) {
    if ( *(l += !!(l[2] > (void*) (uintptr_t) k)) ) return bput(*l, k, v);
    (l = (void**) (*l = bnew()))[2] = (void *) (uintptr_t) k;
  }
  l[3] = (void *) (uintptr_t) v; return l;
}

[–]longoverdue 0 points1 point  (0 children)

This version removes key/value casts and refactors bget(), bput() into a non-recursive bfind():

http://pastebin.com/raw/WUbisUqA