setfu 2.1.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 371320640c75eaaa4682a0c1e0d4ca0255353636
4
- data.tar.gz: 440754a957cd4df9e83960b93b10c041b00d8ab7
3
+ metadata.gz: 52a5ee49e433abe5779edcd424ced5261ef25303
4
+ data.tar.gz: e0e811d20322da32ee9d0fcf69d9ed81e440558a
5
5
  SHA512:
6
- metadata.gz: 9a3fb347e019df2158eea8727ba768c58659335dc2a295fd00b36c3dce4bfbf1e36ac7d81b0719b63ccd581522e082deb0c6f967770985fa3191c34e2f187e4d
7
- data.tar.gz: 591c8c369e1eb6abe642837b5f3af8aeda669a0a5d01200393dde21cd7d687e30b2204dbb4fa2438e15ef40abec6f53f87ae1a36f398fb8d8cf023d1fc58191f
6
+ metadata.gz: 8ff1c1665c1761bcf7c8a30a4c631a4a1416d475487966f24d7037c81af0cc8fcf11cb41b722cd28873d7baaaef4a2cf8c137a2f4ee4f4b63def78f802aefa82
7
+ data.tar.gz: 99e06bd8f3cf88c6440ceea3f36cc77cbd4c4bf374c4faedeb5fef8d6be7b4d610053e35d34efac8aba3ba16d80a84e407b014891792d8f4dddc6f34029e4845
data/README.md CHANGED
@@ -1,10 +1,610 @@
1
1
  # Setfu
2
2
 
3
- ##Purpose: A general purpose object implementing sets.
3
+ ##Purpose: Creates a BitSet class with methods that allow you to construct and opperate on
4
+ set instances. A 'Bignum' instance is used internally to store each element
5
+ of the set. This allows very fast operations when comparing two set instances.
6
+ Member elements can be represented as positive small integers, or characters.
7
+ Sets can be constructed with integers, strings, characters, ranges, and arrays.
8
+ When characters are used, the ordinate value represents the element bit of the internal Bignum.
9
+
10
+ Additional extensions are made to: String, Array, and Range;
11
+ these extensions implement most of the basic set operators such as intersection and union.
12
+ The bits of an internal Bignum instance is used to store the members of the set of non-negative integers.
13
+ Rather than using a long-winded series of comparison operators,
14
+ a set can operate very efficiently in a single step.
15
+ Note that only non-negative integers are possible members of a BitSet instance.
16
+ This differs from the Set object defined by rails which is more or less an unordered Array of any object.
17
+ The BitSet object implements a purer mathematical classical set, and permits faster operations on its members.
18
+ With members constrained to non-negative integers, many more constructs and operations are possible.
4
19
 
5
20
  ##Documentation
6
- See: http://bdlsys.com/gems/setfu.html
7
21
 
