Sha256: d0bd5ab427638732cf8494c1d5b6895e811a5c1d83afb90a7f452ea89daae901
Contents?: true
Size: 1.49 KB
Versions: 1
Compression:
Stored size: 1.49 KB
Contents
#ifndef INT_INT_MAP_HPP_ #define INT_INT_MAP_HPP_ #include <ruby.h> #include <unordered_map> class IntIntMap { std::unordered_map<int, int> container; public: IntIntMap(); ~IntIntMap(); int bracket(const int key); int bracket_equal(const int key, const int value); }; IntIntMap::IntIntMap() {} IntIntMap::~IntIntMap() {} int IntIntMap::bracket(const int key) { return this->container[key]; } int IntIntMap::bracket_equal(const int key, const int value) { return this->container[key] = value; } static IntIntMap *getIntIntMap(VALUE self) { IntIntMap *ptr; Data_Get_Struct(self, IntIntMap, ptr); return ptr; } static void wrap_int_int_map_free(IntIntMap *ptr) { ptr->~IntIntMap(); ruby_xfree(ptr); } static VALUE wrap_int_int_map_alloc(VALUE klass) { void *p = ruby_xmalloc(sizeof(IntIntMap)); p = new IntIntMap; return Data_Wrap_Struct(klass, NULL, wrap_int_int_map_free, p); } static VALUE wrap_int_int_map_init(VALUE self) { IntIntMap *p = getIntIntMap(self); p = new IntIntMap; return Qnil; } static VALUE wrap_int_int_map_bracket(VALUE self, VALUE key) { const int k = NUM2INT(key); const int value = getIntIntMap(self)->bracket(k); VALUE result = INT2NUM(value); return result; } static VALUE wrap_int_int_map_bracket_equal(VALUE self, VALUE key, VALUE value) { const int k = NUM2INT(key); const int v = NUM2INT(value); getIntIntMap(self)->bracket_equal(k, v); return value; } #endif
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
tatara-0.3.0 | ext/tatara/map/integer/int_int_map.hpp |