ext/template/google_hash.cpp.erb in google_hash-0.8.2 vs ext/template/google_hash.cpp.erb in google_hash-0.8.3

- old
+ new

@@ -188,16 +188,15 @@ RCallback* cbs; VALUE current_instance = Data_Make_Struct(klass, RCallback, mark_hash_map_values, free_hash_callback, cbs); // XXXX the last parameter is just a pointer? huh? cbs->hash_map = new <%= type %>_hash_map< <%= key_type %>, <%= value_type %> <%= extra_hash_params %> >(); <% if type == 'dense' %> - // cbs->hash_map->set_deleted_key(<%= unreachable_key %>); - // also needs another one ? - cbs->hash_map->set_empty_key(<%= unreachable_key %>); - <% end %> - - <% if type == 'sparse' %> + // needs both empty key and deleted keys [and different] for deletes... + cbs->hash_map->set_empty_key(<%= unreachable_key %>); + // in th eory could also call set_deleted_key "anytime" ... + cbs->hash_map->set_deleted_key((<%= unreachable_key %>)-1); // hope this is also typically unreachable from ruby land [?] + <% elsif type == 'sparse' %> cbs->hash_map->set_deleted_key(<%= unreachable_key %>); <% end %> return current_instance; } @@ -237,18 +236,18 @@ return to_this; // ltodo test that it returns value... } static VALUE rb_ghash_get(VALUE cb, VALUE get_this, int just_check_for_presence, int delete_it) { // TODO optionally not type check assert anymore [if it slows down computationally, that is...] + <%= options[:extra_get_code] %> <% if assert_key_type %> if(!(TYPE(get_this) == <%= assert_key_type %>)) { <%= "if(!(TYPE(get_this) == #{assert_key_type2}))" if assert_key_type2 %> rb_raise(rb_eTypeError, "not valid get key (expected <%=assert_key_type%>)"); } <% end %> RCallback* cbs = GetCallbackStruct(cb); - <%= options[:extra_get_code] %> <%= type %>_hash_map< <%= key_type %>, <%= value_type %> <%= extra_hash_params %> >::iterator out = cbs->hash_map->find(<%= convert_keys_from_ruby %>(get_this)); if(out == cbs->hash_map->end()) { // key not found in hashmap if(just_check_for_presence) @@ -354,13 +353,11 @@ rb_define_method(rb_cGoogleHashLocal, "[]", RUBY_METHOD_FUNC(rb_ghash_get_value), 1); rb_define_method(rb_cGoogleHashLocal, "each", RUBY_METHOD_FUNC(rb_ghash_each), 0); rb_define_method(rb_cGoogleHashLocal, "values", RUBY_METHOD_FUNC(rb_ghash_values), 0); rb_define_method(rb_cGoogleHashLocal, "keys", RUBY_METHOD_FUNC(rb_ghash_keys), 0); rb_define_method(rb_cGoogleHashLocal, "has_key?", RUBY_METHOD_FUNC(rb_ghash_get_present), 1); - <% if type == 'sparse' %> // only ones its safe on for now, till I get it figured out... - rb_define_method(rb_cGoogleHashLocal, "delete", RUBY_METHOD_FUNC(rb_ghash_delete), 1); - rb_define_method(rb_cGoogleHashLocal, "clear", RUBY_METHOD_FUNC(rb_ghash_clear), 0); - <% end %> + rb_define_method(rb_cGoogleHashLocal, "delete", RUBY_METHOD_FUNC(rb_ghash_delete), 1); + rb_define_method(rb_cGoogleHashLocal, "clear", RUBY_METHOD_FUNC(rb_ghash_clear), 0); rb_define_method(rb_cGoogleHashLocal, "key?", RUBY_METHOD_FUNC(rb_ghash_get_present), 1); rb_define_method(rb_cGoogleHashLocal, "member?", RUBY_METHOD_FUNC(rb_ghash_get_present), 1); rb_define_method(rb_cGoogleHashLocal, "include?", RUBY_METHOD_FUNC(rb_ghash_get_present), 1); rb_define_method(rb_cGoogleHashLocal, "keys_combination_2", RUBY_METHOD_FUNC(rb_ghash_combination_2), 0); rb_define_method(rb_cGoogleHashLocal, "length", RUBY_METHOD_FUNC(rb_ghash_size), 0);