Class: BitSet

Inherits:
Object show all
Defined in:
lib/setfu.rb,
lib/setfu.rb,
lib/setfu.rb,
lib/setfu.rb,
lib/setfu.rb,
lib/setfu.rb,
lib/setfu.rb,
lib/setfu.rb,
lib/setfu.rb,
lib/setfu.rb,
lib/setfu.rb,
lib/setfu.rb,
lib/setfu.rb,
lib/setfu.rb,
lib/setfu.rb,
lib/setfu.rb

Overview

now the stuff that slows down the editor … so last goes here

Constant Summary collapse

UTF_UPPER_CASE_CHARS =

SETFU ‘ɶ’ uppercase or lowercase ??? I have this as lowercase, but I could be wrong …

leave in lowercase_dual until you get difinitive answer
"ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÑÒÓÔÕÖØÙÚÛÜÝÞðĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮIJĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŦŨŪŬŮŰŲŴŶŸŹŻŽƁƂƄƆƇƉƊƋƎƏƐƑƓƔƖƗƘƜƝƟƠƢƤƦƧƩƬƮƯƱƲƳƵƷƸƼǍǏǑǓǕǗǙǛǞǠǢǤǦǨǪǬǮǴǶǷǸǺǼǾȀȂȄȆȈȊȌȎȐȒȔȖȘȚȜȞȠȢȤȦȨȪȬȮȰȲȺȻȽȾɁɃɄɅɆɈɊɌɎΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩⱭⱯⱰⱾⱿfl"
UTF_LOWER_CASE_CHARS =
"Ðàáâãäåçèéêëìíîïñòóôõöøùúûüýþÿāăąćĉċčďđēĕėęěĝğġģĥħĩīĭįĵķĺļľŀłńņňŋōŏőŕŗřśŝşšţťŧũūŭůűųŵŷźżžƀƃƅƈƌƒƕƙƚƞơƥƨƭưƴƶƹƽƿǎǐǒǔǖǘǚǜǝǟǡǥǧǩǫǭǯǵǹǻǿȁȃȅȇȉȋȍȏȑȓȕȗșțȝȟȥȧȩȫȭȯȱȳȼȿɀɂɇɉɋɍɏɐɑɒɓɔɖɗəɛɠɣɨɩɯɲɵʀʃʈʉʊʋʌʒαβγδεζηθικλμνξοπρςστυφχψωⱥⱦfi"
UTF_LOWER_CASE_DUAL_CHARS =
"ȸȹijnjdždzʣʥæǣǽƣœœɶʦljʪʫijȣ"
UTF_UPPER_CASE_DUAL_CHARS =
"NJDŽDZÆǢǼƢƢŒLJIJIJȢ"
UTF_MIXED_CASE_DUAL_CHARS =
"LjNjDžDz"
@@even_bits =
0x5555555555555555555555555555555555555555555555555555555555555555
@@odd_bits =
0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
@@shifts =
256

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*data) ⇒ BitSet

Returns a new instance of BitSet.



591
592
593
594
595
596
# File 'lib/setfu.rb', line 591

def initialize(*data)
  @bits = 0
  @entropy = 0
  add!(data)
  self
end

Instance Attribute Details

#entropyObject

Returns the value of attribute entropy.



413
414
415
# File 'lib/setfu.rb', line 413

def entropy
  @entropy
end

Class Method Details

.add_utf_case_pairs(str) ⇒ Object



1489
1490
1491
1492
1493
1494
1495
# File 'lib/setfu.rb', line 1489

def self.add_utf_case_pairs(str)
  return if str.empty?
  raise "add_utf_case_pairs requires even number of characters" unless str.length.even?
  0.step(str.length-2,2) do |x|
    @@TRANS_HASH[str[x].ord]=str[x+1].ord
  end
end

.default_utf_case_pairsObject



1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
# File 'lib/setfu.rb', line 1427

