Top Description Inners Fields Constructors Methods
org.jruby

public Class RubyHash

extends RubyObject
implements Map
Class Inheritance
All Implemented Interfaces
java.util.Map
Known Direct Subclasses
org.jruby.ext.set.RubySet.DivideTSortHash, org.jruby.java.proxies.MapJavaProxy.RubyHashMap, org.jruby.RubyGlobal.StringOnlyRubyHash
Annotations
@JRubyClass
name:Hash
include:Enumerable
Imports
com.headius.backport9.buffer.Buffers, org.jcodings.specific.USASCIIEncoding, org.jruby.anno.JRubyClass, .JRubyMethod, org.jruby.api.Create, .Error, org.jruby.ast.util.ArgsUtil, org.jruby.exceptions.RaiseException, org.jruby.ir.runtime.IRBreakJump, org.jruby.javasupport.JavaUtil, org.jruby.runtime.Arity, .Block, .CallBlock19, .ClassIndex, .Helpers, .JavaSites.HashSites, .Signature, .ThreadContext, org.jruby.runtime.builtin.IRubyObject, org.jruby.runtime.callsite.CachingCallSite, org.jruby.runtime.marshal.MarshalDumper, .MarshalLoader, org.jruby.util.ByteList, .RecursiveComparator, .TypeConverter, org.jruby.util.io.RubyInputStream, .RubyOutputStream, java.io.IOException, java.nio.ByteBuffer, java.util.AbstractCollection, .AbstractSet, .Arrays, .Collection, .HashSet, .Iterator, .Map, .NoSuchElementException, .Set, java.util.concurrent.atomic.AtomicIntegerFieldUpdater

Implementation of the Hash class. Concurrency: no synchronization is required among readers, but all users must synchronize externally with writers.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private class
private class
private static class
private abstract static class
private abstract static class
private static class
private static class
private static class
private static class
RubyHash.Mismatch

rb_hash_equal

public static class
public abstract static class
private static class
public abstract static class
public static interface

Field Summary

Modifier and TypeField and Description
private static final RubyHash.VisitorWithState<long[]>
public static final int
public static final int
private static final RubyHash.VisitorWithState<Block>
private static final RubyHash.EntryView
private static final RubyHash.EntryView
private static final RubyHash.EntryView
private static final RubyHash.EntryView
private static final RubyHash.VisitorWithState<RubyHash>
private static final RubyHash.VisitorWithState<RubyHash>
private static final RubyHash.Found
private static final RubyHash.VisitorWithState<IRubyObject>
private static final RubyHash.VisitorWithState<IRubyObject>
private static final RubyHash.VisitorWithState<IRubyObject>
private static final RubyHash.VisitorWithState<IRubyObject>
private int
private static final ThreadLocal<ByteBuffer>
private static final int
private final RubyHash.RubyHashEntry
private IRubyObject
private static final int
private static final RubyHash.VisitorWithState<RubyString>
private static final RubyHash.VisitorWithState<RubyHash>
private static final AtomicIntegerFieldUpdater<RubyHash>
private volatile int
private static final int
private static final RubyHash.EntryView
private static final RubyHash.VisitorWithState<MarshalStream>
MarshalDumpVisitor

Deprecated for removal since 10.0.
private static final RubyHash.EntryMatchType
private static final RubyHash.EntryMatchType
private static final int
private static final int
private static final RubyHash.Mismatch
private static final boolean
private static final boolean
private static final int
public static final int[]
public static final RubyHash.RubyHashEntry
private static final int
private static final RubyHash.VisitorWithState<RubyHash>
public static final int
pack-priv static final RubyHash.VisitorWithState<T>
protected int
private static final int
private static final RubyHash.VisitorWithState<RubyArray<T extends IRubyObject>>
private static final RubyHash.VisitorWithState<RubyArray<T extends IRubyObject>>
public static final RubyHash.VisitorWithState<RubyArray<T extends IRubyObject>>
private RubyHash.RubyHashEntry[]
private int
private static final RubyHash.EntryView
private static final RubyHash.VisitorWithState<Block>
private static final RubyHash.VisitorWithState<Block>
private static final RubyHash.VisitorWithState<Block>
private static final RubyHash.VisitorWithState<Block>
Inherited from org.jruby.RubyObject:
IVAR_INSPECTING_OBJECT_ALLOCATOROBJECT_ALLOCATORREIFYING_OBJECT_ALLOCATOR

