Module: Yast::Builtins::Multiset Deprecated

Defined in:
src/ruby/yast/builtins.rb

Overview

Deprecated.

use ruby type Set instead or difference library for set handling

builtins enclosed in Multiset namespace

Class Method Summary collapse

Class Method Details

.difference(set1, set2) ⇒ Object

See Also:



1114
1115
1116
# File 'src/ruby/yast/builtins.rb', line 1114

def self.difference(set1, set2)
  Yast.deep_copy(set1.to_set - set2.to_set).to_a
end

.includes(set1, set2) ⇒ Object

See Also:



1103
1104
1105
1106
1107
1108
1109
1110
1111
# File 'src/ruby/yast/builtins.rb', line 1103

def self.includes(set1, set2)
  # cannot use to_set because there is difference if there is element multipletime
  repetition = {}
  set2.all? do |e|
    repetition[e] ||= 0
    repetition[e] += 1
    set1.count(e) >= repetition[e]
  end
end

.intersection(set1, set2) ⇒ Object

See Also:



1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
# File 'src/ruby/yast/builtins.rb', line 1148

def self.intersection(set1, set2)
  ss1 = set1.sort
  ss2 = set2.sort
  res = []
  until ss1.empty? || ss2.empty?
    i1 = ss1.last
    i2 = ss2.last
    case i1 <=> i2
    when -1
      ss2.pop
    when 1
      ss1.pop
    when 0
      res << i1
      ss1.pop
      ss2.pop
    else
      raise "unknown value from comparison #{i1 <=> u2}"
    end
  end
  Yast.deep_copy(res.reverse)
end

.merge(set1, set2) ⇒ Object

See Also:



1202
1203
1204
# File 'src/ruby/yast/builtins.rb', line 1202

def self.merge(set1, set2)
  Yast.deep_copy(set1 + set2)
end

.symmetric_difference(set1, set2) ⇒ Object

See Also:



1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
# File 'src/ruby/yast/builtins.rb', line 1119

def self.symmetric_difference(set1, set2)
  ss1 = set1.sort
  ss2 = set2.sort
  res = []
  until ss1.empty? || ss2.empty?
    i1 = ss1.last
    i2 = ss2.last
    case i1 <=> i2
    when -1
      res << i2
      ss2.pop
    when 1
      res << i1
      ss1.pop
    when 0
      ss1.pop
      ss2.pop
    else
      raise "unknown value from comparison #{i1 <=> u2}"
    end
  end

  res += ss1.reverse unless ss1.empty?
  res += ss2.reverse unless ss2.empty?

  Yast.deep_copy(res.reverse)
end

.union(set1, set2) ⇒ Object

See Also:



1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
# File 'src/ruby/yast/builtins.rb', line 1172

def self.union(set1, set2)
  ss1 = set1.sort
  ss2 = set2.sort
  res = []
  until ss1.empty? || ss2.empty?
    i1 = ss1.last
    i2 = ss2.last
    case i1 <=> i2
    when -1
      res << i2
      ss2.pop
    when 1
      res << i1
      ss1.pop
    when 0
      res << i1
      ss1.pop
      ss2.pop
    else
      raise "unknown value from comparison #{i1 <=> u2}"
    end
  end

  res += ss1.reverse unless ss1.empty?
  res += ss2.reverse unless ss2.empty?

  Yast.deep_copy(res.reverse)
end