Changeset 331 for EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/hash.h
- Timestamp:
- Jan 21, 2018, 12:10:09 AM (6 years ago)
- Location:
- EcnlProtoTool/trunk/mruby-1.3.0
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/mruby-1.3.0/include/mruby/hash.h
r321 r331 8 8 #define MRUBY_HASH_H 9 9 10 #include "mruby/common.h" 10 #include "common.h" 11 #include <mruby/khash.h> 11 12 12 13 /** … … 24 25 #define mrb_hash_value(p) mrb_obj_value((void*)(p)) 25 26 26 MRB_API mrb_value mrb_hash_new_capa(mrb_state*, int);27 MRB_API mrb_value mrb_hash_new_capa(mrb_state*, mrb_int); 27 28 28 29 /* 29 30 * Initializes a new hash. 31 * 32 * Equivalent to: 33 * 34 * Hash.new 35 * 36 * @param mrb The mruby state reference. 37 * @return The initialized hash. 30 38 */ 31 39 MRB_API mrb_value mrb_hash_new(mrb_state *mrb); … … 33 41 /* 34 42 * Sets a keys and values to hashes. 43 * 44 * Equivalent to: 45 * 46 * hash[key] = val 47 * 48 * @param mrb The mruby state reference. 49 * @param hash The target hash. 50 * @param key The key to set. 51 * @param val The value to set. 52 * @return The value. 35 53 */ 36 54 MRB_API void mrb_hash_set(mrb_state *mrb, mrb_value hash, mrb_value key, mrb_value val); 37 55 38 56 /* 39 * Gets a value from a key. 57 * Gets a value from a key. If the key is not found, the default of the 58 * hash is used. 59 * 60 * Equivalent to: 61 * 62 * hash[key] 63 * 64 * @param mrb The mruby state reference. 65 * @param hash The target hash. 66 * @param key The key to get. 67 * @return The found value. 40 68 */ 41 69 MRB_API mrb_value mrb_hash_get(mrb_state *mrb, mrb_value hash, mrb_value key); 42 70 71 /* 72 * Gets a value from a key. If the key is not found, the default parameter is 73 * used. 74 * 75 * Equivalent to: 76 * 77 * hash.hash_key?(key) ? hash[key] : def 78 * 79 * @param mrb The mruby state reference. 80 * @param hash The target hash. 81 * @param key The key to get. 82 * @param def The default value. 83 * @return The found value. 84 */ 43 85 MRB_API mrb_value mrb_hash_fetch(mrb_state *mrb, mrb_value hash, mrb_value key, mrb_value def); 44 86 45 87 /* 46 88 * Deletes hash key and value pair. 89 * 90 * Equivalent to: 91 * 92 * hash.delete(key) 93 * 94 * @param mrb The mruby state reference. 95 * @param hash The target hash. 96 * @param key The key to delete. 97 * @return The deleted value. 47 98 */ 48 99 MRB_API mrb_value mrb_hash_delete_key(mrb_state *mrb, mrb_value hash, mrb_value key); … … 50 101 /* 51 102 * Gets an array of keys. 103 * 104 * Equivalent to: 105 * 106 * hash.keys 107 * 108 * @param mrb The mruby state reference. 109 * @param hash The target hash. 110 * @return An array with the keys of the hash. 52 111 */ 53 112 MRB_API mrb_value mrb_hash_keys(mrb_state *mrb, mrb_value hash); 54 113 MRB_API mrb_value mrb_check_hash_type(mrb_state *mrb, mrb_value hash); 114 115 /* 116 * Check if the hash is empty 117 * 118 * Equivalent to: 119 * 120 * hash.empty? 121 * 122 * @param mrb The mruby state reference. 123 * @param self The target hash. 124 * @return True if the hash is empty, false otherwise. 125 */ 55 126 MRB_API mrb_value mrb_hash_empty_p(mrb_state *mrb, mrb_value self); 56 127 57 128 /* 129 * Gets an array of values. 130 * 131 * Equivalent to: 132 * 133 * hash.values 134 * 135 * @param mrb The mruby state reference. 136 * @param hash The target hash. 137 * @return An array with the values of the hash. 138 */ 139 MRB_API mrb_value mrb_hash_values(mrb_state *mrb, mrb_value hash); 140 141 /* 58 142 * Clears the hash. 143 * 144 * Equivalent to: 145 * 146 * hash.clear 147 * 148 * @param mrb The mruby state reference. 149 * @param hash The target hash. 150 * @return The hash 59 151 */ 60 152 MRB_API mrb_value mrb_hash_clear(mrb_state *mrb, mrb_value hash); 153 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) 61 162 62 163 /* RHASH_TBL allocates st_table if not available. */ … … 67 168 MRB_API struct kh_ht * mrb_hash_tbl(mrb_state *mrb, mrb_value hash); 68 169 69 #define MRB_HASH_PROC_DEFAULT 256 170 #define MRB_HASH_DEFAULT 1 171 #define MRB_HASH_PROC_DEFAULT 2 172 #define MRB_RHASH_DEFAULT_P(h) (RHASH(h)->flags & MRB_HASH_DEFAULT) 70 173 #define MRB_RHASH_PROCDEFAULT_P(h) (RHASH(h)->flags & MRB_HASH_PROC_DEFAULT) 71 174
Note:
See TracChangeset
for help on using the changeset viewer.