def self.default_utf_case_pairs
  @@TRANS_HASH = {
192=>224, 193=>225, 194=>226, 195=>227, 196=>228, 197=>229, 198=>230, 199=>231, 200=>232, 201=>233, 202=>234, 
203=>235, 204=>236, 205=>237, 206=>238, 207=>239, 208=>240, 209=>241, 210=>242, 211=>243, 212=>244, 213=>245,
214=>246, 216=>248, 217=>249, 218=>250, 219=>251, 220=>252, 221=>253, 222=>254, 224=>192, 225=>193, 226=>194,
227=>195, 228=>196, 229=>197, 230=>198, 231=>199, 232=>200, 233=>201, 234=>202, 235=>203, 236=>204, 237=>205,
238=>206, 239=>207, 240=>208, 241=>209, 242=>210, 243=>211, 244=>212, 245=>213, 246=>214, 248=>216, 249=>217,
250=>218, 251=>219, 252=>220, 253=>221, 254=>222, 255=>376, 256=>257, 257=>256, 258=>259, 259=>258, 260=>261,
261=>260, 262=>263, 263=>262, 264=>265, 265=>264, 266=>267, 267=>266, 268=>269, 269=>268, 270=>271, 271=>270,
272=>273, 273=>272, 274=>275, 275=>274, 276=>277, 277=>276, 278=>279, 279=>278, 280=>281, 281=>280, 282=>283,
283=>282, 284=>285, 285=>284, 286=>287, 287=>286, 288=>289, 289=>288, 290=>291, 291=>290, 292=>293, 293=>292,
294=>295, 295=>294, 296=>297, 297=>296, 298=>299, 299=>298, 300=>301, 301=>300, 302=>303, 303=>302, 306=>307,
307=>306, 308=>309, 309=>308, 310=>311, 311=>310, 313=>314, 314=>313, 315=>316, 316=>315, 317=>318, 318=>317,
319=>320, 320=>319, 321=>322, 322=>321, 323=>324, 324=>323, 325=>326, 326=>325, 327=>328, 328=>327, 330=>331,
331=>330, 332=>333, 333=>332, 334=>335, 335=>334, 336=>337, 337=>336, 338=>339, 339=>338, 340=>341, 341=>340,
342=>343, 343=>342, 344=>345, 345=>344, 346=>347, 347=>346, 348=>349, 349=>348, 350=>351, 351=>350, 352=>353,
353=>352, 354=>355, 355=>354, 356=>357, 357=>356, 358=>359, 359=>358, 360=>361, 361=>360, 362=>363, 363=>362,
364=>365, 365=>364, 366=>367, 367=>366, 368=>369, 369=>368, 370=>371, 371=>370, 372=>373, 373=>372, 374=>375,
375=>374, 376=>255, 377=>378, 378=>377, 379=>380, 380=>379, 381=>382, 382=>381, 384=>579, 385=>595, 386=>387,
387=>386, 388=>389, 389=>388, 390=>596, 391=>392, 392=>391, 393=>598, 394=>599, 395=>396, 396=>395, 398=>477,
399=>601, 400=>603, 401=>402, 402=>401, 403=>608, 404=>611, 405=>502, 406=>617, 407=>616, 408=>409, 409=>408,
410=>573, 412=>623, 413=>626, 414=>544, 415=>629, 416=>417, 417=>416, 418=>419, 419=>418, 420=>421, 421=>420, 422=>640,
423=>424, 424=>423, 425=>643, 428=>429, 429=>428, 430=>648, 431=>432, 432=>431, 433=>650, 434=>651, 435=>436,
436=>435, 437=>438, 438=>437, 439=>658, 440=>441, 441=>440, 444=>445, 445=>444, 447=>503, 452=>454, 454=>452, 455=>457, 457=>455, 458=>460, 460=>458, 461=>462, 462=>461,
463=>464, 464=>463, 465=>466, 466=>465, 467=>468, 468=>467, 469=>470, 470=>469, 471=>472, 472=>471, 473=>474,
474=>473, 475=>476, 476=>475, 477=>398, 478=>479, 479=>478, 480=>481, 481=>480, 482=>483, 483=>482, 484=>485,
485=>484, 486=>487, 487=>486, 488=>489, 489=>488, 490=>491, 491=>490, 492=>493, 493=>492, 494=>495, 495=>494, 497=>499, 499=>497, 
500=>501, 501=>500, 502=>405, 503=>447, 504=>505, 505=>504, 506=>507, 507=>506, 508=>509, 509=>508, 510=>511,
511=>510, 512=>513, 513=>512, 514=>515, 515=>514, 516=>517, 517=>516, 518=>519, 519=>518, 520=>521, 521=>520,
522=>523, 523=>522, 524=>525, 525=>524, 526=>527, 527=>526, 528=>529, 529=>528, 530=>531, 531=>530, 532=>533,
533=>532, 534=>535, 535=>534, 536=>537, 537=>536, 538=>539, 539=>538, 540=>541, 541=>540, 542=>543, 543=>542,
544=>414, 546=>547, 547=>546, 548=>549, 549=>548, 550=>551, 551=>550, 552=>553, 553=>552, 554=>555, 555=>554,
556=>557, 557=>556, 558=>559, 559=>558, 560=>561, 561=>560, 562=>563, 563=>562, 570=>11365, 571=>572, 572=>571,
573=>410, 574=>11366, 575=>11390, 576=>11391, 577=>578, 578=>577, 579=>384, 580=>649, 581=>652, 582=>583, 583=>582,
584=>585, 585=>584, 586=>587, 587=>586, 588=>589, 589=>588, 590=>591, 591=>590, 592=>11375, 593=>11373, 594=>11376,
595=>385, 596=>390, 598=>393, 599=>394, 601=>399, 603=>400, 608=>403, 611=>404, 616=>407, 617=>406, 623=>412, 626=>413,
629=>415, 640=>422, 643=>425, 648=>430, 649=>580, 650=>433, 651=>434, 652=>581, 658=>439, 913=>945, 914=>946, 915=>947, 916=>948,
917=>949, 918=>950, 919=>951, 920=>952, 921=>953, 922=>954, 923=>955, 924=>956, 925=>957, 926=>958, 927=>959, 928=>960,
929=>961, 931=>963, 932=>964, 933=>965, 934=>966, 935=>967, 936=>968, 937=>969, 945=>913, 946=>914, 947=>915, 948=>916,
949=>917, 950=>918, 951=>919, 952=>920, 953=>921, 954=>922, 955=>923, 956=>924, 957=>925, 958=>926, 959=>927, 960=>928,
961=>929, 962=>931, 963=>931, 964=>932, 965=>933, 966=>934, 967=>935, 968=>936, 969=>937, 11365=>570, 11366=>574, 11373=>593,
11375=>592, 11376=>594, 11390=>575, 11391=>576, 64257=>64258, 64258=>64257 }
end

.default_utf_setsObject



1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
# File 'lib/setfu.rb', line 1568

def self.default_utf_sets
  @@UTF_UPPER_CASE_CHARS = UTF_UPPER_CASE_CHARS
  @@UTF_LOWER_CASE_CHARS = UTF_LOWER_CASE_CHARS
  @@UTF_LOWER_CASE_DUAL_CHARS = UTF_LOWER_CASE_DUAL_CHARS
  @@UTF_UPPER_CASE_DUAL_CHARS = UTF_UPPER_CASE_DUAL_CHARS
  @@UTF_MIXED_CASE_DUAL_CHARS = UTF_MIXED_CASE_DUAL_CHARS

  @@UTF_UPPER_CASE_SET = UTF_UPPER_CASE_CHARS.to_bset
  @@UTF_LOWER_CASE_SET = UTF_LOWER_CASE_CHARS.to_bset
  @@UTF_LOWER_CASE_DUAL_SET = UTF_LOWER_CASE_DUAL_CHARS.to_bset
  @@UTF_UPPER_CASE_DUAL_SET = UTF_UPPER_CASE_DUAL_CHARS.to_bset
  @@UTF_MIXED_CASE_DUAL_SET = UTF_MIXED_CASE_DUAL_CHARS.to_bset
end

.digit_charsObject



457
458
459
460
461
462
# File 'lib/setfu.rb', line 457

def self.digit_chars
  set = BitSet.new
  set.set_bits!(287948901175001088)
  set.entropy=58
  return set
end

.dual_lowercase_utf_chars(return_set = true) ⇒ Object



1613
1614
1615
1616
# File 'lib/setfu.rb', line 1613

