Line | Count | Source |
1 | | /* |
2 | | ** enum.c - Enumerable module |
3 | | ** |
4 | | ** See Copyright Notice in mruby.h |
5 | | */ |
6 | | |
7 | | #include <mruby.h> |
8 | | #include <mruby/proc.h> |
9 | | |
10 | | /* internal method `__update_hash(oldhash, index, itemhash)` */ |
11 | | static mrb_value |
12 | | enum_update_hash(mrb_state *mrb, mrb_value self) |
13 | 387k | { |
14 | 387k | mrb_int hash; |
15 | 387k | mrb_int index; |
16 | 387k | mrb_int hv; |
17 | | |
18 | 387k | mrb_get_args(mrb, "iii", &hash, &index, &hv); |
19 | 387k | hash ^= ((uint32_t)hv << (index % 16)); |
20 | | |
21 | 387k | return mrb_int_value(mrb, hash); |
22 | 387k | } |
23 | | |
24 | | void |
25 | | mrb_init_enumerable(mrb_state *mrb) |
26 | 15.0k | { |
27 | 15.0k | struct RClass *enumerable = mrb_define_module_id(mrb, MRB_SYM(Enumerable)); /* 15.3.2 */ |
28 | 15.0k | mrb_define_module_function_id(mrb, enumerable, MRB_SYM(__update_hash), enum_update_hash, MRB_ARGS_REQ(3)); |
29 | 15.0k | } |