コード例 #1
0
ファイル: hash.c プロジェクト: TJ-Hidetaka-Takano/mruby
static inline khint_t
mrb_hash_ht_hash_func(mrb_state *mrb, mrb_value key)
{
  enum mrb_vtype t = mrb_type(key);
  mrb_value hv;
  khint_t h;

  switch (t) {
  case MRB_TT_STRING:
    h = mrb_str_hash(mrb, key);
    break;

  case MRB_TT_TRUE:
  case MRB_TT_FALSE:
  case MRB_TT_SYMBOL:
  case MRB_TT_FIXNUM:
  case MRB_TT_FLOAT:
    h = (khint_t)mrb_obj_id(key);
    break;

  default:
    hv = mrb_funcall(mrb, key, "hash", 0);
    h = (khint_t)t ^ mrb_fixnum(hv);
    break;
  }
  return kh_int_hash_func(mrb, h);
}
コード例 #2
0
ファイル: jni_Value.cpp プロジェクト: ppibburr/jamruby
/*
 * Class:     org_jamruby_mruby_Value
 * Method:    n_obj_id
 * Signature: ()I
 */
JNIEXPORT jint JNICALL Java_org_jamruby_mruby_Value_n_1obj_1id
  (JNIEnv *env, jobject obj)
{
	mrb_value obj_val;
	if (!create_mrb_value(getEnv(), obj, obj_val)) {
		// MEMO invalid object id is undefined.
		return 0;
	}
	return mrb_obj_id(obj_val);
}
コード例 #3
0
ファイル: kernel.c プロジェクト: Bovi-Li/mruby
/*
 *  call-seq:
 *     obj.hash    -> fixnum
 *
 *  Generates a <code>Fixnum</code> hash value for this object. This
 *  function must have the property that <code>a.eql?(b)</code> implies
 *  <code>a.hash == b.hash</code>. The hash value is used by class
 *  <code>Hash</code>. Any hash value that exceeds the capacity of a
 *  <code>Fixnum</code> will be truncated before being used.
 */
mrb_value
mrb_obj_hash(mrb_state *mrb, mrb_value self)
{
  return mrb_fixnum_value(mrb_obj_id(self));
}