def self.dual_lowercase_utf_chars(return_set=true)
  return @@UTF_LOWER_CASE_DUAL_SET.dup if return_set
  return @@UTF_LOWER_CASE_DUAL_CHARS.dup
end

.dual_uppercase_utf_chars(return_set = true) ⇒ Object



1609
1610
1611
1612
# File 'lib/setfu.rb', line 1609

def self.dual_uppercase_utf_chars(return_set=true)
  return @@UTF_UPPER_CASE_DUAL_SET.dup if return_set
  return @@UTF_UPPER_CASE_DUAL_CHARS.dup
end

.fill(n_elms, start = 0) ⇒ Object



427
428
429
430
431
432
433
434
# File 'lib/setfu.rb', line 427

def self.fill(n_elms, start=0)
  set = BitSet.new
  bits = (1 << n_elms) - 1
  set.set_bits!(bits)
  set.entropy=n_elms
  set.inc!(start.ord)
  return set
end

.generate_pattern(nbits, flag_zero_first, zeros, ones) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/setfu.rb', line 135

def self.generate_pattern(nbits, flag_zero_first, zeros, ones )
  bs = BitSet.new
  bs.entropy = nbits
  return bs if ones<=0
  return bs | [0..(nbits-1)] if zeros<=0
  k=0
  hash = {:zero => zeros, :one => ones}
  if flag_zero_first
    ptr = :zero
    val = false
  else
    ptr = :one
    val = true
  end
  nbits.times do |ii|
    if (k >= hash[ptr])
      k = 1
      val = !val
      ptr = (ptr == :zero) ? :one : :zero
    else
      k += 1  
    end
    bs[ii] = val
  end
  return bs
end

.get_utf_case_pairs(char = true) ⇒ Object



1497
1498
1499
1500
1501
1502
1503
1504
1505
# File 'lib/setfu.rb', line 1497

def self.get_utf_case_pairs(char=true)
  return @@TRANS_HASH.dup unless char
  rtn = {}
  @@TRANS_HASH.each_pair do |key,value|
    rtn[key.chr(Encoding::UTF_8)] = value.chr(Encoding::UTF_8)
    rtn[value.chr(Encoding::UTF_8)] = key.chr(Encoding::UTF_8)
  end
  return rtn
end

.int(int, ent = nil) ⇒ Object



177
178
179
180
181
182
183
184
185
186
# File 'lib/setfu.rb', line 177

def self.int(int,ent=nil)
  bs = BitSet.new
  bs.set_bits!(int)
  if ent.nil?
    bs.recalculate_entropy!
  else
    bs.entropy=ent
  end
  bs
end

.letter_charsObject



450
451
452
453
454
455
# File 'lib/setfu.rb', line 450

def self.letter_chars
  set = BitSet.new
  set.set_bits!(10633823810298881996379053697534001152)
  set.entropy=123
  return set
end

.lowercase_charsObject



443
444
445
446
447
448
# File 'lib/setfu.rb', line 443

def self.lowercase_chars
  set = BitSet.new
  set.set_bits!(10633823807823001954701781295154855936)
  set.entropy=123
  return set
end

.lowercase_utf_chars(return_set = true) ⇒ Object



1601
1602
1603
1604
# File 'lib/setfu.rb', line 1601

def self.lowercase_utf_chars(return_set=true)
  return @@UTF_LOWER_CASE_SET.dup if return_set
  return @@UTF_LOWER_CASE_CHARS.dup
end

.mixcase_utf_chars(return_set = true) ⇒ Object



1605
1606
1607
1608
# File 'lib/setfu.rb', line 1605

def self.mixcase_utf_chars(return_set=true)
  return @@UTF_MIXED_CASE_DUAL_SET.dup if return_set
  return @@UTF_MIXED_CASE_DUAL_CHARS.dup
end

.modify_utf_sets(*prms) ⇒ Object



1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
# File 'lib/setfu.rb', line 1618

def self.modify_utf_sets(*prms)
  flag_add = true
  target_chars = nil
  target_set   = nil
  source = nil
  prms.each do |prm|
    if    prm.type_of? String
      source = prm
    elsif prm.type_of? BitSet
      source = prm
    elsif prm.type_of? Array
      source = prm
    elsif prm.type_of? Integer
      source = [prm]
    elsif prm.type_of? Symbol
      if prm == :rm
        flag_add = false
      elsif prm == :add
        flag_add = true
      elsif prm == :mix
        target_chars = "@@UTF_MIXED_CASE_DUAL_CHARS"
        target_set   = "@@UTF_MIXED_CASE_DUAL_SET"
      elsif prm == :upper
        target_chars = "@@UTF_UPPER_CASE_CHARS"
        target_set   = "@@UTF_UPPER_CASE_SET"
      elsif prm == :lower
        target_chars = "@@UTF_LOWER_CASE_CHARS"
        target_set   = "@@UTF_LOWER_CASE_SET"
      elsif prm == :dual_upper
        target_chars = "@@UTF_UPPER_CASE_DUAL_CHARS"
        target_set   = "@@UTF_UPPER_CASE_DUAL_SET"
      elsif prm == :dual_lower
        target_chars = "@@UTF_LOWER_CASE_DUAL_CHARS"
        target_set   = "@@UTF_LOWER_CASE_DUAL_SET"
      end
    end
  end
  return false if target_chars.nil? 
  return false if source.nil?
  if flag_add
    eval("#{target_set} |= source")
    eval("#{target_chars} = #{target_set}.to_s")
  else
    eval("#{target_set} -= source")
    eval("#{target_chars} = #{target_set}.to_s")
  end
  return true
end

.parse_charsObject



464
465
466
467
468
469
# File 'lib/setfu.rb', line 464

def self.parse_chars
  set = BitSet.new
  set.set_bits!(159507359650170349735020301117175103487)
  set.entropy=127
  return set
end

.rm_utf_case_pairs(obj) ⇒ Object



1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
# File 'lib/setfu.rb', line 1477

def self.rm_utf_case_pairs(obj)
  if obj.respond_to? :each_char
    obj.each_char do |ch|
      @@TRANS_HASH.delete str.ord
    end
  else
    obj.each do |elm|
      @@TRANS_HASH.delete elm
    end  
  end  
end

.uppercase_charsObject