Constructor Summary

AccessConstructor and Description
private
RubyHash(Ruby runtime, RubyClass klass, RubyHash other)

public
RubyHash(Ruby runtime, RubyClass klass)

public
RubyHash(Ruby runtime, int buckets)

public
RubyHash(Ruby runtime)

public
RubyHash(Ruby runtime, IRubyObject defaultValue)

public
RubyHash(Ruby runtime, IRubyObject defaultValue, int buckets)

protected
RubyHash(Ruby runtime, RubyClass metaClass, IRubyObject defaultValue, RubyHash.RubyHashEntry[] initialTable, int threshold)

pack-priv
RubyHash(Ruby runtime, int buckets, boolean objectSpace)

public
RubyHash(Ruby runtime, Map<K, V> valueMap, IRubyObject defaultValue)

Method Summary

Modifier and TypeMethod and Description
public void
addAll(ThreadContext context, RubyHash otherHash)

private final void
private final void
private final void
allocFirst(int buckets)

public <T> boolean
public IRubyObject
any_p(ThreadContext context, Block block)

public IRubyObject
any_p(ThreadContext context, IRubyObject pattern, Block block)

public IRubyObject
any_p(ThreadContext context, IRubyObject[] args, Block block)
Deprecated

protected IRubyObject
any_p_i(ThreadContext context, Block block)

protected IRubyObject
protected IRubyObject
any_p_p(ThreadContext context, IRubyObject pattern)

protected void
appendAssociation(boolean
is the key a symbol
keyIsSymbol
,
ByteList
buffer to which to append
bytes
)

Append appropriate characters to indicate association (": " vs " => ").

public IRubyObject
aref(IRubyObject key)
Deprecated for removal. use RubyHash.op_aref instead

Note

this is included as a compatibility measure for Mongrel+JRuby

public IRubyObject
aset(IRubyObject key, IRubyObject value)
Deprecated for removal. use RubyHash.op_aset instead

Note

this is included as a compatibility measure for AR-JDBC

public IRubyObject
assoc(final ThreadContext context, final IRubyObject obj)

private static int
bucketIndex(final int h, final int length)

private void
checkDefaultProcArity(ThreadContext context, Block block)

default_proc_arity_check

protected final void
private void
public void
clear()

Implements java.util.Map.clear.

Removes all of the mappings from this map (optional operation).

public IRubyObject
public IRubyObject
public RubyBoolean
compare(final ThreadContext context, RubyHash.VisitorWithState<RubyHash> visitor, IRubyObject other, boolean eql)

public IRubyObject
public IRubyObject
private final RaiseException
public boolean
containsKey(Object
key whose presence in this map is to be tested
key
)

Implements java.util.Map.containsKey.

Returns true if this map contains a mapping for the specified key.

public boolean
containsValue(Object
value whose presence in this map is to be tested
value
)

Implements java.util.Map.containsValue.

Returns true if this map maps one or more keys to the specified value.

public RubyHash
convertToHash()

Overrides org.jruby.RubyBasicObject.convertToHash.

Implements org.jruby.runtime.builtin.IRubyObject.convertToHash.

Tries to convert this object to a Ruby Hash using the "to_hash" method.

private static void
copyFrom(RubyHash self, RubyHash other, boolean identity)

public static IRubyObject
create(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block)

rb_hash_s_create

