Пример #1
0
static uint64_t
ev_item_hash(ev_item_t *ev)
{
    if (ev->hash == 0) {
        union {
            int *i;
            const unsigned char *c;
            uint64_t *h;
        } u;

        u.i = &ev->ty;
        ev->hash = fasthash(0, u.c, sizeof(ev->ty));
        if (ev->ty == EV_TYPE_IO) {
            int _events;
            u.i = &ev->ev.io.fd;
            ev->hash = fasthash(ev->hash, u.c, sizeof(ev->ev.io.fd));
            _events = ev->ev.io.events & ~EV__IOFDSET;
            u.i = &_events;
            ev->hash = fasthash(ev->hash, u.c, sizeof(_events));
        } else if (ev->ty == EV_TYPE_STAT) {
            uint64_t h;
            h = bytes_hash(ev->stat_path);
            u.h = &h;
            ev->hash = fasthash(ev->hash, u.c, sizeof(u.h));
        } else {
            CTRACE("ev->ty=%d", ev->ty);
            FAIL("ev_item_hash");
        }
    }
    return ev->hash;
}
Пример #2
0
static int ipaddr_hash(Value *vret, Value *v, RefNode *node)
{
    RefSockAddr *rs = Value_vp(*v);
    const char *p = sockaddr_bytes(rs->addr);
    int size = sockaddr_bytes_count(rs->addr);

    *vret = int32_Value(bytes_hash(p, size));
    return TRUE;
}