22
+ ###Construction
23
+
24
+ There are many ways to create a BitSet instance. Anything that can be converted to a list of positive Integers
25
+ can be used in the `#new` method. Also, many types can call `#to_bset` as an alternate means to creating a BitSet instance.
26
+ Additionally, there are several binary operators which were previously undefined for certain types that will now return a BitSet instance.
27
+ BitSet class methods have additional generators as well. This is best seen by example as follows:
28
+
29
+ ```ruby
30
+ require "setfu"
31
+
32
+ # create empty set
33
+ bs = BitSet.new
34
+ bs.empty? # true
35
+ bs.to_a # []
36
+
37
+ # initialize using a list of positive integers
38
+ aaa = BitSet.new 15,27,92,103
39
+ aaa.to_a # [15, 27, 92, 103]
40
+
41
+ # initialize using strings
42
+ aaa = BitSet.new "Each ord of this string is a set member!"
43
+ aaa.to_ra(false) # [" ", "!", "E", "a".."i", "m".."o", "r".."t"]
44
+
45
+ # initialize using ranges
46
+ aaa = BitSet.new 0..15, 'a'..'z'
47
+ aaa.to_ra(true) # [0..15, 97..122]
48
+
49
+ # initialize using arrays
50
+ aaa = BitSet.new [1,2,3],4,5,6,[[[7,8,9]]], "#"
51
+ aaa.to_ra # [1..9, 35]
52
+
53
+ # converting strings to BitSet instances
54
+ aaa = "This string will become a new set with the #to_bset method".to_bset
55
+ aaa.to_ra(false) # [" ", "#", "T", "_", "a".."e", "g".."i", "l".."o", "r".."t", "w"]
56
+
57
+ # converting ranges to BitSet instances
58
+ aaa = (400...425).to_bset
59
+ aaa.to_ra # [400..424]
60
+
61
+ # converting arrays to BitSet instances
62
+ aaa = [5,6,7,8,55..60, "~"].to_bset
63
+ aaa.to_ra # [5..8, 55..60, 126]
64
+ ```
65
+
66
+ ###Operators
67
+
68
+ BitSet instances support the classical set operators of union, exclusive union, and intersection
69
+ There are also membership tests for subset and proper set as well as set intersection.
70
+ Several standard data types do not define some of these operators and are instead defined by BitSet.
71
+ Array types do define union and intersection but not exclusive union;
72
+ as there is utility in having an Array exclusive union; `setfu` defines this as an Array method.
73
+ When an Array performs an exclusive union with some other type, a BitSet type is created.
74
+ This is best seen by example as follows:
75
+
76
+ ```ruby
77
+ require "setfu"
78
+
79
+ # exclusive union ^
80
+ aaa = ('a'..'z') ^ "Cat in the hat"
81
+ aaa.to_ra(false) # [" ", "C", "b".."d", "f", "g", "j".."m", "o".."s", "u".."z"]
82
+ bbb = [1,3,5] ^ [3,6,9] # returns Array type [1, 5, 6, 9]
83
+ bbb = [1,3,5] ^ [3,6,9].to_bset # BitSet type ... bbb.to_a == [1, 5, 6, 9]
84
+
85
+ # union |
86
+ aaa = [1,3,5] | [3,6,9] # returns Array type == [1, 3, 5, 6, 9]
87
+ aaa = [1,3,5] | [3,6,9].to_bset # returns BitSet type == [1, 3, 5, 6, 9]
88
+ aaa = "abcd" | "defg" # aaa.to_s == "abcdefg"
89
+
90
+ # intersection &
91
+ aaa = [1,2,3,5] & [2,3,4,5,6] # returns Array type == [2,3,5]
92
+ aaa = [1,2,3,5].to_bset & [2,3,4,5,6] # returns BitSet type == [2,3,5]
93
+ aaa = "abcdefgh" & "defghijkl" # aaa.to_s == "defgh"
94
+
95
+ # set difference -
96
+ aaa = [1,2,3,4,5,6,7,8,9] - [2,4,6,8] # Array type == [1,3,5,7,9]
97
+ aaa = (1..9) - [2,4,6,8] # BitSet type == [1,3,5,7,9]
98
+
99
+ # set inversion ~
100
+ # note: we must define the bounds of the set before we invert it.
101
+ aaa = BitSet.new "a".."z", "A".."Z", "0".."9"
102
+ aaa.entropy = 256 # ASCII-8BIT range of 256 possible elements
103
+ bbb = ~aaa
104
+ bbb.to_ra # [0..47, 58..64, 91..96, 123..255]
105
+
106
+ # subset <= ... a <= b ... true if `a` is a subset of `b`
107
+ aaa = [3,4,5,6,7]
108
+ [3] <= aaa # true
109
+ [3,6,7] <= aaa # true
110
+ [1,5,6] <= aaa # false
111
+
112
+ # proper subset < ... a < b ... true if `a` is a subset of `b` and `a` != `b`
113
+ aaa = [3,4,5,6,7]
114
+ [3] < aaa # true
115
+ [3,6,7] < aaa # true
116
+ aaa < aaa # false
117
+
118
+ # intersection test ** ... a ** b ... true if intersection is not empty
119
+ [1,2,3,4,5] ** [4,8] # true
120
+ "team" ** "i" # false ... there is no "i" in team!
121
+
122
+ # equality and inequality == !=
123
+ (4..7).to_bset == [4,5,6,7] # true ... Note: left-most must be BitSet type
124
+ (4..7).to_bset != [4,5,6,7] # false
125
+ ```
126
+
127
+ ###Member Access
128
+
129
+ BitSet defines array access operators `:[]` and `:[]=` as it it were an array of bits.
130
+ If you pass an Integer type, you will get `true` (if member of set) or `false`.
131
+ Anything else will return a BitSet instance. You can also set or clear members of the set as well.
132
+ See the example below:
133
+
134
+ ```ruby
135
+ require "setfu"
136
+
137
+ aaa = BitSet.new 0..9
138
+ aaa[4] # true
139
+ aaa[4] = false
140
+ aaa.to_ra # [0..3, 5..9]
141
+ aaa[2..8] # BitSet ... [2, 3, 5..8]
142
+ aaa[15..20] = true # BitSet ... [0..3, 5..9, 15..20]
143
+ aaa[1,2,3,4,5,6,7] # BitSet ... [1..3, 5..7]
144
+ aaa[3..17] = false # BitSet ... [0..2, 18..20]
145
+ ```
146
+
147
+ ###Instance Methods
148
+
149
+ #### bitset.count
150
+ This returns number of elements in the BitSet instance.
151
+ This method is computationally slow as each and every bit of the internal `Bignum` must be checked.
152
+ See below:
153
+ ```ruby
154
+ primes = [2,3,5,7,11,13,17,19,23,29,31,37,41].to_bset
155
+ primes.count # 13
156
+ ```
157
+
158
+ #### bitset.each, bitset.each_member, bitset.reverse_each
159
+
160
+ These methods when called with a block will yield each member of the set as index number values.
161
+ These can also be called without a block returning an Enumerator object.
162
+ The `#each_member` method is identical to `#each` which yields lower index numbers first.
163
+
164
+ #### bitset.add(item), bitset.add!(item)
165
+
166
+ The `#add(item)` method creates a new instance whose members comprise self and the union of the item in the parameter list.
167
+ This is equivalent to `bitset_instance | [item]`. The bang version `#add!(item)` self-modifies.
168
+ The parameter `item` can be any of the following: Integer, Range, BitSet, or Array.
169
+ Arrays can include all of the former items any level deep.
170
+ Note that this method is called by the main constructor which passes an array to this method.
171
+ Recursion is used to unravel the Array.
172
+
173
+ #### bitset.remove(item), bitset.remove!(item)
174
+
175
+ These methods remove elements from the BitSet instance if they exist.
176
+
177
+ #### bitset.include?(item)
178
+
179
+ Returns true if p is a subset. Parameter `p` can be:
180
+ BitSet, Range, String, Array, or Integer.
181
+
182
+ #### bitset.empty?
183
+
184
+ Returns true if there are no elements in the BitSet instance.
185
+
186
+ #### bitset.zap!
187
+
188
+ This removes all elements from the BitSet instance making it empty. Self-modifies.
189
+
190
+ #### bitset.dup
191
+
192
+ This create and returns a duplicate copy of the BitSet instance.
193
+
194
+ #### bitset.replace(item)
195
+
196
+ This replaces the inner content of the current BitSet instance from the item passed to this method.
197
+ The item will first be converted to a BitSet instance, then its internal contents will transfer.
198
+
199
+ #### bitset.to_i
200
+
201
+ This returns the internal Integer representing the set.
202
+
203
+ #### bitset.to_s
204
+
205
+ This returns a string representing the elements of the set. This routine is computationally slow as each bit must be examined.
206
+
207
+ #### bitset.to_a(int=true)
208
+
209
+ This returns an array of every element in the set in the form of integers. If the parameter int is set to false,
210
+ the array is filled with character representations of the number whose ordinal value is that of the integer.
211
+ This routine is computationally slow as each bit must be examined.
212
+
213
+ #### bitset.to_ra(int=true, th=3)
214
+
215
+ This returns as array filled with either integers or ranges of integers. The threshold parameter decides the minimum range size
216
+ that will be used. The minimum value is 2. The `int` parameter when set to false will return string characters and string ranges.
217
+ This routine is computationally slow as each bit must be examined.
218
+
219
+ #### bitset.set_bits!(n)
220
+ This is the inverse of `#to_i` where the internal Integer gets replaced. Note that you should recalculate the entropy
221
+ as this defines the bounds of the set. This is only necessary if you need to invert the set elements later on.
222
+
223
+ #### bitset.recalculate_entropy!
224
+ This routine should be called after a `#set_bits!` where you do not know what the entropy value should be.
225
+
226
+ #### bitset.entropy, bitset.entropy=(n)
227
+ This returns the current entropy number of the set. You can also set this property. Note that this number can only get bigger;
228
+ like the universe entropy can only increase.
229
+
230
+ #### bitset.entropy_2n!
231
+ This sets the entropy number to the nearest 2**n that will contain the highest set element.
232
+
233
+ #### bitset.first(int=true), bitset.first!(int=true)
234
+ This returns the first element of the set, or nil if the set is empty.
235
+ The first element can be converted to a character if the parameter `int` is set to false.
236
+ The bang version removes and returns the first element of the set. The value `nil` is always returned if the set is empty.
237
+
238
+ #### bitset.last(int=true), bitset.last!(int=true)
239
+ This returns the last element of the set, or nil if the set is empty.
240
+ The last element can be converted to a character if the parameter `int` is set to false.
241
+ The bang version removes and returns the last element of the set. The value `nil` is always returned if the set is empty.
242
+
243
+ #### bitset.odd, bitset.even
244
+ This returns the odd or even elements of the set.
245
+
246
+ #### #### bitset.odd!, bitset.even!
247
+ The method `#odd!` retains odd elements and returns the even elements.
248
+ The method `#even!` retains even elements and returns the odd elements.
249
+
250
+ #### #### bitset.odd?, bitset.even?
251
+ This returns true if all elements in the set are odd or even. Note that empty sets are neither even or odd.
252
+
253
+ #### bitset.min, bitset.max
254
+ This returns the smallest or largest element of the set, or nil if the set is empty.
255
+ This is the same as `#first` and `#last` respectfully.
256
+
257
+ #### bitset.max_run
258
+ This returns the largest count of consecutive members.
259
+
260
+ #### bitset.runs
261
+ This returns a new set devoid of isolated elements.
262
+
263
+ #### bitset.runs?(n=2)
264
+ This returns true if the set includes a sequence of runs with a count greater than or equal to n.
265
+
266
+ #### bitset.singles
267
+ Returns a new set of only isolated elements.
268
+
269
+ #### object.to_bset
270
+ Method exported to Array, String, and Range. Returns self if BitSet type. This creates a new BitSet instance.
271
+
272
+ #### bitset.inc(n=1), bitset.dec(n=1), bitset.inc!(n=1), bitset.dec!(n=1)
273
+ These methods increment or decrement each element of the set. Internally, shifting occurs. The parameter `n`
274
+ is the increment (shift) amount. The bang versions self-modify, while the non-bang versions return a new set.
275
+ Decrementing has the possibility of losing bits, thereby making it non-reversible.
276
+
277
+ #### bitset.add_primes(n=100), bitset.add_primes!(n=100)
278
+ This is a generator method that adds prime numbers to the current set or creates a new set combining self with generated prime numbers.
279
+
280
+ #### bitset.add_parse_chars, bitset.add_parse_chars!
281
+ Parse chars comprise the ASCII-7bit characters that are either white space, or non-alpha-numeric characters.
282
+ These combine with self to form a new set. The bang version self-modifies.
283
+
284
+ #### bitset.add_lowercase_chars, bitset.add_lowercase_chars!
285
+ This returns the set of ASCII lowercase characters `'a'..'z'` combined (union) with the current BitSet instance.
286
+ The bang version self-modifies.
287
+
288
+ #### bitset.add_uppercase_chars, bitset.add_uppercase_chars!
289
+ This returns the set of ASCII uppercase characters `'A'..'Z'` combined (union) with the current BitSet instance.
290
+ The bang version self-modifies.
291
+
292
+ #### bitset.add_letter_chars, bitset.add_letter_chars!
293
+ This returns the set of ASCII letter characters `'a'..'z', 'A'..'Z'` combined (union) with the current BitSet instance.
294
+ The bang version self-modifies.
295
+
296
+ #### bitset.add_digit_chars, bitset.add_digit_chars!
297
+ This returns the set of ASCII number characters `'0'..'9'` combined (union) with the current BitSet instance.
298
+ The bang version self-modifies.
299
+
300
+ #### bitset.add_lowercase_utf, bitset.add_lowercase_utf!
301
+ This returns the set of UTF lowercase Latin and Greek non-ASCII lowercase characters combined (union) with the current BitSet instance.
302
+ The bang version self-modifies. You can chain this with `#add_lowercase_chars` to get all lowercase characters. Other UTF characters
303
+ of other languages are not included.
304
+
305
+ #### bitset.add_uppercase_utf, bitset.add_uppercase_utf!
306
+ This returns the set of UTF uppercase Latin and Greek non-ASCII lowercase characters combined (union) with the current BitSet instance.
307
+ The bang version self-modifies. You can chain this with `#add_uppercase_chars` to get all uppercase characters. Other UTF characters
308
+ of other languages are not included.
309
+
310
+ #### bitset.add_mixcase_utf, bitset.add_mixcase_utf!
311
+ There are a few UTF characters that combine two letters, starting with a uppercase and ending with a lowercase.
312
+ This set of characters are combined (union) with the current BitSet instance. The bang version self-modifies. Other UTF characters
313
+ of other languages are not included.
314
+
315
+ #### bitset.add_dual_lower_utf, bitset.add_dual_lower_utf!
316
+ This returns the set of UTF lowercase Latin and Green non-ASCII characters that combine two consecutive characters into one.
317
+ This set of characters are combined (union) with the current BitSet instance. The bang version self-modifies. Other UTF characters
318
+ of other languages are not included.
319
+
320
+ #### bitset.add_dual_upper_utf, bitset.add_dual_upper_utf!
321
+ This returns the set of UTF uppercase Latin and Green non-ASCII characters that combine two consecutive characters into one.
322
+ This set of characters are combined (union) with the current BitSet instance. The bang version self-modifies. Other UTF characters
323
+ of other languages are not included.
324
+
325
+ #### bitset.add_opposing_case, bitset.add_opposing_case!
326
+ This routine looks through the set and wherever there appears a letter character,
327
+ both upper and lower case versions of that character will be combined (union) with the set.
328
+ The bang version updates the current set, while the non-bang version returns a new set.
329
+ This works within the ASCII range only.
330
+
331
+ #### bitset.add_opposing_utf_case, bitset.add_opposing_utf_case!
332
+ This routine (a tad slower) looks at all letter characters, both ASCII and UTF, then adds the case changed letter to the set.
333
+ The bang version updates the current set, while the non-bang version returns a new set.
334
+
335
+ #### bitset.rand(n, return_type= :bset), bitset.rand!(n, return_type= :set)
336
+ This routine selects `n` random elements of the set in order to form a subset.
337
+ The bang version (`rand!`) retains the `n` random elements, and returns the remainder thereby splitting the set in two.
338
+ Passing a value of zero returns all elements of the set which is meaningless if the return type is a BitSet type;
339
+ this is because there is no implied order of a set, so this simply returns the set.
340
+ There is however meaning if we set the return type to something else.
341
+ The return type defaults to a BitSet type; or we can specify a different return type by setting the `return_type` parameter to one of the following symbols as follows:<br /n>
342
+
343
+ ```ruby
344
+ :array # returns an array of Integers
345
+ :array_chars # returns an array of String characters
346
+ :string # returns a String
347
+ :bset # returns a new BitSet instance
348
+ ```
349
+
350
+ #### bitset.split, bitset.split!
351
+ This bisects the set into two roughly equally sized sets and returns an array of two sets.
352
+ The first set contains the lower elements, while the second set contains the higher elements.
353
+ The bang version retaines the lower elements are returns the higher elements.
354
+
355
+ ###Class Methods
356
+
357
+ ### BitSet.fill(num_elements, start=0)
358
+ This constructs a BitSet instance with contiguous values set to the parameter `num_elements`.
359
+ The parameter `start` specifies the starting position of lowest element.
360
+ As an example, we can create a set of lowercase ASCII letters as follows:
361
+
362
+ ```ruby
363
+ aa = BitSet.fill(26,'a') # same as ['a'..'z'].to_bset
364
+ ```
365
+
366
+ #### BitSet.uppercase_chars, BitSet.lowercase_chars, BitSet.letter_chars
367
+ These methods create sets from the standard ASCII character set.
368
+ These are as follows: 'A'..'Z', 'a'..'z', and the combination of the former respectfully.
369
+
370
+ #### BitSet.digit_chars
371
+ These method creates a set from the standard ASCII character set representing '0'..'9' inclusive.
372
+
373
+ #### BitSet.parse_chars
374
+ This is the set of ASCII characters that are typically used as language tokens.
375
+ Pretty much everything that is not a number character or a letter character; this set also includes
376
+ the space character and all control characters.
377
+
378
+ #### BitSet.uppercase_utf_chars(return_set=true)
379
+ This creates a set comprising of UTF Latin and Greek characters that are considered uppercase.
380
+ This set does not include ASCII characters, nor does it include dual (two letters in one glyph) characters.
381
+ If the parameter is set to false, a string is instead returned.
382
+
383
+ #### BitSet.lowercase_utf_chars(return_set=true)
384
+ This creates a set comprising of UTF Latin and Greek characters that are considered lowercase.
385
+ This set does not include ASCII characters, nor does it include dual (two letters in one glyph) characters.
386
+ If the parameter is set to false, a string is instead returned.
387
+
388
+ #### BitSet.dual_uppercase_utf_chars(return_set=true)
389
+ This creates a set comprising of UTF Latin and Greek characters that are dual (two letters in one glyph) uppercase characters.
390
+ This set does not include ASCII characters.
391
+ If the parameter is set to false, a string is instead returned.
392
+
393
+ #### BitSet.dual_lowercase_utf_chars(return_set=true)
394
+ This creates a set comprising of UTF Latin and Greek characters that are dual (two letters in one glyph) lowercase characters.
395
+ This set does not include ASCII characters.
396
+ If the parameter is set to false, a string is instead returned.
397
+
398
+ #### BitSet.mixcase_utf_chars(return_set=true)
399
+ This creates a set comprising of UTF Latin and Greek characters that are dual (two letters in one glyph) where the two combined
400
+ characters have both an uppercase character and a lowercase character.
401
+ This set does not include ASCII characters.
402
+ If the parameter is set to false, a string is instead returned.
403
+
404
+ #### BitSet.get_utf_case_pairs(char=true)
405
+ This returns the hash that pairs uppercase utf characters with their lowercase counterparts.
406
+ The internal hash is stored using integer keys and values. When this method is called with the parameter set to true,
407
+ a new hash is created with string keys and values; otherwise the internal hash is returned.
408
+ This internal hash is used on the instance method `#add_opposing_utf_case`.
409
+
410
+ #### BitSet.zap_utf_case_pairs
411
+ This method creates a blank slate on the internal hash that contains the utf case pairs.
412
+
413
+ #### BitSet.default_utf_case_pairs
414
+ This method restores the internal hash that contains the utf case pairs to its default state.
415
+
416
+ #### BitSet.rm_utf_case_pairs(obj)
417
+ This method removes specific keys from the internal hash that contains the utf case pairs to its default state.
418
+ You can pass a string or an array that represents the keys that you wish to remove.
419
+ You should remove both the key and its value as the value is also a key in the hash.
420
+
421
+ #### BitSet.add_utf_case_pairs(str)
422
+ This method adds additional key-value pairs to the utf case pairs hash. The string should be even as both key and value
423
+ are reversible.
424
+
425
+ #### BitSet.default_utf_sets
426
+ This class method restores the following five utf sets: `::uppercase_utf_chars`, `::lowercase_utf_chars`,
427
+ `::mixcase_utf_chars`, `::dual_uppercase_utf_chars`, `::dual_lowercase_utf_chars`.
428
+
429
+ #### BitSet.zap_utf_sets
430
+ This class method empties the following five utf sets: `::uppercase_utf_chars`, `::lowercase_utf_chars`,
431
+ `::mixcase_utf_chars`, `::dual_uppercase_utf_chars`, `::dual_lowercase_utf_chars`.
432
+
433
+ #### BitSet.modify_utf_sets(*prms)
434
+ This class method modifies the following five utf sets: `::uppercase_utf_chars`, `::lowercase_utf_chars`,
435
+ `::mixcase_utf_chars`, `::dual_uppercase_utf_chars`, `::dual_lowercase_utf_chars`.
436
+ A list of parameters requires a command, a target, and a list of characters. This is best explained by example as follows:
437
+
438
+ ```ruby
439
+ # parameters:
440
+ # :rm ... remove command
441
+ # :add ... add command
442
+ # :upper ... targets ::uppercase_utf_chars
443
+ # :lower ... targets ::lowercase_utf_chars
444
+ # :mix ... targets ::mixcase_utf_chars
445
+ # :dual_upper ... targets ::dual_uppercase_utf_chars
446
+ # :dual_lower ... targets ::dual_lowercase_utf_chars
447
+ # example:
448
+
449
+ BitSet.modify_utf_sets(:add, :dual_upper, 8482) # add trade mark as valid
450
+ BitSet.modify_utf_sets(:rm, :dual_upper, 8482) # undo the above
451
+ ```
452
+
453
+ ### Tuple Processing
454
+ Tuples require a bit of explanation and some definitions.
455
+ A `group` is a collection of sets, in this case, an Array of BitSet instances.
456
+ A `tuple` is a set whereby it represents a `group` which holds the same number of sets as the order of the `tuple`;
457
+ this group's union must be equal to the `tuple` set. Also, a `tuple` cannot be an empty set.
458
+ The `order` of a `tuple` is the number of elements that it holds.
459
+ One more rule, is that a `tuple group` cannot include lower ordered `tuple groups`.
460
+ As most of the processing is performed upon a group of sets, these methods are implemented on the Array class.
461
+ Now that you are totally confused, a few examples should help clear things up as follows:
462
+
463
+ ```ruby
464
+ bs = [5].to_bset
465
+ BitSet.tuple? [bs] # true, group of 1 same as union of all
466
+
467
+ s1 = [4,9].to_bset
468
+ s2 = [4,9].to_bset
469
+ s3 = [4,5].to_bset
470
+ [s1,s2].tuple? # true, set of two same as: s1 | s2
471
+ [s1,s2,s3].tuple? # false, order 2 found in group
472
+ [s2,s3].tuple? # false, order 3 tuple does not match 2 set items
473
+ [s1,s2].tuple # returns BitSet[s1,s2]
474
+ [s2,s3].tuple # returns nil, or invalid tuple
475
+ [s1,s2,s3].tuple # returns nil, or invalid tuple
476
+
477
+ s1 = [4,9].to_bset
478
+ s2 = [5,9].to_bset
479
+ s3 = [4,5].to_bset
480
+ [s1,s2,s3]tuple? # true, order 3, and s1 | s2 | s3 == [4,5,9]
481
+ [s1,s2,s3].tuple # returns BitSet [4,5,9]
482
+
483
+ s1 = [7,8].to_bset
484
+ s2 = [3,9].to_bset
485
+ s3 = [3,7].to_bset
486
+ s4 = [3,7,8,9].to_bset
487
+ [s1,s2,s3,s4].tuple? # true, order 4, and s1 | s2 | s3 | s4 == [3,7,8,9]
488
+ [s1,s2,s3,s4]tuple # returns BitSet [3,7,8,9]
489
+ ```
490
+
491
+ As you can see from the example, higher ordered `tuples` exponentially grow in complexity.
492
+
493
+ #### ary.tuples(group)
494
+
495
+ This routine examines the group (array of sets) and collects tuples starting from lower order tuples first.
496
+ These lower-ordered tuples are removed from consideration when locating higher-ordered tuples.
497
+ Violations are tuples that have too many matches in a sub-group for that particular order.
498
+ Incomplete tuples which would have been considered an error are ignored.
499
+
500
+ This routine returns an array of two groups of sets. The first group is the collection of sub-tuples found
501
+ in the group. The second array returns the tuple violations. See the example below:
502
+
503
+ ```ruby
504
+ group = []
505
+ group.push [1,2].to_bset
506
+ group.push [7,8].to_bset
507
+ group.push [4,5].to_bset
508
+ group.push [3,4,5].to_bset
509
+ group.push [3,5].to_bset
510
+ group.push [3,4,5,7,8,9].to_bset
511
+ group.push [7,8].to_bset
512
+ group.push [1,2,5,6,9].to_bset
513
+ group.push [1,2].to_bset
514
+ rslt = group.tuples
515
+ valid_tuples = rslt.first # finds 3
516
+ error_tuples = rslt.last # empty ... no violations
517
+ valid_tuples[0].to_a # [1,2]
518
+ valid_tuples[1].to_a # [7,8]
519
+ valid_tuples[2].to_a # [3,4,5]
520
+ ```
521
+
522
+ #### ary.reduce_tuples(pass_count=1)
523
+
524
+ This routine calls BitSet.tuples class method and applies that knowledge to reducing each member of that group.
525
+ If a group member contains a proper set of one of the found tuples,
526
+ that member subtracts that particular tuple from its elements. This knowledge can be used to solve Sudoku puzzles.
527
+ In fact, the rspec spec file includes a Sudoku puzzle that gets solved from this singular rule.
528
+ The routine returns the number of reductions performed. The group is self-modified with the reduced sets.
529
+ Using the same group from the previous example, we get the following result:
530
+
531
+ ```ruby
532
+ group.reduce_tuples(1)
533
+ group[0].to_a # [1,2]
534
+ group[1].to_a # [7,8]
535
+ group[2].to_a # [4,5]
536
+ group[3].to_a # [3,4,5]
537
+ group[4].to_a # [3,5]
538
+ group[5].to_a # [9]
539
+ group[6].to_a # [7,8]
540
+ group[7].to_a # [6,9] ... second pass [6]
541
+ group[8].to_a # [1,2]
542
+ ```
543
+
544
+ We notice from the first reduction another tuple [9] was created.
545
+ This means another pass will further reduce the group. The first pass only uses the tuples
546
+ it found in the first pass which were 3. The second pass will find 4 tuples which will further
547
+ reduce the group. If you pass a large number on the second parameter, the routine will
548
+ continually evaluate until no reduction occurs, or the `pass_count` counts down to zero.
549
+
550
+ #### ary.members_to_bset
551
+ This utility method converts elements of the array to BitSets instances.
552
+
553
+ #### ary.untag_bset_elements
554
+ During the reduction process some items in the array get tagged. This routine clears such tagging.
555
+ This is a utility method called by the `#reduce_tuples` method.
556
+
557
+ ###case subsumption operator ===
558
+ The `===` operator has special meaning in ruby. It is known as the case subsumption operator.
559
+ It is used during the `case when` statements as its comparison means.
560
+ The left side of the operator's type is the owner and defines what it means to have the right side passed to it.
561
+ It is like a method call: `my_left_instance.tripple_equals(right_instance)`.
562
+ You could call like this: `(1..3).===(2)` returning true. This is the same as: `(1..3) === 2`.
563
+ Note that `Array` does not define this operator so the following expression returns false: `[1,2,3] === 2`
564
+ It turns out if you don't define it, `Kernel` will define it for you which will look more or less like `==`.
565
+ The default behavior for a BitSet instance is a test for equality; but this can be changed on an instance by instance basis.
566
+
567
+ #### bitset.set_case(sym=:mode_equal)
568
+ This instance method defines the meaning of the `===` operator for the current instance variable.
569
+ There are six different modes of operation as follows:
570
+
571
+ ```ruby
572
+ # where `x` is the current BitSet instance variable, and `y` is a BitSet friendly type.
573
+ # :mode_intersection ... (x===y) true if x ** y
574
+ # :mode_equal ... (x===y) true if x == y
575
+ # :mode_sub ... (x===y) true if y <= x
576
+ # :mode_proper ... (x===y) true if y < x
577
+ # :mode_super ... (x===y) true if x <= y
578
+ # :mode_superproper ... (x===y) true if x < y
579
+
580
+ x = ('a'..'z').to_bset
581
+ x.set_case :mode_intersection
582
+ x === "Fred" # true 'r', 'e', 'd' all intersect
583
+ x === "RED" # false
584
+
585
+ x.set_case :mode_proper
586
+ x === "Fred" # false
587
+ x === "fred" # true
588
+ x === x # false, not a proper set
589
+
590
+ x.set_case :mode_superproper
591
+ x === x # false
592
+ x === "Fred" # false , "Fred" is not a superset of x
593
+ x === "Fred" | x # true
594
+ ```
595
+
596
+ ## Revision History
597
+
598
+ ### Version 3.0.0
599
+
600
+ * added tuple processing
601
+ * added BitSet.fill construction method
602
+ * updated utf methods
603
+ * fixed range bugs
604
+ * includes gems: primitive_wrapper, pred, betterobject, yieldhelper
605
+
606
+ ### Older Versions
607
+ See `bdlsys.com/gems/setfu` to get older documents.
8
608
 
9
609
  ## Installation
10
610
 
@@ -22,4 +622,4 @@ Or install it yourself as:
22
622
 
23
623
  ## Contributing
24
624
 
25
- Not on github yet ... stay tuned!
625
+ I need to control this for the time being
data/lib/setfu/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Setfu
2
- VERSION = "2.1.0"
2
+ VERSION = "3.0.0"
3
3
  end