436
437
438
439
440
441
# File 'lib/setfu.rb', line 436

def self.uppercase_chars
  set = BitSet.new
  set.set_bits!(2475880041677272402379145216)
  set.entropy=91
  return set
end

.uppercase_utf_chars(return_set = true) ⇒ Object



1597
1598
1599
1600
# File 'lib/setfu.rb', line 1597

def self.uppercase_utf_chars(return_set=true)
  return @@UTF_UPPER_CASE_SET.dup if return_set
  return @@UTF_UPPER_CASE_CHARS.dup
end

.zap_utf_case_pairsObject



1473
1474
1475
# File 'lib/setfu.rb', line 1473

def self.zap_utf_case_pairs
  @@TRANS_HASH = {}
end

.zap_utf_setsObject



1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
# File 'lib/setfu.rb', line 1583

def self.zap_utf_sets
  @@UTF_UPPER_CASE_CHARS = ""
  @@UTF_LOWER_CASE_CHARS = ""
  @@UTF_LOWER_CASE_DUAL_CHARS = ""
  @@UTF_UPPER_CASE_DUAL_CHARS = ""
  @@UTF_MIXED_CASE_DUAL_CHARS = ""

  @@UTF_UPPER_CASE_SET = "".to_bset
  @@UTF_LOWER_CASE_SET = "".to_bset
  @@UTF_LOWER_CASE_DUAL_SET = "".to_bset
  @@UTF_UPPER_CASE_DUAL_SET = "".to_bset
  @@UTF_MIXED_CASE_DUAL_SET = "".to_bset
end

Instance Method Details

#!=(item) ⇒ Object



735
736
737
738
739
740
741
742
# File 'lib/setfu.rb', line 735

def !=(item)
  if(item.type_of? BitSet)
    rtn = item.to_i != self.to_i
  else
    rtn = BitSet.new(item).to_i != self.to_i
  end
  rtn
end

#&(item) ⇒ Object



690
691
692
693
694
695
696
697
698
699
# File 'lib/setfu.rb', line 690

def &(item)
  rtn = self.dup
  if(item.type_of? BitSet)
    rtn.set_bits!(rtn.to_i & item.to_i)
  else
    rtn = BitSet.new(item)
    rtn.set_bits!(@bits & rtn.to_i)
  end
  rtn
end

#**(item) ⇒ Object

intersection test



719
720
721
722
723
# File 'lib/setfu.rb', line 719

def **(item)  # intersection test
  set_item = BitSet.new(item)
  return false if (self & set_item).empty?
  return true
end

#-(item) ⇒ Object



701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
# File 'lib/setfu.rb', line 701

def -(item)
  rtn = BitSet.new
  rtn.entropy = self.entropy
  a = self.to_i
  if(item.type_of? BitSet)
    b = item.to_i
    rtn.entropy = item.entropy
  else
    b = BitSet.new(item)
    rtn.entropy = b.entropy
    b = b.to_i
  end
  c = a & b
  d = c ^ a
  rtn.set_bits!(d)
  rtn
end

#<(item) ⇒ Object



781
782
783
784
785
# File 'lib/setfu.rb', line 781

def <(item)
  si = BitSet.new item
  return false if (si == self)  # not a 'proper' subset
  return si.include?(self)
end

#<=(item) ⇒ Object



776
777
778
779
# File 'lib/setfu.rb', line 776

def <=(item)
  si = BitSet.new item
  return si.include?(self)
end

#==(item) ⇒ Object

comparison operators:



726
727
728
729
730
731
732
733
# File 'lib/setfu.rb', line 726

def ==(item)
  if(item.type_of? BitSet)
    rtn = item.to_i == self.to_i
  else
    rtn = BitSet.new(item).to_i == self.to_i
  end
  rtn
end

#===(item) ⇒ Object



753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
# File 'lib/setfu.rb', line 753

def ===(item)
  # self ... when clause  ... 
  # item ... case clause  ... case(item)
  # Note: coerce does not work in this context ...
  
  md = item.to_bset.mode || @mode
  
  case md
    when :mode_intersection
      return item ** self
    when :mode_sub
      return item <= self
    when :mode_proper
      return item < self
    when :mode_super
      return self <= item
    when :mode_superproper
      return self < item
    else
      return self == item  
  end
end

#[](*pset) ⇒ Object

new behavior … single element returns true/false multi element … returns subset



991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
# File 'lib/setfu.rb', line 991

def [](*pset)
  idx = nil
  if pset.count==1  # check for single instance  inst[5], inst['t']
    if pset.first.type_of? Integer
      idx = pset.first
    elsif pset.first.type_of? String
      if pset.first.length == 1
        idx = pset.first.ord
      end
    end
  end
  unless idx.nil?
    raise "Negative indexes are illegal for BitSet" if idx < 0
    self.entropy = idx+1
    y = @bits & (1<<idx)
    return true if y > 0
    return false    
  end
  return pset.to_bset & self
end

#[]=(*pset, value) ⇒ Object

pset goes in the box, value after ‘=’



1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
# File 'lib/setfu.rb', line 1012

def []=(*pset,value)  # pset goes in the box, value after '='
  pset = pset.to_bset
  state = value ? true : false
  if state
    replace pset | self  # add elements to set
  else
    replace self - pset  # remove elements from set
  end
  return state # this gets ignored, but to be safe, do what the previous version did   
end

#^(item) ⇒ Object



667
668
669
670
671
672
673
674
675
676
# File 'lib/setfu.rb', line 667

def ^(item)
  rtn = self.dup
  if(item.type_of? BitSet)
    rtn.set_bits!(rtn.to_i ^ item.to_i)
  else
    rtn = BitSet.new(item)
    rtn.set_bits!(@bits ^ rtn.to_i)
  end
  rtn
end

#add(items) ⇒ Object



819
820
821
# File 'lib/setfu.rb', line 819

def add(items)
  dup.add!(items)
end

#add!(items) ⇒ Object



787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
# File 'lib/setfu.rb', line 787

