Changeset 439 for EcnlProtoTool/trunk/mruby-2.1.1/include/mruby/hash.h
- Timestamp:
- Jul 9, 2020, 8:51:43 AM (4 years ago)
- Location:
- EcnlProtoTool/trunk/mruby-2.1.1
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/mruby-2.1.1/include/mruby/hash.h
r331 r439 1 /* 2 ** mruby/hash.h - Hash class1 /** 2 ** @file mruby/hash.h - Hash class 3 3 ** 4 4 ** See Copyright Notice in mruby.h … … 9 9 10 10 #include "common.h" 11 #include <mruby/khash.h>12 11 13 12 /** … … 19 18 MRB_OBJECT_HEADER; 20 19 struct iv_tbl *iv; 21 struct kh_ht*ht;20 struct htable *ht; 22 21 }; 23 22 … … 25 24 #define mrb_hash_value(p) mrb_obj_value((void*)(p)) 26 25 27 MRB_API mrb_value mrb_hash_new_capa(mrb_state*, mrb_int); 26 MRB_API mrb_value mrb_hash_new_capa(mrb_state *mrb, mrb_int capa); 27 MRB_API mrb_value mrb_ensure_hash_type(mrb_state *mrb, mrb_value hash); 28 MRB_API mrb_value mrb_check_hash_type(mrb_state *mrb, mrb_value hash); 28 29 29 30 /* … … 75 76 * Equivalent to: 76 77 * 77 * hash. hash_key?(key) ? hash[key] : def78 * hash.key?(key) ? hash[key] : def 78 79 * 79 80 * @param mrb The mruby state reference. … … 95 96 * @param hash The target hash. 96 97 * @param key The key to delete. 97 * @return The deleted value. 98 * @return The deleted value. This value is not protected from GC. Use `mrb_gc_protect()` if necessary. 98 99 */ 99 100 MRB_API mrb_value mrb_hash_delete_key(mrb_state *mrb, mrb_value hash, mrb_value key); … … 111 112 */ 112 113 MRB_API mrb_value mrb_hash_keys(mrb_state *mrb, mrb_value hash); 113 MRB_API mrb_value mrb_check_hash_type(mrb_state *mrb, mrb_value hash); 114 /* 115 * Check if the hash has the key. 116 * 117 * Equivalent to: 118 * 119 * hash.key?(key) 120 * 121 * @param mrb The mruby state reference. 122 * @param hash The target hash. 123 * @param key The key to check existence. 124 * @return True if the hash has the key 125 */ 126 MRB_API mrb_bool mrb_hash_key_p(mrb_state *mrb, mrb_value hash, mrb_value key); 114 127 115 128 /* … … 124 137 * @return True if the hash is empty, false otherwise. 125 138 */ 126 MRB_API mrb_ valuemrb_hash_empty_p(mrb_state *mrb, mrb_value self);139 MRB_API mrb_bool mrb_hash_empty_p(mrb_state *mrb, mrb_value self); 127 140 128 141 /* … … 152 165 MRB_API mrb_value mrb_hash_clear(mrb_state *mrb, mrb_value hash); 153 166 154 /* declaration of struct kh_ht */ 155 /* be careful when you touch the internal */ 156 typedef struct { 157 mrb_value v; 158 mrb_int n; 159 } mrb_hash_value; 160 161 KHASH_DECLARE(ht, mrb_value, mrb_hash_value, TRUE) 167 /* 168 * Get hash size. 169 * 170 * Equivalent to: 171 * 172 * hash.size 173 * 174 * @param mrb The mruby state reference. 175 * @param hash The target hash. 176 * @return The hash size. 177 */ 178 MRB_API mrb_int mrb_hash_size(mrb_state *mrb, mrb_value hash); 179 180 /* 181 * Copies the hash. 182 * 183 * 184 * @param mrb The mruby state reference. 185 * @param hash The target hash. 186 * @return The copy of the hash 187 */ 188 MRB_API mrb_value mrb_hash_dup(mrb_state *mrb, mrb_value hash); 189 190 /* 191 * Merges two hashes. The first hash will be modified by the 192 * second hash. 193 * 194 * @param mrb The mruby state reference. 195 * @param hash1 The target hash. 196 * @param hash2 Updating hash 197 */ 198 MRB_API void mrb_hash_merge(mrb_state *mrb, mrb_value hash1, mrb_value hash2); 162 199 163 200 /* RHASH_TBL allocates st_table if not available. */ … … 166 203 #define RHASH_IFNONE(h) mrb_iv_get(mrb, (h), mrb_intern_lit(mrb, "ifnone")) 167 204 #define RHASH_PROCDEFAULT(h) RHASH_IFNONE(h) 168 MRB_API struct kh_ht * mrb_hash_tbl(mrb_state *mrb, mrb_value hash);169 205 170 206 #define MRB_HASH_DEFAULT 1 … … 178 214 void mrb_gc_free_hash(mrb_state*, struct RHash*); 179 215 216 /* return non zero to break the loop */ 217 typedef int (mrb_hash_foreach_func)(mrb_state *mrb, mrb_value key, mrb_value val, void *data); 218 MRB_API void mrb_hash_foreach(mrb_state *mrb, struct RHash *hash, mrb_hash_foreach_func *func, void *p); 219 180 220 MRB_END_DECL 181 221
Note:
See TracChangeset
for help on using the changeset viewer.