public static RubyClass
createHashClass(ThreadContext context, RubyClass Object, RubyModule Enumerable)

public IRubyObject
public IRubyObject
default_proc(ThreadContext context)

rb_hash_default_proc

public IRubyObject
default_proc()
Deprecated

public IRubyObject
public IRubyObject
public IRubyObject
default_value_get(ThreadContext context, IRubyObject[] args)
Deprecated

rb_hash_default

public IRubyObject
default_value_set(ThreadContext context, final IRubyObject defaultValue)

rb_hash_set_default

public IRubyObject
default_value_set(final IRubyObject defaultValue)
Deprecated

public IRubyObject
delete(ThreadContext context, IRubyObject key, Block block)

rb_hash_delete

public IRubyObject
delete(IRubyObject key)

Delete entry or null.

public IRubyObject
public IRubyObject
delete_if(final ThreadContext context, final Block block)

public RubyHash
delete_ifInternal(ThreadContext context, Block block)

rb_hash_delete_if

public IRubyObject
dig(ThreadContext context, IRubyObject arg0)

public IRubyObject
public IRubyObject
public IRubyObject
dig(ThreadContext context, IRubyObject[] args)

public Set<E>
public Set<E>
public Collection<E>
public IRubyObject
dup(ThreadContext
the thread context
context
)

Overrides default org.jruby.runtime.builtin.IRubyObject.dup.

RubyMethod dup.

public RubyHash
dupFast(final ThreadContext context)

A lightweight dup for internal use that does not dispatch to initialize_copy nor rehash the keys.

public IRubyObject
each(final ThreadContext context, final Block block)

public IRubyObject
each_key(final ThreadContext context, final Block block)

public RubyHash
each_keyCommon(final ThreadContext context, final Block block)

rb_hash_each_key

public IRubyObject
each_pair(final ThreadContext context, final Block block)
Deprecated

public RubyHash
each_pairCommon(final ThreadContext context, final Block block)

rb_hash_each_pair

public RubyHash
each_pairCommon(final ThreadContext context, final Block block, final boolean oneNine)
Deprecated

public IRubyObject
each_value(final ThreadContext context, final Block block)

public RubyHash
each_valueCommon(final ThreadContext context, final Block block)

rb_hash_each_value

public RubyHash
eachCommon(final ThreadContext context, final Block block)

rb_hash_each

public RubyBoolean
empty_p(ThreadContext context)

rb_hash_empty_p

public RubyBoolean
empty_p()
Deprecated

public Set<E>
entrySet()

Implements java.util.Map.entrySet.

Returns a Set view of the mappings contained in this map.

public boolean
equals(Object
object to be compared for equality with this map
other
)

Overrides org.jruby.RubyObject.equals.

Implements java.util.Map.equals.

Compares the specified object with this map for equality.

public IRubyObject
except(ThreadContext context, IRubyObject[] keys)

public final IRubyObject
public final void
public final void
fastASet(Ruby runtime, IRubyObject key, IRubyObject value, boolean prepareString)

public final void
public final void
public final void
fastASetSmall(Ruby runtime, IRubyObject key, IRubyObject value, boolean prepareString)

public final void
public final void
public final boolean
public IRubyObject
fetch(ThreadContext context, IRubyObject[] args, Block block)

rb_hash_fetch

public IRubyObject
fetch(ThreadContext context, IRubyObject key, Block block)

public IRubyObject
fetch(ThreadContext context, IRubyObject key, IRubyObject _default, Block block)

public RubyArray<T extends IRubyObject>
fetch_values(ThreadContext context, IRubyObject[] args, Block block)

public IRubyObject
public IRubyObject
public Object
get(Object
the key whose associated value is to be returned
key
)

Implements java.util.Map.get.

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

pack-priv final RubyHash.RubyHashEntry
public IRubyObject
public Class<T>
getJavaClass()

Overrides org.jruby.RubyBasicObject.getJavaClass.