def add!(items)
  if(items.type_of? BitSet)
    @bits |= items.to_i
    entropy = items.entropy
  elsif(items.type_of? Range)
    ran = items.reorder.simplify
    return add!(ran.to_a) unless ran.simple?
    f=ran.first.ord
    l=ran.last.ord
    # f,l = l,f if f>l
    t = (l-f)+1
    t = (1 << t)-1
    @bits |= t << f
    self.entropy = l+1
  elsif(items.respond_to? :each_char)
    items.each_char do |item|
      @bits |= 1 << item.ord
      self.entropy = item.ord+1
    end
  elsif(items.respond_to? :each)
    items.each do |item|
      add! item
    end
  else #assume number
    raise "negative numbers are not allowed" if items < 0
    pos = 1 << items
    @bits |= pos
    self.entropy = items+1
  end
  self
end

#add_digit_charsObject



494
495
496
# File 'lib/setfu.rb', line 494

def add_digit_chars
  return BitSet.digit_chars | self
end

#add_digit_chars!Object



489
490
491
492
# File 'lib/setfu.rb', line 489

def add_digit_chars!
  add! BitSet.digit_chars
  self
end

#add_dual_lower_utfObject



1703
1704
1705
# File 'lib/setfu.rb', line 1703

def add_dual_lower_utf
  return BitSet.dual_lowercase_utf_chars | self
end

#add_dual_lower_utf!Object



1707
1708
1709
1710
# File 'lib/setfu.rb', line 1707

def add_dual_lower_utf!
  add! BitSet.dual_lowercase_utf_chars
  self
end

#add_dual_upper_utfObject



1694
1695
1696
# File 'lib/setfu.rb', line 1694

def add_dual_upper_utf
  return BitSet.dual_uppercase_utf_chars | self
end

#add_dual_upper_utf!Object



1698
1699
1700
1701
# File 'lib/setfu.rb', line 1698

def add_dual_upper_utf!
  add! BitSet.dual_uppercase_utf_chars
  self
end

#add_letter_charsObject



516
517
518
# File 'lib/setfu.rb', line 516

def add_letter_chars
  return BitSet.letter_chars | self
end

#add_letter_chars!Object



520
521
522
523
# File 'lib/setfu.rb', line 520

def add_letter_chars!
  add! BitSet.letter_chars
  self
end

#add_lowercase_charsObject



512
513
514
# File 'lib/setfu.rb', line 512

def add_lowercase_chars
  return BitSet.lowercase_chars | self
end

#add_lowercase_chars!Object



507
508
509
510
# File 'lib/setfu.rb', line 507

def add_lowercase_chars!
  add! BitSet.lowercase_chars
  self
end

#add_lowercase_utfObject



1667
1668
1669
# File 'lib/setfu.rb', line 1667

def add_lowercase_utf
  return BitSet.lowercase_utf_chars | self
end

#add_lowercase_utf!Object



1671
1672
1673
1674
# File 'lib/setfu.rb', line 1671

def add_lowercase_utf!
  add! BitSet.lowercase_utf_chars
  self
end

#add_mixcase_utfObject



1685
1686
1687
# File 'lib/setfu.rb', line 1685

def add_mixcase_utf
  return BitSet.mixcase_utf_chars | self
end

#add_mixcase_utf!Object



1689
1690
1691
1692
# File 'lib/setfu.rb', line 1689

def add_mixcase_utf!
  add! BitSet.mixcase_utf_chars
  self
end

#add_opposing_caseObject



1518
1519
1520
# File 'lib/setfu.rb', line 1518

def add_opposing_case
  dup.add_opposing_case!
end

#add_opposing_case!Object



1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
# File 'lib/setfu.rb', line 1507

def add_opposing_case!
  aa = BitSet.lowercase_chars
  bb = BitSet.uppercase_chars
  ka = aa & self  # subset lower case
  kb = bb & self  # subset upper case
  @bits |= ka.to_i >> 32
  @bits |= kb.to_i << 32
  self.entropy = 32 + kb.recalculate_entropy! if self.entropy <= 123
  self
end

#add_opposing_utf_caseObject



1534
1535
1536
# File 'lib/setfu.rb', line 1534

def add_opposing_utf_case
  dup.add_opposing_utf_case!  
end

#add_opposing_utf_case!Object



1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
# File 'lib/setfu.rb', line 1522

def add_opposing_utf_case!
  add_opposing_case!
  tmp = @@TRANS_HASH.sort
  st = tmp.first[0]
  nd = tmp.last[0]
  self.each_member(st..nd) do |elm|
    unless @@TRANS_HASH[elm].nil?
      @bits |= 1 << @@TRANS_HASH[elm]
      @entropy = elm if elm > @entropy
    end
  end   
end

#add_parse_charsObject



485
486
487
# File 'lib/setfu.rb', line 485

def add_parse_chars
  return BitSet.parse_chars | self
end

#add_parse_chars!Object



479
480
481
482
483
# File 'lib/setfu.rb', line 479

def add_parse_chars!
  # add! [0..47, 58..64, 91..96, 123..126]
  add! BitSet.parse_chars
  self
end

#add_primes(n = 100) ⇒ Object



1421
1422
1423
# File 'lib/setfu.rb', line 1421

def add_primes(n=100)
  self.add(Prime.take(n))
end

#add_primes!(n = 100) ⇒ Object



1418
1419
1420
# File 'lib/setfu.rb', line 1418

def add_primes!(n=100)
  self.add!(Prime.take(n))
end

#add_uppercase_charsObject



503
504
505
# File 'lib/setfu.rb', line 503

def add_uppercase_chars
  return BitSet.uppercase_chars | self
end

#add_uppercase_chars!Object



498
499
500
501
# File 'lib/setfu.rb', line 498

def add_uppercase_chars!
  add! BitSet.uppercase_chars
  self
end

#add_uppercase_utfObject



1676
1677
1678
# File 'lib/setfu.rb', line 1676

def add_uppercase_utf
  return BitSet.uppercase_utf_chars | self
end

#add_uppercase_utf!Object



1680
1681
1682
1683
# File 'lib/setfu.rb', line 1680

def add_uppercase_utf!
  add! BitSet.uppercase_utf_chars
  self
end

#coerce(other) ⇒ Object

this only works on integer … String, Array, Range does not implement: &, |, ^



656
657
658
659
# File 'lib/setfu.rb', line 656

def coerce(other)
  #puts "TESTING ... coerce called!"
  return [self, other]   # does not seem to get called ...
