Package org.jruby.ext.set
Class RubySet
java.lang.Object
org.jruby.RubyBasicObject
org.jruby.RubyObject
org.jruby.ext.set.RubySet
- All Implemented Interfaces:
Serializable,Cloneable,Comparable<IRubyObject>,Iterable,Collection,Set,InstanceVariables,InternalVariables,IRubyObject,CoreObjectType
- Direct Known Subclasses:
RubySortedSet
Native implementation of Ruby's Set (set.rb replacement).
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classprivate static classprivate static final classNested classes/interfaces inherited from class org.jruby.RubyObject
RubyObject.DataNested classes/interfaces inherited from class org.jruby.RubyBasicObject
RubyBasicObject.Finalizer -
Field Summary
FieldsFields 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, COMPARE_BY_IDENTITY_F, ERR_INSECURE_SET_INST_VAR, FALSE_F, FL_USHIFT, flags, FROZEN_F, IS_OVERLAID_F, metaClass, NEVER, NIL_F, REFINED_MODULE_F, STAMP_OFFSET, TAINTED_F, UNDEF, UNTRUST_F, USER0_F, USER1_F, USER2_F, USER3_F, USER4_F, USER5_F, USER6_F, USER7_F, USER8_F, USER9_F, USERA_F, VAR_TABLE_OFFSET, varTable, varTableStampFields inherited from interface org.jruby.runtime.builtin.IRubyObject
NULL_ARRAY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanadd(ThreadContext context, IRubyObject obj) Adds the given object to the set and returns self.add_p(ThreadContext context, IRubyObject obj) Adds the given object to the set and returns self.booleanaddAll(Collection coll) private voidaddFlattened(ThreadContext context, IdentityHashMap seen, IRubyObject e) protected voidaddImpl(Ruby runtime, IRubyObject obj) protected voidaddImplSet(ThreadContext context, RubySet set) private boolean(package private) final void(package private) final voidclassify(ThreadContext context, Block block) voidclear()protected voidcollect_bang(ThreadContext context, Block block) compare_by_identity(ThreadContext context) compare_by_identity_p(ThreadContext context) booleanbooleancontainsAll(Collection coll) (package private) final booleancontainsImpl(IRubyObject obj) static RubySetcreate(ThreadContext context, IRubyObject self, IRubyObject... ary) Creates a new set containing the given objects.(package private) static RubyClasscreateSetClass(Ruby runtime) delete(ThreadContext context, IRubyObject obj) delete_if(ThreadContext context, Block block) delete_p(ThreadContext context, IRubyObject obj) Deletes the given object from the set and returns self.protected booleandeleteImpl(IRubyObject obj) protected voiddeleteImplIterator(IRubyObject obj, Iterator it) disjoint_p(ThreadContext context, IRubyObject set) Returns true if the set and the given set have no element in common.divide(ThreadContext context, Block block) Divides the set into a set of subsets according to the commonality defined by the given block.private IRubyObjectdivideTSort(ThreadContext context, Block block) private static IRubyObjectdoWithEnum(ThreadContext context, IRubyObject enume, RubySet.EachBody blockImpl) each(ThreadContext context, Block block) protected final Set<IRubyObject>elements()protected Set<IRubyObject>empty_p(ThreadContext context) booleaneql(IRubyObject other) method used for Hash key comparison (specialized for String, Symbol and Fixnum) Will by default just call the Ruby method "eql?"flatten(ThreadContext context) flatten_bang(ThreadContext context) flatten_merge(ThreadContext context, IRubyObject set) private voidflattenMerge(ThreadContext context, IRubyObject set, IdentityHashMap seen) freeze(ThreadContext context) rb_obj_freeze call-seq: obj.freeze => obj Prevents further modifications to obj.(package private) static RubyModulehash()rb_obj_id Will return the hash code of this object.include_p(ThreadContext context, IRubyObject obj) Returns true if the set contains the given object.initialize(ThreadContext context, Block block) initialize(enum = nil, &block)protected IRubyObjectinitialize(ThreadContext context, IRubyObject[] args, Block block) initialize(ThreadContext context, IRubyObject enume, Block block) initialize(enum = nil, &block)initialize_clone(ThreadContext context, IRubyObject orig) initialize_dup(ThreadContext context, IRubyObject orig) (package private) final RubySetinitSet(ThreadContext context, IRubyObject[] elements, int off, int len) private IRubyObjectinitWithEnum(ThreadContext context, IRubyObject enume, Block block) final IRubyObjectinspect()rb_obj_inspect call-seq: obj.inspect => string Returns a string containing a human-readable representation of obj.inspect(ThreadContext context) private RubyStringinspectEmpty(Ruby runtime) private static RubyStringinspectPrefix(RubyString str, RubyClass metaClass) private RubyStringinspectRecurse(Ruby runtime) private voidinspectSet(ThreadContext context, RubyString str) instance_variable_set(IRubyObject name, IRubyObject value) rb_obj_ivar_set call-seq: obj.instance_variable_set(symbol, obj) => obj Sets the instance variable names by symbol to object, thereby frustrating the efforts of the class's author to attempt to provide proper encapsulation.booleanintersect_p(ThreadContext context, IRubyObject set) Returns true if the set and the given set have at least one element in common.(package private) IRubyObjectinvokeAdd(ThreadContext context, IRubyObject val) booleanisEmpty()iterator()keep_if(ThreadContext context, Block block) length(ThreadContext context) protected final voidmodifyCheck(Ruby runtime) static RubySetConstruct a new Set.static RubySetConstruct a new Set.private static RubySetnewSet(ThreadContext context, RubyClass metaClass, RubyArray elements) (package private) RubySetnewSetFast(Ruby runtime) Construct a new Set with the same class as this one.op_and(ThreadContext context, IRubyObject enume) Returns a new set built by merging the set and the elements of the given enumerable object.op_diff(ThreadContext context, IRubyObject enume) Returns a new set built by duplicating the set, removing every element that appears in the given enumerable object.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_or(ThreadContext context, IRubyObject enume) Returns a new set built by merging the set and the elements of the given enumerable object.op_xor(ThreadContext context, IRubyObject enume) Returns a new set containing elements exclusive between the set and the given enumerable object.proper_subset_p(ThreadContext context, IRubyObject set) proper_superset_p(ThreadContext context, IRubyObject set) rb_clear(ThreadContext context) rb_merge(ThreadContext context, IRubyObject enume) Merges the elements of the given enumerable object to the set and returns self.reject_bang(ThreadContext context, Block block) booleanbooleanremoveAll(Collection coll) replace(ThreadContext context, IRubyObject enume) Replaces the contents of the set with the contents of the given enumerable object and returns self.reset(ThreadContext context) booleanretainAll(Collection coll) select_bang(ThreadContext context, Block block) (package private) final voidprivate static JavaSites.SetSitessites(ThreadContext context) intsize()private static IRubyObjectsize(ThreadContext context, RubySet recv, IRubyObject[] args) A size method suitable for lambda method reference implementation ofRubyEnumerator.SizeFn.size(ThreadContext, IRubyObject, IRubyObject[])subset_p(ThreadContext context, IRubyObject set) subtract(ThreadContext context, IRubyObject enume) Deletes every element that appears in the given enumerable object and returns self.superset_p(ThreadContext context, IRubyObject set) taint(ThreadContext context) rb_obj_taint call-seq: obj.taint -> obj Marks obj as tainted---if the$SAFElevel is set appropriately, many method calls which might alter the running programs environment will refuse to accept tainted strings.to_a(ThreadContext context) Converts the set to an array.to_set(ThreadContext context, Block block) to_set(ThreadContext context, IRubyObject[] args, Block block) Object[]toArray()Object[](package private) final IRubyObject(package private) static IRubyObject(package private) voiduntaint(ThreadContext context) rb_obj_untaint call-seq: obj.untaint => obj Removes the taint from obj.Methods inherited from class org.jruby.RubyObject
attachToObjectSpace, callInit, callInit, callInit, callInit, callInit, callInit, callInit, callInit, callInit, callInit, convertToType, createObjectClass, dig, dig1, dig2, eqlInternal, equalInternal, equals, getNativeClassIndex, hashCode, inspect, op_eqq, puts, specificEval, toRubyString, toStringMethods inherited from class org.jruby.RubyBasicObject
addFinalizer, anyToString, asJavaString, asString, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callSuper, checkArrayType, checkCallMethod, checkCallMethod, checkFrozen, checkStringType, checkStringType19, compareTo, convertToArray, convertToFloat, convertToHash, convertToInteger, convertToInteger, convertToInteger, convertToString, copyInstanceVariablesInto, copySpecialInstanceVariables, createBasicObjectClass, dataGetStruct, dataGetStructChecked, dataWrapStruct, decode, display, dup, ensureInstanceVariablesSettable, eql_p, equal_p, equal_p19, evalUnder, extend, fastGetInstanceVariable, fastGetInternalVariable, fastHasInstanceVariable, fastHasInternalVariable, fastSetInstanceVariable, fastSetInternalVariable, frozen_p, getFFIHandle, getFlag, getInstanceEvalClass, getInstanceVariable, getInstanceVariableList, getInstanceVariableNameList, getInstanceVariables, getInternalVariable, getInternalVariables, getJavaClass, getMetaClass, getMetaClass, getNativeHandle, getNativeTypeIndex, getObjectId, getRuntime, getSingletonClass, getSingletonClassClone, getSingletonClassCloneAndAttach, getType, getVariable, getVariableCount, getVariableList, getVariableNameList, hashyInspect, hasInstanceVariable, hasInstanceVariables, hasInternalVariable, hasVariables, id, infectBy, initialize, initialize_copy, initialize19, inspectHashCode, instance_eval, instance_eval, instance_eval, instance_eval, instance_eval19, instance_eval19, instance_eval19, instance_eval19, instance_exec, instance_exec19, instance_of_p, instance_variable_defined_p, instance_variable_get, instance_variables, instance_variables19, isBuiltin, isClass, isFalse, isFrozen, isImmediate, isModule, isNil, isSpecialConst, isSpecialObject, isTaint, isTrue, isUntrusted, kind_of_p, makeMetaClass, method, method_missing, method_missing19, method19, methods, methods, methods19, nil_p, nonFixnumHashCode, OBJ_INIT_COPY, objInitCopy, op_cmp, op_equal_19, op_match, op_match19, op_not, op_not_equal, op_not_match, private_methods, private_methods19, protected_methods, protected_methods19, public_methods, public_methods19, rbClone, rbClone, rbInspect, remove_instance_variable, removeFinalizers, removeInstanceVariable, removeInternalVariable, respond_to_p, respond_to_p, respond_to_p19, respond_to_p19, respondsTo, respondsToMissing, respondsToMissing, send, send, send, send, send, send19, send19, send19, send19, setFFIHandle, setFlag, setFrozen, setInstanceVariable, setInternalVariable, setMetaClass, setNativeHandle, setTaint, setUntrusted, setVariable, singleton_method, singleton_method_added, singleton_method_added19, singleton_method_removed, singleton_method_removed19, singleton_method_undefined, singleton_method_undefined19, singleton_methods, specificEval, specificEval, specificEval, specificEval, syncVariables, syncVariables, taint, tainted_p, testFrozen, testFrozen, to_a, to_s, toJava, trust, type, type_deprecated, untrust, untrusted_p, validateInstanceVariable, validateInstanceVariable, validateInstanceVariable, variableTableContains, variableTableFastContains, variableTableFastFetch, variableTableFastStore, variableTableFetch, variableTableRemove, variableTableStore, variableTableSync, yieldUnder, yieldUnderMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.Set
equals, hashCode, spliterator
-
Field Details
-
hash
RubyHash hash -
RECURSIVE_BYTES
private static final byte[] RECURSIVE_BYTES
-
-
Constructor Details
-
RubySet
-
-
Method Details
-
createSetClass
-
unmarshal
void unmarshal() -
allocHash
-
allocHash
-
setHash
-
newSetFast
Construct a new Set with the same class as this one.- Parameters:
runtime- the current runtime- Returns:
- a new Set
-
newSet
Construct a new Set. The Set class will be retrieved from the global namespace.- Parameters:
runtime- the current runtime- Returns:
- a new Set
-
newSet
Construct a new Set.- Parameters:
runtime- the current runtimemetaclass- the class to assign to the new set- Returns:
- a new Set
-
newSet
-
initSet
-
create
Creates a new set containing the given objects. -
initialize
initialize(enum = nil, &block) -
initialize
initialize(enum = nil, &block) -
initialize
-
initWithEnum
-
doWithEnum
private static IRubyObject doWithEnum(ThreadContext context, IRubyObject enume, RubySet.EachBody blockImpl) -
instance_variable_set
Description copied from class:RubyBasicObjectrb_obj_ivar_set call-seq: obj.instance_variable_set(symbol, obj) => obj Sets the instance variable names by symbol to object, thereby frustrating the efforts of the class's author to attempt to provide proper encapsulation. The variable did not have to exist prior to this call. class Fred def initialize(p1, p2)- Overrides:
instance_variable_setin classRubyBasicObject
-
invokeAdd
-
initialize_dup
-
initialize_clone
-
freeze
Description copied from class:RubyBasicObjectrb_obj_freeze call-seq: obj.freeze => obj Prevents further modifications to obj. ATypeErrorwill be raised if modification is attempted. There is no way to unfreeze a frozen object. See alsoObject#frozen?. a = [ "a", "b", "c" ] a.freeze a << "z" produces: prog.rb:3:in `<<': can't modify frozen array (TypeError) from prog.rb:3- Overrides:
freezein classRubyBasicObject
-
taint
Description copied from class:RubyBasicObjectrb_obj_taint call-seq: obj.taint -> obj Marks obj as tainted---if the$SAFElevel is set appropriately, many method calls which might alter the running programs environment will refuse to accept tainted strings.- Overrides:
taintin classRubyBasicObject
-
untaint
Description copied from class:RubyBasicObjectrb_obj_untaint call-seq: obj.untaint => obj Removes the taint from obj. Only callable in if more secure than 3.- Overrides:
untaintin classRubyBasicObject
-
length
-
empty_p
-
rb_clear
-
clearImpl
protected void clearImpl() -
replace
Replaces the contents of the set with the contents of the given enumerable object and returns self. -
to_a
Converts the set to an array. The order of elements is uncertain.- Overrides:
to_ain classRubyBasicObject
-
to_set
-
to_set
-
compare_by_identity
-
compare_by_identity_p
-
flatten_merge
-
flattenMerge
-
addFlattened
-
flatten
-
flatten_bang
-
include_p
Returns true if the set contains the given object. -
containsImpl
-
allElementsIncluded
-
superset_p
-
proper_superset_p
-
subset_p
-
proper_subset_p
-
intersect_p
Returns true if the set and the given set have at least one element in common. -
intersect
-
disjoint_p
Returns true if the set and the given set have no element in common. This method is the opposite of +intersect?+. -
each
-
size
A size method suitable for lambda method reference implementation ofRubyEnumerator.SizeFn.size(ThreadContext, IRubyObject, IRubyObject[]) -
add
Adds the given object to the set and returns self. -
addImpl
-
addImplSet
-
add_p
Adds the given object to the set and returns self. If the object is already in the set, returns nil. -
delete
-
deleteImpl
-
deleteImplIterator
-
delete_p
Deletes the given object from the set and returns self. If the object is not in the set, returns nil. -
delete_if
-
keep_if
-
collect_bang
-
reject_bang
-
select_bang
-
rb_merge
Merges the elements of the given enumerable object to the set and returns self. -
subtract
Deletes every element that appears in the given enumerable object and returns self. -
op_or
Returns a new set built by merging the set and the elements of the given enumerable object. -
op_diff
Returns a new set built by duplicating the set, removing every element that appears in the given enumerable object. -
op_and
Returns a new set built by merging the set and the elements of the given enumerable object. -
op_xor
Returns a new set containing elements exclusive between the set and the given enumerable object. `(set ^ enum)` is equivalent to `((set | enum) - (set & enum))`. -
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
-
reset
-
op_eql
-
eql
Description copied from class:RubyBasicObjectmethod used for Hash key comparison (specialized for String, Symbol and Fixnum) Will by default just call the Ruby method "eql?"- Specified by:
eqlin interfaceIRubyObject- Overrides:
eqlin classRubyBasicObject
-
hash
Description copied from class:RubyBasicObjectrb_obj_id Will 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
-
classify
-
divide
Divides the set into a set of subsets according to the commonality defined by the given block. If the arity of the block is 2, elements o1 and o2 are in common if block.call(o1, o2) is true. Otherwise, elements o1 and o2 are in common if block.call(o1) == block.call(o2). e.g.: require 'set' numbers = Set[1, 3, 4, 6, 9, 10, 11] set = numbers.divide { |i,j| (i - j).abs == 1 } p set # => #<Set: {#<Set: {1}>, # #<Set: {11, 9, 10}>, # #<Set: {3, 4}>, # #<Set: {6}>}> -
divideTSort
-
getTSort
-
inspect
Description copied from class:RubyBasicObjectrb_obj_inspect call-seq: obj.inspect => string Returns 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- Returns:
- String
-
inspect
-
inspectEmpty
-
inspectRecurse
-
inspectPrefix
-
inspectSet
-
elements
-
elementsOrdered
-
modifyCheck
-
size
public int size()- Specified by:
sizein interfaceCollection- Specified by:
sizein interfaceSet
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection- Specified by:
isEmptyin interfaceSet
-
clear
public void clear()- Specified by:
clearin interfaceCollection- Specified by:
clearin interfaceSet
-
contains
- Specified by:
containsin interfaceCollection- Specified by:
containsin interfaceSet
-
rawIterator
-
iterator
-
toArray
- Specified by:
toArrayin interfaceCollection- Specified by:
toArrayin interfaceSet
-
toArray
- Specified by:
toArrayin interfaceCollection- Specified by:
toArrayin interfaceSet
-
add
- Specified by:
addin interfaceCollection- Specified by:
addin interfaceSet
-
remove
- Specified by:
removein interfaceCollection- Specified by:
removein interfaceSet
-
containsAll
- Specified by:
containsAllin interfaceCollection- Specified by:
containsAllin interfaceSet
-
addAll
- Specified by:
addAllin interfaceCollection- Specified by:
addAllin interfaceSet
-
retainAll
- Specified by:
retainAllin interfaceCollection- Specified by:
retainAllin interfaceSet
-
removeAll
- Specified by:
removeAllin interfaceCollection- Specified by:
removeAllin interfaceSet
-
toRuby
-
toRuby
-
sites
-