Implements org.jruby.runtime.builtin.IRubyObject.getJavaClass.

Will return the Java interface that most closely can represent this object, when working through Java integration translations.

public ClassIndex
getNativeClassIndex()

Overrides org.jruby.RubyObject.getNativeClassIndex.

Implements org.jruby.runtime.marshal.CoreObjectType.getNativeClassIndex.

This is overridden in the other concrete Java builtins to provide a fast way to determine what type they are.

public RubyBoolean
has_key_p(ThreadContext context, IRubyObject key)

rb_hash_has_key

public RubyBoolean
has_key_p(IRubyObject key)
Deprecated

public RubyBoolean
has_value_p(ThreadContext context, IRubyObject expected)

rb_hash_has_value

public boolean
public RubyFixnum
hash(ThreadContext
the current thread context
context
)

Overrides org.jruby.RubyBasicObject.hash.

Will return the hash code of this object.

private boolean
hash_le(RubyHash other)

hash_le_i

private RubyHash
private static RubyString
protected final int
public boolean

Returns:

true if the hash contains the provided key
hasKey
(IRubyObject
the native (Ruby) key
key
)

A Java API to test the presence of a (Ruby) key in the Hash

private boolean
hasValue(ThreadContext context, IRubyObject expected)

public IRubyObject
initialize(ThreadContext context, final Block block)

rb_hash_initialize

public IRubyObject
initialize(ThreadContext context, IRubyObject _default, final Block block)

public IRubyObject
initialize(ThreadContext context, IRubyObject _default, IRubyObject hash, final Block block)

public IRubyObject
initialize(IRubyObject[] args, final Block block)
Deprecated

public RubyHash
initialize_copy(ThreadContext
the thread context
context
,
IRubyObject
the original
other
)

Overrides org.jruby.RubyBasicObject.initialize_copy.

Initializes this object as a copy of the original, that is the parameter to this object.

public IRubyObject
protected RubyString
inspectHash(final ThreadContext context)

inspect_hash

private final RubyHash.RubyHashEntry[]
protected RubyHash.RubyHashEntry
private final RubyHash.RubyHashEntry
internalDelete(final int hash, final RubyHash.EntryMatchType matchType, final Object obj)

protected RubyHash.RubyHashEntry
protected IRubyObject
protected RubyHash.RubyHashEntry
private IRubyObject
internalIndex(final ThreadContext context, final IRubyObject expected)

protected final IRubyObject
internalJavaPut(final IRubyObject key, final IRubyObject value)
Deprecated

private boolean
internalKeyExist(int entryHash, IRubyObject entryKey, int hash, IRubyObject key)

public IRubyObject
internalPut(final IRubyObject key, final IRubyObject value)

private void
internalPut(final IRubyObject key, final IRubyObject value, final boolean checkForExisting)

pack-priv final boolean
internalPutIfNoKey(final IRubyObject key, final IRubyObject value)

protected IRubyObject
internalPutNoResize(final IRubyObject key, final IRubyObject value, final boolean checkForExisting)

private void
internalPutSmall(final IRubyObject key, final IRubyObject value)

protected void
internalPutSmall(final IRubyObject key, final IRubyObject value, final boolean checkForExisting)
Deprecated

public RubyHash
invert(final ThreadContext context)

rb_hash_invert

public boolean

Returns:

true if this object is compared by identity, false otherwise
isComparedByIdentity
()

Is this object compared by identity or not?

public boolean
isEmpty()

Implements java.util.Map.isEmpty.

Returns true if this map contains no key-value mappings.

public boolean
private void
private synchronized void
private void
private synchronized void
private void
private <T> void
private static int
JavaSoftBucketIndex(final int h, final int length)

private final void
private static int
public IRubyObject
keep_if(final ThreadContext context, final Block block)

public boolean
keep_ifCommon(final ThreadContext context, final Block block)

