Sha256: af5b0ae87bae5b79a6e06e332c7c145b7212c7bcb201ba883fa328b87afdb805
Contents?: true
Size: 1.57 KB
Versions: 1
Compression:
Stored size: 1.57 KB
Contents
#ifndef INT_FLOAT_MAP_HPP_ #define INT_FLOAT_MAP_HPP_ #include <ruby.h> #include <unordered_map> class IntFloatMap { std::unordered_map<int, double> container; public: IntFloatMap(); ~IntFloatMap(); double bracket(const int key); double bracket_equal(const int key, const double value); }; IntFloatMap::IntFloatMap() {} IntFloatMap::~IntFloatMap() {} double IntFloatMap::bracket(const int key) { return this->container[key]; } double IntFloatMap::bracket_equal(const int key, const double value) { return this->container[key] = value; } static IntFloatMap *getIntFloatMap(VALUE self) { IntFloatMap *ptr; Data_Get_Struct(self, IntFloatMap, ptr); return ptr; } static void wrap_int_float_map_free(IntFloatMap *ptr) { ptr->~IntFloatMap(); ruby_xfree(ptr); } static VALUE wrap_int_float_map_alloc(VALUE klass) { void *p = ruby_xmalloc(sizeof(IntFloatMap)); p = new IntFloatMap; return Data_Wrap_Struct(klass, NULL, wrap_int_float_map_free, p); } static VALUE wrap_int_float_map_init(VALUE self) { IntFloatMap *p = getIntFloatMap(self); p = new IntFloatMap; return Qnil; } static VALUE wrap_int_float_map_bracket(VALUE self, VALUE key) { const int k = NUM2INT(key); const double value = getIntFloatMap(self)->bracket(k); VALUE result = DBL2NUM(value); return result; } static VALUE wrap_int_float_map_bracket_equal(VALUE self, VALUE key, VALUE value) { const int k = NUM2INT(key); const double v = NUM2DBL(value); getIntFloatMap(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_float_map.hpp |