java.lang.Object
org.jruby.RubyBasicObject
org.jruby.RubyObject
org.jruby.RubyHash
- All Implemented Interfaces:
Serializable,Cloneable,Comparable<IRubyObject>,Map,InstanceVariables,InternalVariables,IRubyObject,CoreObjectType
- Direct Known Subclasses:
RubyHashLinkedBuckets
Implementation of the Hash class.
Concurrency: no synchronization is required among readers, but
all users must synchronize externally with writers.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classstatic classprotected static classstatic classstatic interfaceNested classes/interfaces inherited from class org.jruby.RubyObject
RubyObject.DataNested classes/interfaces inherited from class org.jruby.RubyBasicObject
RubyBasicObject.Finalizer -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final bytestatic final intstatic final int[]Deprecated.static final RubyHash.RubyHashEntryDeprecated.protected static final RubyHash.RubyHashEntryprotected static final byteprotected static final byteprotected ObjectThis field is used as part of the state of RubyHashLinkedBuckets, but when supporting legacy constructors it will point at a delegated instance.static final RubyHash.VisitorWithState<RubyArray> Fields inherited from class org.jruby.RubyObject
IVAR_INSPECTING_OBJECT_ALLOCATOR, OBJECT_ALLOCATOR, REIFYING_OBJECT_ALLOCATORFields inherited from class org.jruby.RubyBasicObject
ALL_F, BASICOBJECT_ALLOCATOR, ERR_INSECURE_SET_INST_VAR, FALSE_F, flags, FROZEN_F, metaClass, NEVER, NIL_F, STAMP_OFFSET, TAINTED_F, UNDEF, VAR_TABLE_OFFSET, varTable, varTableStampFields inherited from interface org.jruby.runtime.builtin.IRubyObject
NULL_ARRAY -
Constructor Summary
ConstructorsModifierConstructorDescriptionDeprecated.Deprecated.Deprecated.protectedRubyHash(Ruby runtime, IRubyObject defaultValue) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAll(ThreadContext context, RubyHash otherHash) <T> booleanany_p(ThreadContext context, Block block) any_p(ThreadContext context, IRubyObject pattern, Block block) assoc(ThreadContext context, IRubyObject obj) voidclear()compact(ThreadContext context) compact_bang(ThreadContext context) compare(ThreadContext context, RubyHash.VisitorWithState<RubyHash> visitor, IRubyObject other, boolean eql) compare_by_identity(ThreadContext context) compare_by_identity_p(ThreadContext context) booleancontainsKey(Object key) booleancontainsValue(Object value) Tries to convert this object to a Ruby Hash using the "to_hash" method.static IRubyObjectcreate(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) rb_hash_s_createstatic RubyClasscreateHashClass(ThreadContext context, RubyClass Object, RubyModule Enumerable) deconstruct_keys(ThreadContext context, IRubyObject _arg1) default_proc(ThreadContext context) default_value_get(ThreadContext context) default_value_get(ThreadContext context, IRubyObject arg) default_value_set(ThreadContext context, IRubyObject defaultValue) delete(IRubyObject key) delete(ThreadContext context, IRubyObject key) delete(ThreadContext context, IRubyObject key, Block block) delete_if(ThreadContext context, Block block) delete_ifInternal(ThreadContext context, Block block) dig(ThreadContext context, IRubyObject arg0) dig(ThreadContext context, IRubyObject[] args) dig(ThreadContext context, IRubyObject arg0, IRubyObject arg1) dig(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) dup(ThreadContext context) RubyMethod dup.dupFast(ThreadContext context) A lightweight dup for internal use that does not dispatch to initialize_copy nor rehash the keys.each(ThreadContext context, Block block) each_key(ThreadContext context, Block block) each_keyCommon(ThreadContext context, Block block) each_pairCommon(ThreadContext context, Block block) each_value(ThreadContext context, Block block) each_valueCommon(ThreadContext context, Block block) eachCommon(ThreadContext context, Block block) empty_p(ThreadContext context) entrySet()booleanThis override does not do a "checked" dispatch.except(ThreadContext context, IRubyObject[] keys) fastARef(IRubyObject key) voidfastASet(Ruby runtime, IRubyObject key, IRubyObject value, boolean prepareString) voidfastASet(IRubyObject key, IRubyObject value) voidfastASetCheckString(Ruby runtime, IRubyObject key, IRubyObject value) voidfastASetSmall(Ruby runtime, IRubyObject key, IRubyObject value, boolean prepareString) voidfastASetSmall(IRubyObject key, IRubyObject value) voidfastASetSmallCheckString(Ruby runtime, IRubyObject key, IRubyObject value) voidfastASetSmallPair(ThreadContext context, IRubyObject _pair) booleanfastDelete(IRubyObject key) fetch(ThreadContext context, IRubyObject[] args, Block block) fetch(ThreadContext context, IRubyObject key, Block block) fetch(ThreadContext context, IRubyObject key, IRubyObject _default, Block block) fetch_values(ThreadContext context, IRubyObject[] args, Block block) flatten(ThreadContext context) flatten(ThreadContext context, IRubyObject level) protected booleanget(int flag) Will return the Java interface that most closely can represent this object, when working through Java integration translations.This is overridden in the other concrete Java builtins to provide a fast way to determine what type they are.has_key_p(ThreadContext context, IRubyObject key) has_value_p(ThreadContext context, IRubyObject expected) booleanhash(ThreadContext context) Will return the hash code of this object.booleanhasKey(IRubyObject key) A Java API to test the presence of a (Ruby) key in the Hashinitialize(ThreadContext context, Block block) initialize(ThreadContext context, IRubyObject _default, Block block) initialize(ThreadContext context, IRubyObject _default, IRubyObject hash, Block block) initialize_copy(ThreadContext context, IRubyObject other) Initializes this object as a copy of the original, that is the parameter to this object.inspect(ThreadContext context) Returns a string containing a human-readable representation of obj.protected IRubyObjectinternalGet(IRubyObject key) internalPut(IRubyObject key, IRubyObject value) invert(ThreadContext context) booleanbooleanisEmpty()booleankeep_if(ThreadContext context, Block block) booleankeep_ifCommon(ThreadContext context, Block block) key(ThreadContext context, IRubyObject expected) keys()keys(ThreadContext context) keySet()static voidmarshalTo(RubyHash hash, MarshalStream output) Deprecated, for removal: This API element is subject to removal in a future version.static voidmarshalTo(ThreadContext context, RubyOutputStream out, RubyHash hash, MarshalDumper output) merge(ThreadContext context, IRubyObject[] others, Block block) merge_bang(ThreadContext context, IRubyObject[] others, Block block) voidmodify()static final RubyHashrb_hash_newstatic final RubyHashnewHash(Ruby runtime, Map valueMap, IRubyObject defaultValue) rb_hash_newstatic RubyHashnewHash(Ruby runtime, IRubyObject key, IRubyObject value) static RubyHashnewKwargs(Ruby runtime, String key, IRubyObject value) static final RubyHashnewSmallHash(Ruby runtime) rb_hash_newop_aref(ThreadContext context, IRubyObject key) op_aset(ThreadContext context, IRubyObject key, IRubyObject value) Set a key/value pair into this hash.op_eql(ThreadContext context, IRubyObject other) op_equal(ThreadContext context, IRubyObject other) rb_obj_equal Will by default use identity equality to compare objects.op_ge(ThreadContext context, IRubyObject other) op_gt(ThreadContext context, IRubyObject other) op_le(ThreadContext context, IRubyObject other) op_lt(ThreadContext context, IRubyObject other) voidrassoc(ThreadContext context, IRubyObject obj) rb_clear(ThreadContext context) rb_size(ThreadContext context) rb_values(ThreadContext context) rbClone(ThreadContext context) rbClone(ThreadContext context, IRubyObject opts) rehash(ThreadContext context) reject(ThreadContext context, Block block) reject_bang(ThreadContext context, Block block) reject_bangInternal(ThreadContext context, Block block) rejectInternal(ThreadContext context, Block block) replace(ThreadContext context, IRubyObject other) static IRubyObjectruby2_keywords_hash(ThreadContext context, IRubyObject _self, IRubyObject arg) static IRubyObjectruby2_keywords_hash_p(ThreadContext context, IRubyObject _self, IRubyObject arg) select(ThreadContext context, Block block) select_bang(ThreadContext context, Block block) protected voidset(int flag, boolean set) set_default_proc(ThreadContext context, IRubyObject proc) voidsetComparedByIdentity(boolean comparedByIdentity) voidsetRuby2KeywordHash(boolean value) shift(ThreadContext context) intsize()slice(ThreadContext context, IRubyObject[] args) to_a(ThreadContext context) to_h(ThreadContext context, Block block) protected RubyHashto_h_block(ThreadContext context, Block block) to_hash(ThreadContext context) to_proc(ThreadContext context) to_s(ThreadContext context) transform_keys(ThreadContext context, IRubyObject[] args, Block block) transform_keys_bang(ThreadContext context, IRubyObject[] args, Block block) transform_values(ThreadContext context, Block block) transform_values_bang(ThreadContext context, Block block) static IRubyObjecttry_convert(ThreadContext context, IRubyObject recv, IRubyObject args) static RubyHashunmarshalFrom(UnmarshalStream input, boolean defaultValue) Deprecated, for removal: This API element is subject to removal in a future version.static RubyHashunmarshalFrom(ThreadContext context, RubyInputStream in, MarshalLoader input, boolean defaultValue, boolean identity) values()values(ThreadContext context) values_at(ThreadContext context, IRubyObject[] args) final voidvisitAll(RubyHash.Visitor visitor) Deprecated.<T> voidvisitAll(ThreadContext context, RubyHash.VisitorWithStateI visitor) <T> voidvisitAll(ThreadContext context, RubyHash.VisitorWithState visitor, T state) protected <T> voidvisitLimited(ThreadContext context, RubyHash.VisitorWithState visitor, long size, T state) withRuby2Keywords(boolean ruby2Keywords) Methods inherited from class org.jruby.RubyObject
attachToObjectSpace, callInit, callInit, callInit, callInit, callInit, callInit, callInit, callInit, callInit, callInit, dig, dig1, dig2, eqlInternal, equalInternal, finishObjectClass, hashCode, inspect, op_eqq, puts, toRubyString, toStringMethods inherited from class org.jruby.RubyBasicObject
__id__, addFinalizer, addFinalizer, anyToString, asJavaString, asString, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, checkArrayType, checkCallMethod, checkCallMethod, checkFrozen, checkStringType, cloneSetup, compareTo, convertToArray, convertToFloat, convertToInteger, convertToInteger, convertToString, copyInstanceVariablesInto, copySpecialInstanceVariables, dataGetStruct, dataWrapStruct, decode, display, dup, dupFinalizer, dupSetup, ensureInstanceVariablesSettable, eql, eql_p, eql_p, equal_p, evalUnder, extend, finishBasicObjectClass, forEachInstanceVariable, forEachInstanceVariableName, freeze, frozen_p, getCurrentContext, getFFIHandle, getFlag, getInstanceEvalClass, getInstanceEvalClass, getInstanceVariable, getInstanceVariableList, getInstanceVariableNameList, getInstanceVariables, getInternalVariable, getInternalVariables, getMarshalVariableList, getMetaClass, getMetaClass, getObjectId, getRuntime, getSingletonClass, getSingletonClassClone, getSingletonClassCloneAndAttach, getSingletonClassCloneAndAttach, getType, getVariable, getVariableList, getVariableNameList, hash, hashyInspect, hashyInspect, hasInstanceVariable, hasInstanceVariables, hasInternalVariable, hasVariables, id, infectBy, initialize, initialize_copy, inspect, inspectHashCode, instance_eval, instance_eval, instance_eval, instance_eval, instance_eval, instance_exec, instance_of_p, instance_variable_defined_p, instance_variable_get, instance_variable_set, instance_variables, isBuiltin, isClass, isFalse, isFrozen, isImmediate, isModule, isNil, isSpecialConst, isSpecialObject, isTaint, isTrue, kind_of_p, makeMetaClass, makeMetaClass, makeMetaClassBootstrap, method, method, method, method_missing, methods, nil_p, nonFixnumHashCode, nonFixnumHashCode, OBJ_INIT_COPY, objInitCopy, op_cmp, op_match, op_not, op_not_equal, op_not_match, private_methods, protected_methods, public_methods, rbClone, rbInspect, remove_instance_variable, removeFinalizers, removeInstanceVariable, removeInternalVariable, respond_to_p, respondsTo, respondsToMissing, respondsToMissing, send, send, send, send, send, setFFIHandle, setFlag, setFrozen, setInstanceVariable, setInternalVariable, setMetaClass, setTaint, setVariable, singleton_method, singleton_method, singleton_method_added, singleton_method_removed, singleton_method_undefined, singleton_methods, singletonClass, specificEval, specificEval, specificEval, specificEval, syncVariables, taint, taint, tainted_p, testFrozen, testFrozen, to_s, toJava, type, untaint, validateInstanceVariable, variableTableContains, variableTableFetch, variableTableRemove, variableTableStore, variableTableSync, yieldUnder, yieldUnderMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.jruby.runtime.builtin.IRubyObject
checkStringType19, marshalLiveVariablesMethods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Field Details
-
DEFAULT_INSPECT_STR_SIZE
public static final int DEFAULT_INSPECT_STR_SIZE- See Also:
-
state
This field is used as part of the state of RubyHashLinkedBuckets, but when supporting legacy constructors it will point at a delegated instance. Once all consumers of the deprecated constructor have been migrated, we move this field back into the subclasses and eliminate all delegated methods. -
COMPARE_BY_IDENTITY
protected static final byte COMPARE_BY_IDENTITY- See Also:
-
RUBY2_KEYWORD
protected static final byte RUBY2_KEYWORD- See Also:
-
PROCDEFAULT_HASH
protected static final byte PROCDEFAULT_HASH- See Also:
-
NULL_ENTRY
-
NO_ENTRY
Deprecated. -
MRI_PRIMES
Deprecated. -
StoreValueVisitor
-
-
Constructor Details
-
RubyHash
-
RubyHash
Deprecated. -
RubyHash
Deprecated. -
RubyHash
Deprecated. -
RubyHash
Deprecated.
-
-
Method Details
-
createHashClass
public static RubyClass createHashClass(ThreadContext context, RubyClass Object, RubyModule Enumerable) -
getNativeClassIndex
Description copied from class:RubyObjectThis is overridden in the other concrete Java builtins to provide a fast way to determine what type they are. Will generally return a value from org.jruby.runtime.ClassIndex- Specified by:
getNativeClassIndexin interfaceCoreObjectType- Overrides:
getNativeClassIndexin classRubyObject- Returns:
- the ClassIndex of the native type this object was constructed from
- See Also:
-
create
public static IRubyObject create(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) rb_hash_s_create -
try_convert
-
newHash
rb_hash_new -
newSmallHash
rb_hash_new -
newKwargs
-
newHash
-
newHash
rb_hash_new -
internalPut
-
internalGet
-
visitAll
-
visitAll
-
visitLimited
protected <T> void visitLimited(ThreadContext context, RubyHash.VisitorWithState visitor, long size, T state) -
allSymbols
public <T> boolean allSymbols() -
initialize
-
initialize
-
initialize
public IRubyObject initialize(ThreadContext context, IRubyObject _default, IRubyObject hash, Block block) -
default_value_get
-
default_value_get
-
default_value_set
-
default_proc
-
set_default_proc
-
modify
public void modify() -
inspect
Description copied from class:RubyBasicObjectReturns a string containing a human-readable representation of obj. If not overridden, uses theto_smethod to generate the string. [ 1, 2, 3..4, 'five' ].inspect #=> "[1, 2, 3..4, \"five\"]" Time.new.inspect #=> "Wed Apr 09 08:54:39 CDT 2003"- Specified by:
inspectin interfaceIRubyObject- Overrides:
inspectin classRubyBasicObject
-
rb_size
-
empty_p
-
to_a
- Overrides:
to_ain classRubyBasicObject
-
to_s
- Overrides:
to_sin classRubyBasicObject
-
rehash
-
to_hash
-
to_h
-
to_h_block
-
convertToHash
Description copied from class:RubyBasicObjectTries to convert this object to a Ruby Hash using the "to_hash" method.- Specified by:
convertToHashin interfaceIRubyObject- Overrides:
convertToHashin classRubyBasicObject- Returns:
- hash representation of this
-
fastASet
-
fastASetSmall
-
fastASetSmallPair
-
fastASetCheckString
-
fastASetSmallCheckString
-
fastASet
-
fastASetSmall
-
op_aset
Set a key/value pair into this hash.- Parameters:
context- the current thread contextkey- the keyvalue- the value- Returns:
- the value set
-
fastARef
-
compare
public RubyBoolean compare(ThreadContext context, RubyHash.VisitorWithState<RubyHash> visitor, IRubyObject other, boolean eql) -
op_equal
Description copied from class:RubyBasicObjectrb_obj_equal Will by default use identity equality to compare objects. This follows the Ruby semantics. The name of this method doesn't follow the convention because hierarchy problems- Specified by:
op_equalin interfaceIRubyObject- Overrides:
op_equalin classRubyBasicObject
-
op_eql
-
op_aref
-
op_lt
-
op_le
-
op_gt
-
op_ge
-
hash
Description copied from class:RubyBasicObjectWill return the hash code of this object. In comparison to MRI, this method will use the Java identity hash code instead of using rb_obj_id, since the usage of id in JRuby will incur the cost of some. ObjectSpace maintenance.- Overrides:
hashin classRubyBasicObject- Parameters:
context- the current thread context- Returns:
- the hash value
-
fetch
-
except
-
fetch
-
fetch
-
has_key_p
-
hasKey
A Java API to test the presence of a (Ruby) key in the Hash- Parameters:
key- the native (Ruby) key- Returns:
- true if the hash contains the provided key
-
has_value_p
-
eachCommon
-
each
-
each_pairCommon
-
each_valueCommon
-
each_value
-
each_keyCommon
-
each_key
-
transform_keys
-
transform_values
-
transform_keys_bang
-
transform_values_bang
-
select_bang
-
keep_if
-
keep_ifCommon
-
key
-
keys
-
keys
-
values
-
rb_values
-
shift
-
fastDelete
-
delete
-
delete
-
delete
-
select
-
slice
-
delete_ifInternal
-
delete_if
-
rejectInternal
-
reject
-
reject_bangInternal
-
reject_bang
-
rb_clear
-
invert
-
merge_bang
-
addAll
-
merge
-
initialize_copy
Description copied from class:RubyBasicObjectInitializes this object as a copy of the original, that is the parameter to this object. Will make sure that the argument actually has the same real class as this object. It shouldn't be possible to initialize an object with something totally different.- Overrides:
initialize_copyin classRubyBasicObject- Parameters:
context- the thread contextother- the original- Returns:
- a copy unless the same thing
-
replace
-
values_at
-
fetch_values
-
assoc
-
rassoc
-
flatten
-
flatten
-
compact
-
compact_bang
-
compare_by_identity
-
compare_by_identity_p
-
dup
Description copied from interface:IRubyObjectRubyMethod dup.- Specified by:
dupin interfaceIRubyObject- Parameters:
context- the thread context- Returns:
- a dup-ed object
-
rbClone
- Overrides:
rbClonein classRubyBasicObject
-
rbClone
-
any_p
-
any_p
-
dupFast
A lightweight dup for internal use that does not dispatch to initialize_copy nor rehash the keys. Intended for use in dup'ing keyword args for processing.- Parameters:
context-- Returns:
-
withRuby2Keywords
-
hasDefaultProc
public boolean hasDefaultProc() -
getIfNone
-
deconstruct_keys
-
dig
-
dig
-
dig
-
dig
-
to_proc
-
ruby2_keywords_hash
public static IRubyObject ruby2_keywords_hash(ThreadContext context, IRubyObject _self, IRubyObject arg) -
ruby2_keywords_hash_p
public static IRubyObject ruby2_keywords_hash_p(ThreadContext context, IRubyObject _self, IRubyObject arg) -
marshalTo
@Deprecated(since="10.0.0.0", forRemoval=true) public static void marshalTo(RubyHash hash, MarshalStream output) throws IOException Deprecated, for removal: This API element is subject to removal in a future version.- Throws:
IOException
-
marshalTo
public static void marshalTo(ThreadContext context, RubyOutputStream out, RubyHash hash, MarshalDumper output) -
unmarshalFrom
@Deprecated(since="10.0.0.0", forRemoval=true) public static RubyHash unmarshalFrom(UnmarshalStream input, boolean defaultValue) throws IOException Deprecated, for removal: This API element is subject to removal in a future version.- Throws:
IOException
-
unmarshalFrom
public static RubyHash unmarshalFrom(ThreadContext context, RubyInputStream in, MarshalLoader input, boolean defaultValue, boolean identity) -
getJavaClass
Description copied from class:RubyBasicObjectWill return the Java interface that most closely can represent this object, when working through Java integration translations.- Specified by:
getJavaClassin interfaceIRubyObject- Overrides:
getJavaClassin classRubyBasicObject- Returns:
- the true Java class of this (Ruby) object
-
size
public int size() -
isEmpty
public boolean isEmpty() -
containsKey
- Specified by:
containsKeyin interfaceMap
-
containsValue
- Specified by:
containsValuein interfaceMap
-
get
-
put
-
remove
-
putAll
-
clear
public void clear() -
equals
Description copied from class:RubyObjectThis override does not do a "checked" dispatch.- Specified by:
equalsin interfaceMap- Overrides:
equalsin classRubyObject- Parameters:
other- object to compare- Returns:
- true if equals
- See Also:
-
keySet
-
values
-
entrySet
-
directKeySet
-
directValues
-
directEntrySet
-
isComparedByIdentity
public boolean isComparedByIdentity() -
setComparedByIdentity
public void setComparedByIdentity(boolean comparedByIdentity) -
isRuby2KeywordHash
public boolean isRuby2KeywordHash() -
setRuby2KeywordHash
public void setRuby2KeywordHash(boolean value) -
set
protected void set(int flag, boolean set) -
get
protected boolean get(int flag) -
visitAll
Deprecated.
-