Sha256: 425653d1080865686ea2ca3551b767532349b7ef20b403c6f3c52b6bca1b9e93

Contents?: true

Size: 590 Bytes

Versions: 6

Compression:

Stored size: 590 Bytes

Contents

#include "ruby.h"
#include "stdio.h"

static VALUE t_itu_t(VALUE self, VALUE string) {
  VALUE str = StringValue(string);
  int   n = RSTRING(str)->len;
  char* p = RSTRING(str)->ptr;
  unsigned long r = 0xFFFFFFFF;
  int i, j;

  for (i = 0; i < n; i++) {
    r = r ^ p[i];
    for (j = 0; j < 8; j++) {
      if ( (r & 1) != 0 ) {
        r = (r >> 1) ^ 0xEDB88320;
      } else {
        r = r >> 1;
      }
    }
  }
  return INT2FIX(r ^ 0xFFFFFFFF);
}

VALUE cCRC32;
void Init_crc32() {
  cCRC32 = rb_define_module("CRC32");
  rb_define_module_function(cCRC32, "itu_t", t_itu_t, 1);
}

Version data entries

6 entries across 6 versions & 6 rubygems

Version Path
fiveruns-fiveruns-memcache-client-1.5.0.3 ext/crc32/crc32.c
fiveruns-memcache-client-1.5.0.3 ext/crc32/crc32.c
myobie-memcache-client-1.5.0.3 ext/crc32/crc32.c
ninjudd-geni-memcache-client-1.5.0.3 ext/crc32/crc32.c
ninjudd-memcache-client-1.5.0.3 ext/crc32/crc32.c
ninjudd-ninjudd-memcache-client-1.5.0.3 ext/crc32/crc32.c