@@ -108,11 +108,15 @@ class IMAP
108108    # When a set includes <tt>*</tt>, some methods may have surprising behavior. 
109109    # 
110110    # For example, #complement treats <tt>*</tt> as its own number.  This way, 
111-     # the #intersection of a set and its #complement will always be empty. 
112-     # This is not how an \IMAP server interprets the set: it will convert 
113-     # <tt>*</tt> to either the number of messages in the mailbox or +UIDNEXT+, 
114-     # as appropriate.  And there _will_ be overlap between a set and its 
115-     # complement after #limit is applied to each: 
111+     # the #intersection of a set and its #complement will always be empty.  And 
112+     # <tt>*</tt> is sorted as greater than any other number in the set.  This is 
113+     # not how an \IMAP server interprets the set: it will convert <tt>*</tt> to 
114+     # the number of messages in the mailbox, the +UID+ of the last message in 
115+     # the mailbox, or +UIDNEXT+, as appropriate.  Several methods have an 
116+     # argument for how <tt>*</tt> should be interpreted. 
117+     # 
118+     # But, for example, this means that there may be overlap between a set and 
119+     # its complement after #limit is applied to each: 
116120    # 
117121    #   ~Net::IMAP::SequenceSet["*"]  == Net::IMAP::SequenceSet[1..(2**32-1)] 
118122    #   ~Net::IMAP::SequenceSet[1..5] == Net::IMAP::SequenceSet["6:*"] 
@@ -179,9 +183,9 @@ class IMAP
179183    # - #include_star?: Returns whether the set contains <tt>*</tt>. 
180184    # 
181185    # <i>Minimum and maximum value elements:</i> 
182-     # - #min: Returns one or more minimum  numbers in the set. 
183-     # - #max: Returns one or more maximum  numbers in the set. 
184-     # - #minmax: Returns the minimum  and maximum  numbers in the set. 
186+     # - #min: Returns one or more of the lowest  numbers in the set. 
187+     # - #max: Returns one or more of the highest  numbers in the set. 
188+     # - #minmax: Returns the lowest  and highest  numbers in the set. 
185189    # 
186190    # <i>Accessing value by offset in sorted set:</i> 
187191    # - #[] (aliased as #slice): Returns the number or consecutive subset at a 
@@ -643,7 +647,14 @@ def full?; @tuples == [[1, STAR_INT]] end
643647      #     Net::IMAP::SequenceSet["1:5"] | 2 | [4..6, 99] 
644648      #     #=> Net::IMAP::SequenceSet["1:6,99"] 
645649      # 
646-       # Related: #add, #merge 
650+       # Related: #add, #merge, #&, #-, #^, #~ 
651+       # 
652+       # ==== Set identities 
653+       # 
654+       # <tt>lhs | rhs</tt> is equivalent to: 
655+       # * <tt>rhs | lhs</tt> (commutative) 
656+       # * <tt>~(~lhs & ~rhs)</tt> (De Morgan's Law) 
657+       # * <tt>(lhs & rhs) ^ (lhs ^ rhs)</tt> 
647658      def  |( other )  remain_frozen  dup . merge  other  end 
648659      alias  :+     :| 
649660      alias  union  :| 
@@ -662,7 +673,17 @@ def |(other) remain_frozen dup.merge other end
662673      #     Net::IMAP::SequenceSet[1..5] - 2 - 4 - 6 
663674      #     #=> Net::IMAP::SequenceSet["1,3,5"] 
664675      # 
665-       # Related: #subtract 
676+       # Related: #subtract, #|, #&, #^, #~ 
677+       # 
678+       # ==== Set identities 
679+       # 
680+       # <tt>lhs - rhs</tt> is equivalent to: 
681+       # * <tt>~r - ~l</tt> 
682+       # * <tt>lhs & ~rhs</tt> 
683+       # * <tt>~(~lhs | rhs)</tt> 
684+       # * <tt>lhs & (lhs ^ rhs)</tt> 
685+       # * <tt>lhs ^ (lhs & rhs)</tt> 
686+       # * <tt>rhs ^ (lhs | rhs)</tt> 
666687      def  -( other )  remain_frozen  dup . subtract  other  end 
667688      alias  difference  :- 
668689
@@ -680,7 +701,17 @@ def -(other) remain_frozen dup.subtract other end
680701      #     Net::IMAP::SequenceSet[1..5] & [2, 4, 6] 
681702      #     #=> Net::IMAP::SequenceSet["2,4"] 
682703      # 
683-       # <tt>(seqset & other)</tt> is equivalent to <tt>(seqset - ~other)</tt>. 
704+       # Related: #intersect?, #|, #-, #^, #~ 
705+       # 
706+       # ==== Set identities 
707+       # 
708+       # <tt>lhs & rhs</tt> is equivalent to: 
709+       # * <tt>rhs & lhs</tt> (commutative) 
710+       # * <tt>~(~lhs | ~rhs)</tt> (De Morgan's Law) 
711+       # * <tt>lhs - ~rhs</tt> 
712+       # * <tt>lhs - (lhs - rhs)</tt> 
713+       # * <tt>lhs - (lhs ^ rhs)</tt> 
714+       # * <tt>lhs ^ (lhs - rhs)</tt> 
684715      def  &( other ) 
685716        remain_frozen  dup . subtract  SequenceSet . new ( other ) . complement! 
686717      end 
@@ -700,8 +731,16 @@ def &(other)
700731      #     Net::IMAP::SequenceSet[1..5] ^ [2, 4, 6] 
701732      #     #=> Net::IMAP::SequenceSet["1,3,5:6"] 
702733      # 
703-       # <tt>(seqset ^ other)</tt> is equivalent to <tt>((seqset | other) - 
704-       # (seqset & other))</tt>. 
734+       # Related: #|, #&, #-, #~ 
735+       # 
736+       # ==== Set identities 
737+       # 
738+       # <tt>lhs ^ rhs</tt> is equivalent to: 
739+       # * <tt>rhs ^ lhs</tt> (commutative) 
740+       # * <tt>~lhs ^ ~rhs</tt> 
741+       # * <tt>(lhs | rhs) - (lhs & rhs)</tt> 
742+       # * <tt>(lhs - rhs) | (rhs - lhs)</tt> 
743+       # * <tt>(lhs ^ other) ^ (other ^ rhs)</tt> 
705744      def  ^( other )  remain_frozen  ( dup  | other ) . subtract ( self  & other )  end 
706745      alias  xor  :^ 
707746
@@ -719,7 +758,12 @@ def ^(other) remain_frozen (dup | other).subtract(self & other) end
719758      #     ~Net::IMAP::SequenceSet["6:99,223:*"] 
720759      #     #=> Net::IMAP::SequenceSet["1:5,100:222"] 
721760      # 
722-       # Related: #complement! 
761+       # Related: #complement!, #|, #&, #-, #^ 
762+       # 
763+       # ==== Set identities 
764+       # 
765+       # <tt>~set</tt> is equivalent to: 
766+       # * <tt>full - set</tt>, where "full" is Net::IMAP::SequenceSet.full 
723767      def  ~;  remain_frozen  dup . complement!  end 
724768      alias  complement  :~ 
725769
@@ -731,7 +775,10 @@ def ~; remain_frozen dup.complement! end
731775      # 
732776      # #string will be regenerated.  Use #merge to add many elements at once. 
733777      # 
734-       # Related: #add?, #merge, #union 
778+       # Use #append to append new elements to #string.  See 
779+       # Net::IMAP@Ordered+and+Normalized+Sets. 
780+       # 
781+       # Related: #add?, #merge, #union, #append 
735782      def  add ( element ) 
736783        tuple_add  input_to_tuple  element 
737784        normalize! 
@@ -742,6 +789,10 @@ def add(element)
742789      # 
743790      # Unlike #add, #merge, or #union, the new value is appended to #string. 
744791      # This may result in a #string which has duplicates or is out-of-order. 
792+       # 
793+       # See Net::IMAP@Ordered+and+Normalized+Sets. 
794+       # 
795+       # Related: #add, #merge, #union 
745796      def  append ( entry ) 
746797        modifying! 
747798        tuple  =  input_to_tuple  entry 
@@ -890,21 +941,21 @@ def subtract(*sets)
890941      # This is useful when the given order is significant, for example in a 
891942      # ESEARCH response to IMAP#sort. 
892943      # 
944+       # See Net::IMAP@Ordered+and+Normalized+Sets. 
945+       # 
893946      # Related: #each_entry, #elements 
894947      def  entries ;  each_entry . to_a  end 
895948
896949      # Returns an array of ranges and integers and <tt>:*</tt>. 
897950      # 
898951      # The returned elements are sorted and coalesced, even when the input 
899-       # #string is not.  <tt>*</tt> will sort last.  See #normalize. 
952+       # #string is not.  <tt>*</tt> will sort last.  See #normalize, 
953+       # Net::IMAP@Ordered+and+Normalized+Sets. 
900954      # 
901955      # By itself, <tt>*</tt> translates to <tt>:*</tt>.  A range containing 
902956      # <tt>*</tt> translates to an endless range.  Use #limit to translate both 
903957      # cases to a maximum value. 
904958      # 
905-       # The returned elements will be sorted and coalesced, even when the input 
906-       # #string is not.  <tt>*</tt> will sort last.  See #normalize. 
907-       # 
908959      #   Net::IMAP::SequenceSet["2,5:9,6,*,12:11"].elements 
909960      #   #=> [2, 5..9, 11..12, :*] 
910961      # 
@@ -915,15 +966,13 @@ def elements; each_element.to_a end
915966      # Returns an array of ranges 
916967      # 
917968      # The returned elements are sorted and coalesced, even when the input 
918-       # #string is not.  <tt>*</tt> will sort last.  See #normalize. 
969+       # #string is not.  <tt>*</tt> will sort last.  See #normalize, 
970+       # Net::IMAP@Ordered+and+Normalized+Sets. 
919971      # 
920972      # <tt>*</tt> translates to an endless range.  By itself, <tt>*</tt> 
921973      # translates to <tt>:*..</tt>.  Use #limit to set <tt>*</tt> to a maximum 
922974      # value. 
923975      # 
924-       # The returned ranges will be sorted and coalesced, even when the input 
925-       # #string is not.  <tt>*</tt> will sort last.  See #normalize. 
926-       # 
927976      #   Net::IMAP::SequenceSet["2,5:9,6,*,12:11"].ranges 
928977      #   #=> [2..2, 5..9, 11..12, :*..] 
929978      #   Net::IMAP::SequenceSet["123,999:*,456:789"].ranges 
@@ -935,7 +984,7 @@ def ranges; each_range.to_a end
935984      # Returns a sorted array of all of the number values in the sequence set. 
936985      # 
937986      # The returned numbers are sorted and de-duplicated, even when the input 
938-       # #string is not.  See #normalize. 
987+       # #string is not.  See #normalize, Net::IMAP@Ordered+and+Normalized+Sets . 
939988      # 
940989      #   Net::IMAP::SequenceSet["2,5:9,6,12:11"].numbers 
941990      #   #=> [2, 5, 6, 7, 8, 9, 11, 12] 
@@ -967,6 +1016,8 @@ def numbers; each_number.to_a end
9671016      # no sorting, deduplication, or coalescing.  When #string is in its 
9681017      # normalized form, this will yield the same values as #each_element. 
9691018      # 
1019+       # See Net::IMAP@Ordered+and+Normalized+Sets. 
1020+       # 
9701021      # Related: #entries, #each_element 
9711022      def  each_entry ( &block )  # :yields: integer or range or :* 
9721023        return  to_enum ( __method__ )  unless  block_given? 
@@ -977,7 +1028,7 @@ def each_entry(&block) # :yields: integer or range or :*
9771028      # and returns self.  Returns an enumerator when called without a block. 
9781029      # 
9791030      # The returned numbers are sorted and de-duplicated, even when the input 
980-       # #string is not.  See #normalize. 
1031+       # #string is not.  See #normalize, Net::IMAP@Ordered+and+Normalized+Sets . 
9811032      # 
9821033      # Related: #elements, #each_entry 
9831034      def  each_element  # :yields: integer or range or :* 
@@ -1400,6 +1451,7 @@ def complement!
14001451      # 
14011452      # The returned set's #string is sorted and deduplicated.  Adjacent or 
14021453      # overlapping elements will be merged into a single larger range. 
1454+       # See Net::IMAP@Ordered+and+Normalized+Sets. 
14031455      # 
14041456      #   Net::IMAP::SequenceSet["1:5,3:7,10:9,10:11"].normalize 
14051457      #   #=> Net::IMAP::SequenceSet["1:7,9:11"] 
@@ -1412,7 +1464,7 @@ def normalize
14121464      end 
14131465
14141466      # Resets #string to be sorted, deduplicated, and coalesced.  Returns 
1415-       # +self+. 
1467+       # +self+.  See Net::IMAP@Ordered+and+Normalized+Sets.  
14161468      # 
14171469      # Related: #normalize, #normalized_string 
14181470      def  normalize! 
@@ -1422,11 +1474,13 @@ def normalize!
14221474
14231475      # Returns a normalized +sequence-set+ string representation, sorted 
14241476      # and deduplicated.  Adjacent or overlapping elements will be merged into 
1425-       # a single larger range.  Returns +nil+ when the set is empty . 
1477+       # a single larger range.  See Net::IMAP@Ordered+and+Normalized+Sets . 
14261478      # 
14271479      #   Net::IMAP::SequenceSet["1:5,3:7,10:9,10:11"].normalized_string 
14281480      #   #=> "1:7,9:11" 
14291481      # 
1482+       # Returns +nil+ when the set is empty. 
1483+       # 
14301484      # Related: #normalize!, #normalize 
14311485      def  normalized_string 
14321486        @tuples . empty?  ? nil  : -@tuples . map  {  tuple_to_str  _1  } . join ( "," ) 
0 commit comments