class Set
class Set
lib/collections/set.tya:2
Set provides the collections/Set standard library API.
Source
# Set provides the collections/Set standard library API.
class Set
# Set.items stores instance state.
# @type Array
items: []
# Set.initialize provides the collections/Set standard library operation.
# @param values Array values value.
# @return Self the initialized object.
initialize: values = nil ->
self.items = []
if values != nil
i = 0
while i < values.len()
found = false
j = 0
while j < self.items.len()
if self.items[j] == values[i]
found = true
j = j + 1
if not found
self.items.push(values[i])
i = i + 1
# Set.add provides the collections/Set standard library operation.
# @param value String value value.
# @return Any the resulting value.
add: value ->
if not self.has?(value)
self.items.push(value)
self
# Set.clear provides the collections/Set standard library operation.
# @return Nil the resulting value.
clear: ->
self.items = []
self
# Set.delete provides the collections/Set standard library operation.
# @param value String value value.
# @return Any the resulting value.
delete: value ->
next = []
removed = false
i = 0
while i < self.items.len()
if not removed and self.items[i] == value
removed = true
else
next.push(self.items[i])
i = i + 1
self.items = next
removed
# Set.difference provides the collections/Set standard library operation.
# @param other Any other value.
# @return Any the resulting value.
difference: other ->
out = Set(nil)
values = self.to_array()
i = 0
while i < values.len()
if not other.has?(values[i])
out.add(values[i])
i = i + 1
out
# Set.empty? provides the collections/Set standard library operation.
# @return Boolean whether the condition is true.
empty?: ->
self.items.empty?()
# Set.from_array provides the collections/Set standard library operation.
# @param values Array values value.
# @return Array the resulting value.
from_array: values ->
Set(values)
# Set.has? provides the collections/Set standard library operation.
# @param value String value value.
# @return Boolean whether the condition is true.
has?: value ->
i = 0
while i < self.items.len()
if self.items[i] == value
return true
i = i + 1
false
# Set.intersection provides the collections/Set standard library operation.
# @param other Any other value.
# @return Any the resulting value.
intersection: other ->
out = Set(nil)
values = self.to_array()
i = 0
while i < values.len()
if other.has?(values[i])
out.add(values[i])
i = i + 1
out
# Set.len provides the collections/Set standard library operation.
# @return Int the resulting value.
len: ->
self.items.len()
# Set.new provides the collections/Set standard library operation.
# @return Self the resulting value.
new: ->
Set(nil)
# Set.subset? provides the collections/Set standard library operation.
# @param other Any other value.
# @return Boolean whether the condition is true.
subset?: other ->
values = self.to_array()
i = 0
while i < values.len()
if not other.has?(values[i])
return false
i = i + 1
true
# Set.to_array provides the collections/Set standard library operation.
# @return Array the resulting value.
to_array: ->
self.items.slice(0, self.items.len())
# Set.union provides the collections/Set standard library operation.
# @param other Any other value.
# @return Any the resulting value.
union: other ->
out = Set(self.to_array())
i = 0
values = other.to_array()
while i < values.len()
out.add(values[i])
i = i + 1
out
Instance Variables
items
Set.items
lib/collections/set.tya:5
Set.items stores instance state.
Source
# Set.items stores instance state.
# @type Array
items: []
Methods
add
Set.add(value)
lib/collections/set.tya:28
Set.add provides the collections/Set standard library operation.
Source
# Set.add provides the collections/Set standard library operation.
# @param value String value value.
# @return Any the resulting value.
add: value ->
if not self.has?(value)
self.items.push(value)
self
clear
Set.clear()
lib/collections/set.tya:35
Set.clear provides the collections/Set standard library operation.
Source
# Set.clear provides the collections/Set standard library operation.
# @return Nil the resulting value.
clear: ->
self.items = []
self
delete
Set.delete(value)
lib/collections/set.tya:42
Set.delete provides the collections/Set standard library operation.
Source
# Set.delete provides the collections/Set standard library operation.
# @param value String value value.
# @return Any the resulting value.
delete: value ->
next = []
removed = false
i = 0
while i < self.items.len()
if not removed and self.items[i] == value
removed = true
else
next.push(self.items[i])
i = i + 1
self.items = next
removed
difference
Set.difference(other)
lib/collections/set.tya:58
Set.difference provides the collections/Set standard library operation.
Source
# Set.difference provides the collections/Set standard library operation.
# @param other Any other value.
# @return Any the resulting value.
difference: other ->
out = Set(nil)
values = self.to_array()
i = 0
while i < values.len()
if not other.has?(values[i])
out.add(values[i])
i = i + 1
out
empty?
Set.empty?()
lib/collections/set.tya:70
Set.empty? provides the collections/Set standard library operation.
Source
# Set.empty? provides the collections/Set standard library operation.
# @return Boolean whether the condition is true.
empty?: ->
self.items.empty?()
from_array
Set.from_array(values)
lib/collections/set.tya:76
Set.from_array provides the collections/Set standard library operation.
Source
# Set.from_array provides the collections/Set standard library operation.
# @param values Array values value.
# @return Array the resulting value.
from_array: values ->
Set(values)
has?
Set.has?(value)
lib/collections/set.tya:82
Set.has? provides the collections/Set standard library operation.
Source
# Set.has? provides the collections/Set standard library operation.
# @param value String value value.
# @return Boolean whether the condition is true.
has?: value ->
i = 0
while i < self.items.len()
if self.items[i] == value
return true
i = i + 1
false
initialize
Set.initialize(values = nil)
lib/collections/set.tya:10
Set.initialize provides the collections/Set standard library operation.
Source
# Set.initialize provides the collections/Set standard library operation.
# @param values Array values value.
# @return Self the initialized object.
initialize: values = nil ->
self.items = []
if values != nil
i = 0
while i < values.len()
found = false
j = 0
while j < self.items.len()
if self.items[j] == values[i]
found = true
j = j + 1
if not found
self.items.push(values[i])
i = i + 1
intersection
Set.intersection(other)
lib/collections/set.tya:93
Set.intersection provides the collections/Set standard library operation.
Source
# Set.intersection provides the collections/Set standard library operation.
# @param other Any other value.
# @return Any the resulting value.
intersection: other ->
out = Set(nil)
values = self.to_array()
i = 0
while i < values.len()
if other.has?(values[i])
out.add(values[i])
i = i + 1
out
len
Set.len()
lib/collections/set.tya:105
Set.len provides the collections/Set standard library operation.
Source
# Set.len provides the collections/Set standard library operation.
# @return Int the resulting value.
len: ->
self.items.len()
new
Set.new()
lib/collections/set.tya:110
Set.new provides the collections/Set standard library operation.
Source
# Set.new provides the collections/Set standard library operation.
# @return Self the resulting value.
new: ->
Set(nil)
subset?
Set.subset?(other)
lib/collections/set.tya:116
Set.subset? provides the collections/Set standard library operation.
Source
# Set.subset? provides the collections/Set standard library operation.
# @param other Any other value.
# @return Boolean whether the condition is true.
subset?: other ->
values = self.to_array()
i = 0
while i < values.len()
if not other.has?(values[i])
return false
i = i + 1
true
to_array
Set.to_array()
lib/collections/set.tya:127
Set.to_array provides the collections/Set standard library operation.
Source
# Set.to_array provides the collections/Set standard library operation.
# @return Array the resulting value.
to_array: ->
self.items.slice(0, self.items.len())
union
Set.union(other)
lib/collections/set.tya:133
Set.union provides the collections/Set standard library operation.
Source
# Set.union provides the collections/Set standard library operation.
# @param other Any other value.
# @return Any the resulting value.
union: other ->
out = Set(self.to_array())
i = 0
values = other.to_array()
while i < values.len()
out.add(values[i])
i = i + 1
out