end

#countObject



916
917
918
919
920
921
922
# File 'lib/setfu.rb', line 916

def count
  cnt = 0
  each_member do |toss|
    cnt += 1
  end 
  cnt    
end

#dec(n = 1) ⇒ Object



625
626
627
# File 'lib/setfu.rb', line 625

def dec(n=1)
  return dup.dec!(n)
end

#dec!(n = 1) ⇒ Object



615
616
617
618
619
# File 'lib/setfu.rb', line 615

def dec!(n=1)
  raise "illegal negative parameter in #inc" if n < 0
  @bits >>= n
  self
end

#doubleObject



170
171
172
# File 'lib/setfu.rb', line 170

def double
  dup.double!
end

#double!Object



165
166
167
168
169
# File 'lib/setfu.rb', line 165

def double!
  @bits |= @bits << @entropy
  @entropy <<= 1
  self    
end

#dupObject



661
662
663
664
665
# File 'lib/setfu.rb', line 661

def dup
  rtn = BitSet.new
  rtn.replace(self)
  return rtn
end

#each(*prms) ⇒ Object Also known as: each_member



879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
# File 'lib/setfu.rb', line 879

def each(*prms)
  return Enumerator.enumerate_yields(self, :each, *prms) unless block_given?
  bits = @bits
  pos = 0
  stop = nil
  chr_mode = false
  prms.each do |prm|
    if prm.respond_to? :first
      a = prm.first.ord
      b = prm.last.ord
      a,b = b,a if a>b
      pos = a
      bits >>= pos
      stop = b
    else
      chr_mode = !prm
    end
  end
  while bits > 0
    if ((bits & 1) == 1)
      yield chr_mode ? pos.chr(Encoding::UTF_8) : pos
    end
    pos += 1
    unless stop.nil?
      break if pos > stop
    end
    bits >>= 1
  end  
  self
end

#empty?Boolean

Returns:

  • (Boolean)


823
824
825
# File 'lib/setfu.rb', line 823

def empty?
  @bits == 0
end

#entropy_2n!Object

set entropy to the next greater power of 2**n



1308
1309
1310
# File 'lib/setfu.rb', line 1308

def entropy_2n!   # set entropy to the next greater power of 2**n
  @entropy = 1 << @bits.bit_length.bit_length
end

#eql?(item) ⇒ Boolean

Returns:

  • (Boolean)


744
745
746
# File 'lib/setfu.rb', line 744

def eql?(item)
  self.==(item)
end

#evenObject



1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
# File 'lib/setfu.rb', line 1354

def even
  t = @@even_bits
  s = @@shifts
  while @bits > t
    t |= t << s
    s <<= 1
  end
  rtn = self.dup
  rtn.set_bits!(t & @bits)
  return rtn
end

#even!Object



1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
# File 'lib/setfu.rb', line 1379

def even!
  t1 = @@odd_bits
  t2 = @@even_bits
  s = @@shifts
  while @bits > t2
    t1 |= t1 << s
    t2 |= t2 << s
    s <<= 1
  end
  rtn = self.dup
  rtn.set_bits!(t1 & @bits)
  self.set_bits!(t2 & @bits)
  return rtn
end

#even?Boolean

Returns:

  • (Boolean)


1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
# File 'lib/setfu.rb', line 1404

def even?
  return false if empty?
  t = @@even_bits
  s = @@shifts
  while @bits > t
    t |= t << s
    s <<= 1
  end
  tst = t & @bits
  return tst == @bits
end

#first(p = true) ⇒ Object Also known as: min



1314
1315
1316
1317
# File 'lib/setfu.rb', line 1314

def first(p=true)
  rtn = @bits.lsb_bit_position
  return p ? rtn : rtn.chr(Encoding::UTF_8)
end

#first!(p = true) ⇒ Object



1322
1323
1324
1325
1326
# File 'lib/setfu.rb', line 1322

def first!(p=true)
  rtn = @bits.lsb_bit_position
  replace(self ^ [rtn]) unless rtn.nil?
  return p ? rtn : rtn.chr(Encoding::UTF_8)
end

#inc(n = 1) ⇒ Object



621
622
623
# File 'lib/setfu.rb', line 621

def inc(n=1)
  return dup.inc!(n)
end

#inc!(n = 1) ⇒ Object



608
609
610
611
612
613
# File 'lib/setfu.rb', line 608

def inc!(n=1)
  raise "illegal negative parameter in #inc" if n < 0
  @entropy += n
  @bits <<= n
  self
end

#include?(items) ⇒ Boolean

Returns:

  • (Boolean)


827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
# File 'lib/setfu.rb', line 827

def include?(items)
  return false if items.nil?   # sets never include nil
  return false if @bits == 0   # empty sets include nothing including other empty sets
  if(items.type_of? BitSet)
    tmp = @bits & items.to_i
    return false if tmp==0
    return (tmp) == items.to_i
  elsif(items.type_of? Range)
    ran = items.reorder.simplify
    return(include?(ran.to_a)) unless ran.simple?
    f=ran.first.ord
    l=ran.last.ord
    # f,l = l,f if f>l
    t = (l-f)+1
    t = (1 << t)-1
    t = t << f
    return (@bits & t) == t
  elsif(items.respond_to? :each_char)
    return false if items.empty?
    items.each_char do |item|
      t = 1 << item.ord
      return false if 0 == (t & @bits)
    end
  elsif(items.respond_to? :each)
    return false if items.empty?
    items.each do |item|
      return false if false==include?(item)
    end
  else #assume number
    t = 1 << items.abs
    return false if 0 == (t & @bits)
  end
  return true
end

#last(p = true) ⇒ Object Also known as: max



1318
1319
1320
1321
# File 'lib/setfu.rb', line 1318

def last(p=true)
  rtn = @bits.msb_bit_position
  return p ? rtn : rtn.chr(Encoding::UTF_8)
end

#last!(p = true) ⇒ Object



1327
1328
1329
1330
1331
# File 'lib/setfu.rb', line 1327

def last!(p=true)
  rtn =  @bits.msb_bit_position
  replace(self ^ [rtn]) unless rtn.nil?
  return p ? rtn : rtn.chr(Encoding::UTF_8)
end

#max_runObject