public IRubyObject
key(ThreadContext context, IRubyObject expected)

public RubyArray<T extends IRubyObject>
keys(final ThreadContext context)

rb_hash_keys

public final RubyArray<T extends IRubyObject>
keys()

public Set<E>
keySet()

Implements java.util.Map.keySet.

Returns a Set view of the keys contained in this map.

public static void
marshalTo(final RubyHash hash, final MarshalStream output)
Deprecated for removal since 10.0.

public static void
marshalTo(ThreadContext context, RubyOutputStream out, final RubyHash hash, final MarshalDumper output)

public RubyHash
merge(ThreadContext context, IRubyObject other, Block block)
Deprecated

public RubyHash
merge(ThreadContext context, IRubyObject[] others, Block block)

rb_hash_merge

public RubyHash
merge_bang(ThreadContext context, IRubyObject other, Block block)
Deprecated

public RubyHash
merge_bang(ThreadContext context, IRubyObject[] others, Block block)

rb_hash_update

public void
modify()

rb_hash_modify

private static int
MRIBucketIndex(final int h, final int length)

private final void
private static int
MRIHashValue(int h)

public static final RubyHash
newHash(Ruby runtime)

rb_hash_new

public static RubyHash
newHash(Ruby runtime, IRubyObject key, IRubyObject value)

public static final RubyHash
newHash(Ruby runtime, Map<K, V> valueMap, IRubyObject defaultValue)

rb_hash_new

public static RubyHash
newKwargs(Ruby runtime, String key, IRubyObject value)

public static final RubyHash
newSmallHash(Ruby runtime)

rb_hash_new

public IRubyObject
op_aref(ThreadContext context, IRubyObject key)

rb_hash_aref

public IRubyObject

Returns:

the value set
op_aset
(ThreadContext
the current thread context
context
,
IRubyObject
the key
key
,
IRubyObject
the value
value
)

Set a key/value pair into this hash.

public IRubyObject
op_aset(IRubyObject key, IRubyObject value)
Deprecated

protected void
protected void
public IRubyObject
op_eql(final ThreadContext context, IRubyObject other)

rb_hash_eql

public IRubyObject
public IRubyObject
public IRubyObject
public IRubyObject
public IRubyObject
private boolean
public Object
put(Object
key with which the specified value is to be associated
key
,
Object
value to be associated with the specified key
value
)

Implements java.util.Map.put.

Associates the specified value with the specified key in this map (optional operation).

public void
putAll(Map<K, V>
mappings to be stored in this map
map
)

Implements java.util.Map.putAll.

Copies all of the mappings from the specified map to this map (optional operation).

public IRubyObject
rassoc(final ThreadContext context, final IRubyObject obj)

public RubyHash
rb_clear(ThreadContext context)

rb_hash_clear

public RubyHash
rb_clear()
Deprecated

public RubyFixnum
rb_size(ThreadContext context)

rb_hash_size

public RubyFixnum
rb_size()
Deprecated

public final RubyArray<T extends IRubyObject>
public final RubyArray<T extends IRubyObject>
rb_values()
Deprecated

public IRubyObject
public IRubyObject
public RubyHash
rehash(ThreadContext context)

rb_hash_rehash

public RubyHash
rehash()
Deprecated

public IRubyObject
reject(final ThreadContext context, final Block block)

public IRubyObject
reject_bang(final ThreadContext context, final Block block)

public IRubyObject
reject_bangInternal(ThreadContext context, Block block)

rb_hash_reject_bang

public RubyHash
rejectInternal(ThreadContext context, Block block)

rb_hash_reject

public Object
remove(Object
key whose mapping is to be removed from the map
key
)

Implements java.util.Map.remove.

Removes the mapping for a key from this map if it is present (optional operation).

public RubyHash
replace(final ThreadContext
key with which the specified value is associated
context
,
IRubyObject
value to be associated with the specified key
other
)

Overrides default java.util.Map.replace.

