[#44776] [ruby-trunk - Bug #6385][Open] mtime vie File.stat(filename).utime vs File.open(filename, 'r').mtime in Windows — "kolmanv (Kolman Vornovitsky)" <kolmanv@...>

9 messages 2012/05/01

[#44782] [ruby-trunk - Bug #6387][Open] 1.9.3p194 crashed on require in ubuntu — "ywen (Yi Wen)" <hayafirst@...>

12 messages 2012/05/01

[#44795] [ruby-trunk - Bug #6391][Open] Segment Fault while execute make_encmake.rb for Ruby 1.9.3 P194 ( MinGW64) — "raylinn@... (ray linn)" <raylinn@...>

13 messages 2012/05/02

[#44911] [ruby-trunk - Bug #6408][Open] DelegateClass#eql? and <=> don't work as expected — "tenderlovemaking (Aaron Patterson)" <aaron@...>

11 messages 2012/05/06

[#44951] [ruby-trunk - Feature #6414][Open] Destructuring Assignment — "edtsech (Edward Tsech)" <edtsech@...>

14 messages 2012/05/08

[#44958] [ruby-trunk - Feature #6418][Assigned] Supporing a subset of ANSI escape code on Windows — "usa (Usaku NAKAMURA)" <usa@...>

11 messages 2012/05/09

[#45035] [ruby-trunk - Bug #6433][Open] rb_thread_blocking_region(): ubf() function is executed with GVL — ibc (Iñaki Baz Castillo) <ibc@...>

12 messages 2012/05/14

[#45180] [ruby-trunk - Feature #6478][Open] BasicObject#__class__ — "trans (Thomas Sawyer)" <transfire@...>

14 messages 2012/05/22

[#45193] [ruby-trunk - Feature #6482][Open] Add URI requested to Net::HTTP request and response objects — "drbrain (Eric Hodel)" <[email protected]>

16 messages 2012/05/23

[#45198] [ruby-trunk - Feature #6483][Open] parametric map — "prijutme4ty (Ilya Vorontsov)" <prijutme4ty@...>

14 messages 2012/05/23

[#45222] [ruby-trunk - Feature #6492][Open] Inflate all HTTP Content-Encoding: deflate, gzip, x-gzip responses by default — "drbrain (Eric Hodel)" <[email protected]>

23 messages 2012/05/24

[#45252] [ruby-trunk - Feature #6499][Open] Array::zip — "prijutme4ty (Ilya Vorontsov)" <prijutme4ty@...>

14 messages 2012/05/26

[#45272] [ruby-trunk - Feature #6503][Open] Support for the NPN extension to TLS/SSL — "igrigorik (Ilya Grigorik)" <ilya@...>

13 messages 2012/05/27

[#45316] [ruby-trunk - Feature #6515][Open] array.c: added method that verifies if an Array is part of another — "lellisga (Li Ellis Galardo)" <lellisga@...>

14 messages 2012/05/30

[ruby-core:44858] [ruby-trunk - Feature #6361] Bitwise string operations

From: "kernigh (George Koehler)" <xkernigh@...>
Date: 2012-05-03 21:04:42 UTC
List: ruby-core #44858
Issue #6361 has been updated by kernigh (George Koehler).


=begin
A new BinaryString (or Blob) class would entail several changes. For example, Array#pack and IO#read(n) would need to return BinaryString, not String. I prefer to keep String for binary strings.

The main reason, to perform bitwise operations on a String, is to use this String as an array of bits. The purpose of each bitwise operation is to clear or set some bits in this array. For example, a sieve of Erathosthenes might clear a bit in a String to show that a number is not prime.

String has no bitwise operations. So, the code to clear a bit is long, not simple.

 sieve = "\xAC(\x8A\xA2("
 # 25 is not prime. Clear bit 0x02 of byte 3.
 sieve.setbyte(3, sieve.getbyte(3) & ~0x02)

A simpler way, with current Ruby, is to unpack this String into an Array of Integers. The code can then perform bitwise operations with these Integers.

 sieve = "\xAC(\x8A\xA2(".unpack("C*")
 # 25 is not prime. Clear bit 0x02 of byte 3.
 sieve[3] &= ~0x02

The sieve in [1] uses an Array of 16-bit Fixnums. This works because Fixnum has bitwise operations. A sieve at [2] uses an Array of true and false. This also works, though it uses more memory.

[1] https://github.com/ruby/ruby/blob/trunk/lib/prime.rb
[2] http://rosettacode.org/wiki/Sieve_of_Eratosthenes#Ruby

If String would have bitwise operations, a sieve of Eratosthenes might use them. If String#& and String#~ would exist, then they can clear a bit.

 sieve = "\xAC(\x8A\xA2("
 sieve[3] &= ~"\x02"

With this design, String#& and String#~ never modify the original string. This design forgot that Strings are mutable. String#& must allocate a new string, before String#[]= modifies the original string. A better design might provide destructive methods that use bitwise operations to modify a slice of the original string.
=end

----------------------------------------
Feature #6361: Bitwise string operations
https://bugs.ruby-lang.org/issues/6361#change-26433

Author: MartinBosslet (Martin Bosslet)
Status: Feedback
Priority: Normal
Assignee: 
Category: core
Target version: 


I know this has been discussed a lot in the past (and if there's still 
an open issue for this, I apologize, I couldn't find one), for example
in [1]. While it is generally no problem to implement this on the fly,
I still find that built-in support would be a real improvement. There
are quite some use cases in cryptography where this would come in very
handy, but I'm sure there are lots of other areas, too.

While of course I understand the reasons that were given in the previous
threads that ultimately lead to rejection, I still would like to reopen
the discussion as I felt that in every thread so far the consensus was
that having bitwise string operations would indeed be quite valuable. 

[1] http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/34586


-- 
http://bugs.ruby-lang.org/

In This Thread