max_run << returns maximum number of consecutive numbers



560
561
562
563
564
565
566
567
568
569
570
571
# File 'lib/setfu.rb', line 560

def max_run # max_run << returns maximum number of consecutive numbers
  return 0 if @bits==0
  mx = 1
  bits = @bits
  loop do
    bits <<= 1
    bits &= @bits
    break if 0 == bits
    mx += 1
  end
  return mx
end

#modeObject



587
588
589
# File 'lib/setfu.rb', line 587

def mode
  return @mode
end

#neighbor(nvars, dir) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/setfu.rb', line 95

def neighbor(nvars, dir)
  raise "too many neighbors for #{nvars} variables" if dir >= nvars
  raise "dir must be positive" if dir.negative?
  rtn = dup

  if 1==nvars      # two squares
    rtn[dir]=!self[dir]
  elsif 2==nvars   # a 2x2 box
    if 0==dir
      rtn[0]=!self[0]
    else
      rtn[1]=!self[1]
    end
  end
  # now programmatically do the remaining pattern
  if nvars.even?
    if dir.even?   # up if dir==0 and nvars==4  ... left if dir==2 and nvars==4
      rtn[dir]=self[dir+1]
      rtn[dir+1]=!self[dir]
    else          # down if dir ==1 and nvars==4 ... right if dir==3 and nvars==4
      rtn[dir-1]=!self[dir]  # modified on dec 21, 2019  9:34AM
      rtn[dir]=self[dir-1]
    end
  else # odd    .......... compare with neighbor5    dir [0,1,2,3,4]
    if dir==(nvars-1)   # dir==4
      rtn[dir]=!self[dir]
    elsif dir.even?          # 0,2 validated
      rtn[dir]=self[dir+1]
      rtn[dir+1]=!self[dir]
    else                     # 1,3 validated
      rtn[dir-1]=!self[dir]
      rtn[dir]=self[dir-1]
    end
  end
  return rtn
end

#oddObject



1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
# File 'lib/setfu.rb', line 1343

def odd
  t = @@odd_bits
  s = @@shifts
  while @bits > t
    t |= t << s
    s <<= 1
  end
  rtn = self.dup
  rtn.set_bits!(t & @bits)
  return rtn
end

#odd!Object



1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
# File 'lib/setfu.rb', line 1365

def odd!
  t1 = @@odd_bits
  t2 = @@even_bits
  s = @@shifts
  while @bits > t2
    t1 |= t1 << s
    t2 |= t2 << s
    s <<= 1
  end
  rtn = self.dup
  rtn.set_bits!(t2 & @bits)
  self.set_bits!(t1 & @bits)
  return rtn
end

#odd?Boolean

Returns:

  • (Boolean)


1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
# File 'lib/setfu.rb', line 1393

def odd?
  return false if empty?
  t = @@odd_bits
  s = @@shifts
  while @bits > t
    t |= t << s
    s <<= 1
  end
  tst = t & @bits
  return tst == @bits
end

#rand(elm_count, format = :bset) ⇒ Object

:array :array_chars :string :set



1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
# File 'lib/setfu.rb', line 1024

def rand(elm_count, format = :bset)
  ary = self.to_a
  ary.shuffle!
  ary = ary[0..(elm_count-1)]
  case format
    when :array
      return ary
    when :array_chars
      rtn = []
      ary.each do |elm|
        rtn.push elm.chr(Encoding::UTF_8)
      end
      return rtn
    when :string
      rtn = []
      ary.each do |elm|
        rtn.push elm.chr(Encoding::UTF_8)
      end
      return rtn.join ""
    else # :bset
      return ary.to_bset
  end
end

#rand!(elm_count, format = :bset) ⇒ Object



1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
# File 'lib/setfu.rb', line 1048

def rand!(elm_count, format = :bset)
  ary = self.to_a
  rna = ary.shuffle[0..(elm_count-1)]
  replace rna.to_bset
  case format
    when :array
      return (ary - rna).shuffle
    when :array_chars
      src = (ary - rna).shuffle
      rtn = []
      src.each do |elm|
        rtn.push elm.chr(Encoding::UTF_8)
      end
      return rtn
    when :string
      src = (ary - rna).shuffle
      rtn = []
      src.each do |elm|
        rtn.push elm.chr(Encoding::UTF_8)
      end
      return rtn.join ""
    else # :bset
      return (ary - rna).to_bset
  end
end

#recalculate_entropy!Object



629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
# File 'lib/setfu.rb', line 629

def recalculate_entropy!
  @entropy = 0
  bits = @bits
  num = 1 << 8192
  while(bits > num)
    @entropy += 8192
    bits >>= 8192
  end
  num = 1 << 256
  while(bits > num)
    @entropy += 256
    bits >>= 256
  end
  num = 1 << 16
  while(bits > num)
    @entropy += 16
    bits >>= 16
  end
  while(bits > 0)
    @entropy += 1
    bits >>= 1
  end
  #@entropy += 1
  @entropy
end

#replace(ent) ⇒ Object



471
472
473
474
475
476
477
# File 'lib/setfu.rb', line 471

def replace(ent)
  ent = ent.to_bset
  @mode = ent.mode
  @entropy = ent.entropy
  @bits = ent.to_i
  self  
end

#reverse_each(*prms) ⇒ Object

do a benchmark and see which is faster, reverse_each or each



862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
# File 'lib/setfu.rb', line 862

def reverse_each(*prms)  # do a benchmark and see which is faster, reverse_each or each
  return Enumerator.enumerate_yields(self, :reverse_each, *prms) unless block_given?
  int_mode = true
  set = self.dup
  prms.each do |prm|
    if prm.respond_to? :first
      set &= prm
    else
      int_mode = prm  
    end
  end
  ary = set.to_a(int_mode)
  while !ary.empty?
    yield ary.pop
  end
end

#runsObject

01100010011111111100010101001101 … test

01100010011111111100010101001101    ... left shift
001000000011111111000000000001000   ... and with left shift

 01100010011111111100010101001101   ... test
 00110001001111111110001010100110    ... right shift
 00100000001111111100000000000100    ... and with right shift

001000000011111111000000000001000   ... AND with left shift
 00100000001111111100000000000100    ... AND with right shift
