Upgrade to 1.46.0
[platform/upstream/nghttp2.git] / third-party / mruby / src / enum.c
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 {
14   mrb_int hash;
15   mrb_int index;
16   mrb_int hv;
17
18   mrb_get_args(mrb, "iii", &hash, &index, &hv);
19   hash ^= ((uint32_t)hv << (index % 16));
20
21   return mrb_fixnum_value(hash);
22 }
23
24 void
25 mrb_init_enumerable(mrb_state *mrb)
26 {
27   struct RClass *enumerable;
28   enumerable = mrb_define_module(mrb, "Enumerable");  /* 15.3.2 */
29   mrb_define_module_function(mrb, enumerable, "__update_hash", enum_update_hash, MRB_ARGS_REQ(3));
30 }