Sha256: b2e273d7c20a172fff2a043be8bc697fc8db411be5002d206da5f9637cb7dc94

Contents?: true

Size: 742 Bytes

Versions: 8

Compression:

Stored size: 742 Bytes

Contents

#include <ruby.h>
#include <stdbool.h>

#include "strmemo.h"
#include "uthash.h"

static unsigned long hash_djb2(unsigned char *str) {
  unsigned long hash = 5381;
  int c;
  while ((c = *str++)) hash = ((hash << 5) + hash) + c;
  return hash;
}

bool rs_strmemo_uniq(rs_strmemo_t **calls, unsigned char *entry) {
  rs_strmemo_t *c = NULL;
  unsigned long hashkey = hash_djb2(entry);

  HASH_FIND_INT(*calls, &hashkey, c);
  if (c != NULL) return false;

  c = ALLOC(rs_strmemo_t);
  c->key = hashkey;
  HASH_ADD_INT(*calls, key, c);
  return true;
}

void rs_strmemo_free(rs_strmemo_t *calls) {
  rs_strmemo_t *current_call, *tmp;
  HASH_ITER(hh, calls, current_call, tmp) {
    HASH_DEL(calls, current_call);
    xfree(current_call);
  }
}

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rotoscope-0.3.0.pre.6 ext/rotoscope/strmemo.c
rotoscope-0.3.0.pre.5 ext/rotoscope/strmemo.c
rotoscope-0.3.0.pre.4 ext/rotoscope/strmemo.c
rotoscope-0.3.0.pre.3 ext/rotoscope/strmemo.c
rotoscope-0.3.0.pre.2 ext/rotoscope/strmemo.c
rotoscope-0.3.0.pre.1 ext/rotoscope/strmemo.c
rotoscope-0.2.2 ext/rotoscope/strmemo.c
rotoscope-0.2.1 ext/rotoscope/strmemo.c