Groonga 3.0.9 Source Code Document
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
hash-ext.c
Go to the documentation of this file.
1 /*
2 ** hash.c - Hash class
3 **
4 ** See Copyright Notice in mruby.h
5 */
6 
7 #include "mruby.h"
8 #include "mruby/array.h"
9 #include "mruby/class.h"
10 #include "mruby/hash.h"
11 #include "mruby/khash.h"
12 #include "mruby/string.h"
13 #include "mruby/variable.h"
14 
15 /*
16  * call-seq:
17  * hsh.values_at(key, ...) -> array
18  *
19  * Return an array containing the values associated with the given keys.
20  * Also see <code>Hash.select</code>.
21  *
22  * h = { "cat" => "feline", "dog" => "canine", "cow" => "bovine" }
23  * h.values_at("cow", "cat") #=> ["bovine", "feline"]
24  */
25 
27 mrb_hash_values_at(mrb_state *mrb, int argc, mrb_value *argv, mrb_value hash)
28 {
29  mrb_value result = mrb_ary_new_capa(mrb, argc);
30  long i;
31 
32  for (i=0; i<argc; i++) {
33  mrb_ary_push(mrb, result, mrb_hash_get(mrb, hash, argv[i]));
34  }
35  return result;
36 }
37 
38 static mrb_value
39 hash_values_at(mrb_state *mrb, mrb_value hash)
40 {
41  mrb_value *argv;
42  int argc;
43 
44  mrb_get_args(mrb, "*", &argv, &argc);
45 
46  return mrb_hash_values_at(mrb, argc, argv, hash);
47 }
48 
49 void
51 {
52  struct RClass *h;
53 
54  h = mrb->hash_class;
55 
56  mrb_define_method(mrb, h, "values_at", hash_values_at, MRB_ARGS_ANY());
57 }
58 
59 void
61 {
62 }