Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/sorted_containers/core_extensions.rb

Overview

Array class is being extended to include methods for converting an Array to a SortedSet, SortedHash, and SortedArray.

Instance Method Summary collapse

Instance Method Details

#to_sorted_a(load_factor: SortedContainers::SortedArray::DEFAULT_LOAD_FACTOR) ⇒ SortedContainers::SortedArray

Converts the array to a SortedArray.

Parameters:

  • load_factor (Integer) (defaults to: SortedContainers::SortedArray::DEFAULT_LOAD_FACTOR)

    The load factor for the SortedArray.

Returns:



27
28
29
# File 'lib/sorted_containers/core_extensions.rb', line 27

def to_sorted_a(load_factor: SortedContainers::SortedArray::DEFAULT_LOAD_FACTOR)
  SortedContainers::SortedArray.new(self, load_factor: load_factor)
end

#to_sorted_h(load_factor: SortedContainers::SortedArray::DEFAULT_LOAD_FACTOR) ⇒ SortedContainers::SortedHash

Converts the array to a SortedHash.

Parameters:

  • load_factor (Integer) (defaults to: SortedContainers::SortedArray::DEFAULT_LOAD_FACTOR)

    The load factor for the SortedHash.

Returns:



18
19
20
21
# File 'lib/sorted_containers/core_extensions.rb', line 18

def to_sorted_h(load_factor: SortedContainers::SortedArray::DEFAULT_LOAD_FACTOR)
  hash = SortedContainers::SortedHash.new(load_factor: load_factor)
  hash.merge!(self)
end

#to_sorted_set(load_factor: SortedContainers::SortedArray::DEFAULT_LOAD_FACTOR) ⇒ SortedContainers::SortedSet

Converts the array to a SortedSet.

Parameters:

  • load_factor (Integer) (defaults to: SortedContainers::SortedArray::DEFAULT_LOAD_FACTOR)

    The load factor for the SortedSet.

Returns:



10
11
12
# File 'lib/sorted_containers/core_extensions.rb', line 10

def to_sorted_set(load_factor: SortedContainers::SortedArray::DEFAULT_LOAD_FACTOR)
  SortedContainers::SortedSet.new(self, load_factor: load_factor)
end