001100000011111111100000000001100    ... OR the two ands
 01100010011111111100010101001101   ... test original
 01100000011111111100000000001100   ... BINGO ... original with the OR  gives us the runs only
 00000010000000000000010101000001   ... BINGO ... original XOR with OR gives us the singles!


540
541
542
543
544
545
546
547
548
# File 'lib/setfu.rb', line 540

def runs # runs    << creates a set of touching elements
  an_l = (@bits << 1) & @bits
  an_r = (@bits >> 1) & @bits
  or_lr = an_l | an_r
  rtn = BitSet.new
  rtn.set_bits!(or_lr & @bits)
  rtn.entropy=self.entropy
  return rtn
end

#runs?(cnt = 2) ⇒ Boolean

Returns:

  • (Boolean)


573
574
575
576
577
578
579
580
581
# File 'lib/setfu.rb', line 573

def runs?(cnt=2)
  bits = @bits
  (cnt-1).times do
    bits <<= 1
    bits &= @bits
    return false if 0 == bits
  end
  return true
end

#set_all!Object

set all possible bits … make sure this does not already exist … if it does, then use the proper name



190
191
192
193
# File 'lib/setfu.rb', line 190

def set_all!  # set all possible bits   ... make sure this does not already exist ... if it does, then use the proper name
  bits = (2 ** entropy) - 1
  set_bits! bits
end

#set_bits!(bits) ⇒ Object



977
978
979
980
# File 'lib/setfu.rb', line 977

def set_bits!(bits)
  raise "negative numbers are not allowed" if bits.to_i < 0
  @bits = bits.to_i
end

#set_case(mode = :mode_equal) ⇒ Object



748
749
750
751
# File 'lib/setfu.rb', line 748

def set_case(mode=:mode_equal)
  @mode = mode
  self
end

#singlesObject

singles << creates a set of non-touching elements



550
551
552
553
554
555
556
557
558
# File 'lib/setfu.rb', line 550

def singles # singles << creates a set of non-touching elements 
  an_l = (@bits << 1) & @bits
  an_r = (@bits >> 1) & @bits
  or_lr = an_l | an_r
  rtn = BitSet.new
  rtn.set_bits!(or_lr ^ @bits)
  rtn.entropy=self.entropy
  return rtn
end

#sizeObject



604
605
606
# File 'lib/setfu.rb', line 604

def size
  count
end

#splitObject



1540
1541
1542
1543
1544
1545
1546
1547
# File 'lib/setfu.rb', line 1540

def split
  ary = self.to_a
  len = ary.length
  lh = len >> 1
  a = ary[0..(lh-1)].to_bset
  b = ary[lh..len].to_bset
  return [a,b]
end

#split!Object



1548
1549
1550
1551
1552
1553
# File 'lib/setfu.rb', line 1548

def split!
  both = self.split
  rtn = both.last
  self.replace both.first
  return rtn
end

#swap(pos1, pos2) ⇒ Object



83
84
85
86
87
# File 'lib/setfu.rb', line 83

def swap(pos1,pos2)
  bs = dup
  bs[pos1],bs[pos2] = self[pos2], self[pos1]
  bs
end

#swap!(pos1, pos2) ⇒ Object



79
80
81
82
# File 'lib/setfu.rb', line 79

def swap!(pos1,pos2)
  self[pos1],self[pos2] = self[pos2], self[pos1]
  self
end

#to_a(int = true) ⇒ Object



932
933
934
935
936
937
938
# File 'lib/setfu.rb', line 932

def to_a(int = true)
  rtn = []
  each_member do |num|
    rtn.push int ? num : num.chr(Encoding::UTF_8)
  end
  rtn
end

#to_bsetObject



583
584
585
# File 'lib/setfu.rb', line 583

def to_bset
  return self
end

#to_iObject



912
913
914
# File 'lib/setfu.rb', line 912

def to_i
  return @bits
end

#to_ra(int = true, th = 3) ⇒ Object



940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
# File 'lib/setfu.rb', line 940

def to_ra(int=true, th=3)
  raise "Threshold too low" unless th >= 2
  rtn = []
  cnt = 0
  last  = -100
  flag  = false
  th -= 1
  each_member do |num|
    # byebug unless int
    rtn.push int ? num : num.chr(Encoding::UTF_8)
    if ((last+1)==num)
      # byebug if cnt.nil?
      cnt += 1
      flag = cnt >= th
    elsif flag
      save = rtn.pop
      tmp = rtn.pop(cnt+1)
      range = (tmp.first)..(tmp.last)
      rtn.push range
      rtn.push save
      cnt = 0
      last = -100
      flag = false
    else
      cnt = 0  
    end
    last = num
  end
  #byebug
  if flag # convert final range
    tmp = rtn.pop(cnt+1)
    range = (tmp.first)..(tmp.last)
    rtn.push range
  end
  rtn
end

#to_sObject



924
925
926
927
928
929
930
# File 'lib/setfu.rb', line 924

def to_s
  rtn = ""
  each_member do |ch|
    rtn += ch.chr(Encoding::UTF_8)
  end
  rtn
end

#untagObject



365
366
367
# File 'lib/setfu.rb', line 365

def untag
  BitSet.new | self
end

#untag!Object



368
369
370
371
# File 'lib/setfu.rb', line 368

def untag!
  remove_instance_variable :@bo_setfu_tag rescue :never_mind
  remove_instance_variable :@bo_setfu_count rescue :never_mind
end

#zap!Object



598
599
600
601
602
# File 'lib/setfu.rb', line 598

def zap!
  @bits = 0
  @entropy = 0
  self
end

#|(item) ⇒ Object



678
679
680
681
682
683
684
685
686
687
688
# File 'lib/setfu.rb', line 678

def |(item)
  rtn = self.dup
  if(item.type_of? BitSet)
    rtn.set_bits!(rtn.to_i | item.to_i)
    self.entropy=item.entropy
  else
    rtn = BitSet.new(item)
    rtn.set_bits!(@bits | rtn.to_i)
  end
  rtn
end

#~@Object



982
983
984
985
986
987
# File 'lib/setfu.rb', line 982

def ~@()
  rtn = dup
  mask = (1 << @entropy) - 1
  rtn.set_bits!(mask ^ @bits)
  rtn
end