www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Bit type?

reply Dan <murpsoft hotmail.com> writes:
I thought I recalled D having a "bit[]" type with the restriction that you
could only use bit[n*8]?

I'm asking because I've been developing an interest in DNA.  I had thought it
would be an amazing project to produce an open source DNA format.  Raw DNA uses
two bits, but you could probably need another 2 per base pair for expression. 
From there, you have raw DNA.  You want to build slices, as slices get copied
off to make siRNA and mRNA and such.  So mapping out which parts of the DNA are
used to make copies of what tends to be useful.

D just seems to fit together quite well - but I want an easy 4-bit type to work
with.

Who likes the idea?
Nov 23 2007
next sibling parent reply "Stewart Gordon" <smjg_1998 yahoo.com> writes:
"Dan" <murpsoft hotmail.com> wrote in message 
news:fi7r8q$l05$1 digitalmars.com...
 I thought I recalled D having a "bit[]" type with the restriction that you 
 could only use bit[n*8]?
There was once a bit type, but it never had such a restriction. Walter removed it, I think because it was found too complicated and bug-prone to implement. Or something like that. Meanwhile, Phobos has std.bitarray. I also have a bit array implementation capable of arbitrary slicing: http://pr.stewartsplace.org.uk/d/sutil/ <snip>
 D just seems to fit together quite well - but I want an easy 4-bit type to 
 work with.

 Who likes the idea?
4-bit type? I guess some of the bit array code could be modified to give nibble arrays, if that's what you mean.... Stewart. -- My e-mail address is valid but not my primary mailbox. Please keep replies on the 'group where everybody may benefit.
Nov 24 2007
parent BCS <ao pathlink.com> writes:
Reply to Stewart,

 "Dan" <murpsoft hotmail.com> wrote in message
 news:fi7r8q$l05$1 digitalmars.com...
 
 I thought I recalled D having a "bit[]" type with the restriction
 that you could only use bit[n*8]?
 
There was once a bit type, but it never had such a restriction. Walter removed it, I think because it was found too complicated and bug-prone to implement. Or something like that.
I think it was dropped because there was no way to get uniform slice semantics bit[100] bits; auto bits[20..25]; For that to even be doable it needs a copy that junks reference semantics, or needs to play games with pointers in ways that restrict sliced bit arrays to only 1/8th of the address space (low 3 bits of pointer are used for position in byte and byte location is got by bit shifting, but now the high order bits need to be implicit :P )
Nov 24 2007
prev sibling parent reply Dan <murpsoft hotmail.com> writes:
Stewart Gordon Wrote:
 Meanwhile, Phobos has std.bitarray.  I also have a bit array implementation 
 capable of arbitrary slicing:
 http://pr.stewartsplace.org.uk/d/sutil/
Yeah, more or less.
 4-bit type?  I guess some of the bit array code could be modified to give 
 nibble arrays, if that's what you mean....
 
 Stewart.
Yeah okay. A nibble[] then. Or I might opt to go a little smaller. See, while almost no complex operations are done on DNA, pattern-matches are done often, and trying to do that on the human genome is to pattern-match against 3 billion base-pairs (6GB if you're tight-ship, 24GB if you use char) My guess is that the process would be an exercise in DMA and cache prefetch timing. So back on subject, how does one implement a nibble[] without a nibble type? Would I be using a struct containing byte[] and overloading opIndex and such to reflect half the "nibble" index into the "byte" index? : p
Nov 24 2007
parent reply BCS <ao pathlink.com> writes:
Reply to Dan,

 Stewart Gordon Wrote:
 
 Meanwhile, Phobos has std.bitarray.  I also have a bit array
 implementation
 capable of arbitrary slicing:
 http://pr.stewartsplace.org.uk/d/sutil/
Yeah, more or less.
 4-bit type?  I guess some of the bit array code could be modified to
 give nibble arrays, if that's what you mean....
 
 Stewart.
 
Yeah okay. A nibble[] then. Or I might opt to go a little smaller. See, while almost no complex operations are done on DNA, pattern-matches are done often, and trying to do that on the human genome is to pattern-match against 3 billion base-pairs (6GB if you're tight-ship, 24GB if you use char)
your off by a factor of 8 (or swaped B and b) 3 * 1024^3 * 2 bits = 6Gb = 0.75GB 3 * 1024^3 * 8 bits = 24Gb = 3.00GB but 2.25 GB is still a lot of RAM and IO.
Nov 24 2007
parent Dan <murpsoft hotmail.com> writes:
BCS Wrote:

 Reply to Dan,
 
 Stewart Gordon Wrote:
 
 Meanwhile, Phobos has std.bitarray.  I also have a bit array
 implementation
 capable of arbitrary slicing:
 http://pr.stewartsplace.org.uk/d/sutil/
Yeah, more or less.
 4-bit type?  I guess some of the bit array code could be modified to
 give nibble arrays, if that's what you mean....
 
 Stewart.
 
Yeah okay. A nibble[] then. Or I might opt to go a little smaller. See, while almost no complex operations are done on DNA, pattern-matches are done often, and trying to do that on the human genome is to pattern-match against 3 billion base-pairs (6GB if you're tight-ship, 24GB if you use char)
your off by a factor of 8 (or swaped B and b) 3 * 1024^3 * 2 bits = 6Gb = 0.75GB 3 * 1024^3 * 8 bits = 24Gb = 3.00GB but 2.25 GB is still a lot of RAM and IO.
b : p
Nov 25 2007