Class: Farce::Local::Vector

Inherits:
Abstract::Vector show all
Includes:
Shareable::Tracked
Defined in:
lib/farce/local/vector.rb

Overview

A shareable vector with independent mutable storage in each scope.

Instance Attribute Summary

Attributes included from Scoped

#scope

Instance Method Summary collapse

Methods included from Shareable

#ractor_shareable?

Methods inherited from Abstract::Vector

#&, #*, #+, #-, #<<, #<=>, #[], #[]=, #append, #as_extended_json, #as_json, #assoc, #at, #bsearch, #bsearch_index, #bson_type, #chunk, #chunk_while, #clear, #combination, #compact, #compact!, #compact_blank, #compare_and_set, #compare_by_identity?, #concat, #deconstruct, #deep_dup, #delete, #delete_at, #delete_if, #difference, #dig, #drop, #drop_while, #each, #each_cons, #each_index, #each_slice, #entries, #excluding, #fetch, #fetch_values, #fifth, #fill, #filter_map, #first, #flat_map, #flatten, #flatten!, #forty_two, #fourth, #from, #get, #grep, #grep_v, #group_by, #in_groups, #in_groups_of, #in_order_of, #include?, #including, #index, #inquiry, #insert, #intersect?, #intersection, #keep_if, #last, #map, #map!, #max, #max_by, #maximum, #min, #min_by, #minimum, #minmax, #minmax_by, #pack, #partition, #permutation, #pick, #pluck, #pop, #product, #push, #rassoc, #reject, #reject!, #repeated_combination, #repeated_permutation, #replace, #reverse, #reverse!, #reverse_each, #rfind, #rindex, #rotate, #rotate!, #sample, #second, #second_to_last, #select, #select!, #shareable_values?, #shift, #shuffle, #shuffle!, #size, #slice, #slice!, #slice_after, #slice_before, #slice_when, #sort, #sort!, #sort_by, #sort_by!, #split, #store, #store_if_absent, #swap, #take, #take_while, #third, #third_to_last, #to, #to_a, #to_ary, #to_bson, #to_bson_normalized_value, #to_cbor, #to_fs, #to_h, #to_json, #to_msgpack, #to_param, #to_query, #to_sentence, #to_xml, #transpose, #union, #uniq, #uniq!, #unshift, #update, #upsert, #values_at, #wait_until, #wait_until_changed, #wait_until_match, #wait_until_non_nil, #wait_until_value, #wait_while, #wait_while_match, #wait_while_value, #zip, #|

Methods inherited from Abstract::Collection

#<<, [], #clear, #compare_by_identity?, #count, #each, #empty?, #filter, #include?, #join, #length, #member?, #reject, #select, #size, #to_a, #to_s

Methods included from Internal::Copyable

#duplicable?

Constructor Details

#initialize(source = nil, compare_by_identity: false, scope: :ractor) ⇒ Vector

Valid scopes are:

  • :ractor - The value is shared by all threads within the same Ractor.
  • :thread_group - The value is shared by all threads within the same thread group.
  • :thread - The value is shared by all fibers within the same thread.
  • :fiber_storage - The value is shared by all fibers using the same storage. Unless explicitly specified, storage is inherited from the parent fiber for blocking fibers, but not for non-blocking fibers (such as those created by Scheduler#schedule).
  • :fiber - Each fiber has its own independent value.

Parameters:

  • source (Array, Integer, nil) (defaults to: nil) —

    Initial values or a size filled with nil.

  • compare_by_identity (Boolean) (defaults to: false) —

    whether values are compared by identity

  • scope (Symbol) (defaults to: :ractor) —

    the scope of the vector

Raises:

  • (ArgumentError) —

    If the size is negative.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/farce/local/vector.rb', line 16

class Vector < Abstract::Vector
  include Shareable::Tracked
  include Scoped::Tracked

  protected

  def internal_vector = scoped_value

  def build_derived_vector(values)
    self.class.new(values, compare_by_identity: compare_by_identity?, scope:)
  end

  private def new_scoped_value(source = nil, **) = Internal::UnsharedVector.new(normalize_vector_source(source), **)
end