Class: Array

Overview

::TODO

add document

Instance Method Summary collapse

Methods included from SetFuMixinBinaryProperOperator

#<

Methods included from SetFuMixinBinarySubsetOperator

#<=

Methods included from SetFuMixinTrippleEqualsOperator

#===, #old_triple_equal4Set

Methods included from SetFuMixinToSetMethod

#to_bset

Methods included from SetFuMixinBinaryIntersectionOperator

#**

Instance Method Details

#&(item) ⇒ Object



1202
1203
1204
1205
1206
1207
# File 'lib/setfu.rb', line 1202

def &(item)
  return old_and_method4set(item) if (item.type_of? Array)
  a = BitSet.new(self)
  b = BitSet.new(item)
  return a & b 
end

#-(item) ⇒ Object



1196
1197
1198
1199
1200
1201
# File 'lib/setfu.rb', line 1196

def -(item)
  return old_subtract_method4set(item) if (item.type_of? Array)
  a = BitSet.new(self)
  b = BitSet.new(item)
  return a - b 
end

#^(item) ⇒ Object



1186
1187
1188
1189
1190
1191
1192
1193
1194
# File 'lib/setfu.rb', line 1186

def ^(item)
  if item.type_of? Array
    return (self | item) - (self & item)
  else
    a = BitSet.new(self)
    b = BitSet.new(item)
    return a ^ b
  end
end

#ascending?Boolean

additions to be used by other future gems:

Returns:

  • (Boolean)


50
51
52
53
54
55
56
57
58
# File 'lib/setfu.rb', line 50

def ascending?
  return false unless count >=2
  cnt = self.length - 1
  cnt.times do |ii|
    return false unless self[ii+1] >= self[ii]
  end
  return false if first==last  # ascending means something has to get bigger
  true
end

#descending?Boolean

Returns:

  • (Boolean)


59
60
61
62
63
64
65
66
67
# File 'lib/setfu.rb', line 59

def descending?
  return false unless count >=2
  cnt = self.length - 1
  cnt.times do |ii|
    return false unless self[ii+1] <= self[ii]
  end
  return false if first==last  # descending means something has to get smaller
  true
end

#members_to_bsetObject



375
376
377
378
# File 'lib/setfu.rb', line 375

def members_to_bset
  Setfu::bset_elements(self)
  self
end

#old_and_method4setObject



1176
# File 'lib/setfu.rb', line 1176

alias_method :old_and_method4set, :&

#old_or_method4setObject



1177
# File 'lib/setfu.rb', line 1177

alias_method :old_or_method4set, :|

#old_subtract_method4setObject



1175
# File 'lib/setfu.rb', line 1175

alias_method :old_subtract_method4set, :-

#peek(n = 0) ⇒ Object



43
44
45
# File 'lib/setfu.rb', line 43

def peek(n=0)
  return self[count-n-1]
end

#pop2Object



38
39
40
41
42
# File 'lib/setfu.rb', line 38

def pop2
  a = pop
  b = pop
  return [a,b]
end

#reduce_tuples(passes = 1) ⇒ Object



390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
# File 'lib/setfu.rb', line 390

def reduce_tuples(passes = 1)
  Setfu::bset_elements(self)
  Setfu::untag_bset_elements(self)
  total_count = 0
  loop do
    tc = Setfu::reduce(self)
    if tc < 0
      total_count = -1
      break
    end
    break if tc == 0
    total_count += tc
    passes -= 1
    break if passes <= 0
  end
  total_count
end

#sorted?Boolean

Returns:

  • (Boolean)


68
69
70
71
72
73
74
# File 'lib/setfu.rb', line 68

def sorted?
  return false unless count >=1
  return true if (self & self).count == 1  # [4,4,4,4] is sorted, but not ascending or desending
  return true if ascending?
  return true if descending?
  false
end

#stack_rotObject



30
31
32
33
34
35
36
37
# File 'lib/setfu.rb', line 30

def stack_rot
  a = pop
  b = pop
  c = pop
  push a
  push c
  push b
end

#stack_swapObject



24
25
26
27
28
29
# File 'lib/setfu.rb', line 24

def stack_swap
  a = pop
  b = pop
  push a
  push b
end

#tupleObject



387
388
389
# File 'lib/setfu.rb', line 387

def tuple
  Setfu::tuple(self)
end

#tuple?Boolean

Returns:

  • (Boolean)


384
385
386
# File 'lib/setfu.rb', line 384

def tuple?
  Setfu::tuple?(self)
end

#tuplesObject



379
380
381
382
383
# File 'lib/setfu.rb', line 379

def tuples
  members_to_bset
  rtn = Setfu::tuples(self)
  rtn
end

#untag_bset_elementsObject



407
408
409
# File 'lib/setfu.rb', line 407

def untag_bset_elements
  Setfu::untag_bset_elements(self)
end

#|(item) ⇒ Object



1208
1209
1210
1211
1212
1213
# File 'lib/setfu.rb', line 1208

def |(item)
  return old_or_method4set(item) if (item.type_of? Array)
  a = BitSet.new(self)
  b = BitSet.new(item)
  return a | b 
end