rb_hash_replace

protected void
protected void
replaceWith(ThreadContext context, RubyHash otherHash)

private final synchronized void
resize(int newCapacity)

private void
public static IRubyObject
public static IRubyObject
public IRubyObject
select(final ThreadContext context, final Block block)

rb_hash_select

public IRubyObject
select_bang(final ThreadContext context, final Block block)

public IRubyObject
set_default_proc(ThreadContext context, IRubyObject proc)

rb_hash_set_default_proc

public IRubyObject
set_default_proc(IRubyObject proc)
Deprecated

public void
setComparedByIdentity(boolean
should this object be compared by identity?
comparedByIdentity
)

Sets whether this object is compared by identity or not.

public void
setRuby2KeywordHash(boolean value)

public IRubyObject
shift(ThreadContext context)

rb_hash_shift

private static JavaSites.HashSites
sites(ThreadContext context)

Hides org.jruby.RubyObject.sites.

Retrieve the call sites for this class.

private static IRubyObject
size(ThreadContext context, RubyHash recv, IRubyObject[] args)

A size method suitable for lambda method reference implementation of SizeFn#size(ThreadContext, IRubyObject, IRubyObject[])

public int
size()

Implements java.util.Map.size.

Returns the number of key-value mappings in this map.

public RubyHash
slice(final ThreadContext context, final IRubyObject[] args)

rb_hash_slice

public IRubyObject
sort(ThreadContext context, Block block)
Deprecated

public RubyArray<T extends IRubyObject>
to_a(ThreadContext context)

Overrides org.jruby.RubyBasicObject.to_a.

rb_hash_to_a

public RubyArray<T extends IRubyObject>
to_a()

Overrides org.jruby.RubyBasicObject.to_a.

Deprecated

public RubyHash
to_h(ThreadContext context)
Deprecated

public RubyHash
to_h(ThreadContext context, Block block)

protected RubyHash
to_h_block(ThreadContext context, Block block)

public RubyHash
to_hash(ThreadContext context)

rb_hash_to_hash

public RubyHash
to_hash()
Deprecated

public IRubyObject
public IRubyObject
to_s(ThreadContext context)

Overrides org.jruby.RubyBasicObject.to_s.

rb_hash_to_s & to_s_hash

public IRubyObject
transform_keys(final ThreadContext context, IRubyObject[] args, final Block block)

public IRubyObject
transform_keys_bang(final ThreadContext context, IRubyObject[] args, final Block block)

public IRubyObject
transform_values(final ThreadContext context, final Block block)

public IRubyObject
transform_values_bang(final ThreadContext context, final Block block)

public static IRubyObject
public static RubyHash
unmarshalFrom(UnmarshalStream input, boolean defaultValue)
Deprecated for removal since 10.0.

public static RubyHash
unmarshalFrom(ThreadContext context, RubyInputStream in, MarshalLoader input, boolean defaultValue)

public RubyArray<T extends IRubyObject>
values(final ThreadContext context)

rb_hash_values

public Collection<E>
values()

Implements java.util.Map.values.

Returns a Collection view of the values contained in this map.

public RubyArray<T extends IRubyObject>
values_at(ThreadContext context, IRubyObject[] args)

rb_hash_values_at

public <T> void
public <T> void
visitAll(ThreadContext context, RubyHash.VisitorWithState<T> visitor, T state)

public final void
visitAll(RubyHash.Visitor visitor)
Deprecated

private <T> void
visitLimited(ThreadContext context, RubyHash.VisitorWithState<T> visitor, long size, T state)

Inherited from org.jruby.RubyObject:
attachToObjectSpacecallInitcallInitcallInitcallInitcallInitcallInitcallInitcallInitcallInitcallInitconvertToTypedigdig1dig2eqlInternalequalInternalfinishObjectClasshashCodeinspectop_eqqputsspecificEvaltoRubyStringtoString