Jump to page: 1 24  
Page
Thread overview
BitArray - Is there one?
May 27, 2012
Era Scarecrow
May 27, 2012
Era Scarecrow
May 27, 2012
Era Scarecrow
May 27, 2012
Era Scarecrow
May 27, 2012
bearophile
BitArray - preview of what's to come?
May 30, 2012
Era Scarecrow
May 30, 2012
Dmitry Olshansky
May 30, 2012
bearophile
May 30, 2012
Era Scarecrow
May 30, 2012
Dmitry Olshansky
May 30, 2012
Era Scarecrow
Aug 22, 2014
Suliman
Aug 22, 2014
bearophile
May 27, 2012
Chris Cain
May 27, 2012
Era Scarecrow
May 27, 2012
Era Scarecrow
May 27, 2012
Jonathan M Davis
May 28, 2012
Era Scarecrow
May 28, 2012
Dmitry Olshansky
May 29, 2012
Era Scarecrow
May 29, 2012
jerro
May 29, 2012
Dmitry Olshansky
May 29, 2012
Dmitry Olshansky
May 29, 2012
Era Scarecrow
May 29, 2012
Dmitry Olshansky
May 29, 2012
Era Scarecrow
May 29, 2012
Dmitry Olshansky
May 29, 2012
Era Scarecrow
May 29, 2012
Jonathan M Davis
May 29, 2012
Dmitry Olshansky
May 27, 2012
 Curiously I'm making a huffman compression algo for fun, however I didn't see anything in std.array or anywhere that was to support bools specifically (in a packed form anyways). So I'm making one. So far I've got it saving the data as uint, 0 refers to the most significant bit and 7 the least significant, so A will come out as 0100001 and look right

 It supports a range, however foreach doesn't like using front/popFront/empty if I make opApply. It supports slices as well.

 For the BitArray, using it as follows I get an error:

struct BitArray {
  alias length opDollar;
  alias length __dollar;

  int length();
  Range opSlice();
  Range opSlice(int s, int e);
  struct Range {
     int opDollar();
  }
}

 BitArray ba = BitArray(someArrayOfUbyte);
 auto range = ba[0 .. $]; //needs to access 'this' for length? shouldn't it rewrite to ba[0 .. ba.opDollar()] ?
 auto range2 = ba[];      //works fine

 It also seems the BitArray (but not the range) requires __dollar rather than opDollar, however an alias seems to fix that. (Why is this?? the Range doesn't need a __dollar alias to work right)

 I also have it so you can ref the individual bools (by using an intermediate one in opApply). So..

//perfectly fine in unittest
foreach(ref r_b; range) {
  r_b = !r_b;
}
May 27, 2012
On 27-05-2012 08:50, Era Scarecrow wrote:
> Curiously I'm making a huffman compression algo for fun, however I
> didn't see anything in std.array or anywhere that was to support bools
> specifically (in a packed form anyways). So I'm making one. So far I've
> got it saving the data as uint, 0 refers to the most significant bit and
> 7 the least significant, so A will come out as 0100001 and look right
>
> It supports a range, however foreach doesn't like using
> front/popFront/empty if I make opApply. It supports slices as well.
>
> For the BitArray, using it as follows I get an error:
>
> struct BitArray {
> alias length opDollar;
> alias length __dollar;
>
> int length();
> Range opSlice();
> Range opSlice(int s, int e);
> struct Range {
> int opDollar();
> }
> }
>
> BitArray ba = BitArray(someArrayOfUbyte);
> auto range = ba[0 .. $]; //needs to access 'this' for length? shouldn't
> it rewrite to ba[0 .. ba.opDollar()] ?
> auto range2 = ba[]; //works fine
>
> It also seems the BitArray (but not the range) requires __dollar rather
> than opDollar, however an alias seems to fix that. (Why is this?? the
> Range doesn't need a __dollar alias to work right)
>
> I also have it so you can ref the individual bools (by using an
> intermediate one in opApply). So..
>
> //perfectly fine in unittest
> foreach(ref r_b; range) {
> r_b = !r_b;
> }

std.bitmanip.BitArray.

-- 
Alex Rønne Petersen
alex@lycus.org
http://lycus.org
May 27, 2012
On Sunday, 27 May 2012 at 06:53:33 UTC, Alex Rønne Petersen wrote:
> std.bitmanip.BitArray.

 And I was certain I checked std.bitmanip. Oh well, I'll throw my current unittests at it and perhaps improve what's already avaliable if it needs it.
May 27, 2012
On Sunday, 27 May 2012 at 06:58:21 UTC, Era Scarecrow wrote:
> On Sunday, 27 May 2012 at 06:53:33 UTC, Alex Rønne Petersen wrote:
>> std.bitmanip.BitArray.
>
>  And I was certain I checked std.bitmanip. Oh well, I'll throw my current unittests at it and perhaps improve what's already avaliable if it needs it.

 Wow, it passed all my basic unittests with flying colors, even working with $ where mine failed. Most curious :) Guess my partial code can be put away and likely never touched again.
May 27, 2012
On 27-05-2012 08:58, Era Scarecrow wrote:
> On Sunday, 27 May 2012 at 06:53:33 UTC, Alex Rønne Petersen wrote:
>> std.bitmanip.BitArray.
>
> And I was certain I checked std.bitmanip. Oh well, I'll throw my current
> unittests at it and perhaps improve what's already avaliable if it needs
> it.

It could definitely use some improvement. In particular:

* It still uses the deprecated operator overload methods, rather than opBinary(Right) and opUnary.
* It's not quite const/immutable-friendly.
* It forces the GC on you. Probably not easy to solve until Andrei comes up with an allocators design.
* Needs more pure and nothrow.
* Needs more @safe/@trusted.
* The init() methods are very unintuitive at first glance.
* Should probably deprecate the reverse and sort properties.

... if you want to have a poke at it. ;)

-- 
Alex Rønne Petersen
alex@lycus.org
http://lycus.org
May 27, 2012
On Sunday, 27 May 2012 at 07:04:36 UTC, Alex Rønne Petersen wrote:
> It could definitely use some improvement. In particular:
>
> * It still uses the deprecated operator overload methods, rather than opBinary(Right) and opUnary.
> * It's not quite const/immutable-friendly.
> * It forces the GC on you. Probably not easy to solve until Andrei comes up with an allocators design.
> * Needs more pure and nothrow.
> * Needs more @safe/@trusted.
> * The init() methods are very unintuitive at first glance.
> * Should probably deprecate the reverse and sort properties.
>
> ... if you want to have a poke at it. ;)

Mmm probably the first change I'd do is

struct BitArray(INT = size_t)

 It should more precise size control letting you make larger than 2^32bits in an array. If there's an objection to this I'd need to know before I began (Not that it changes any functionality).

 I'll go over it and see what I can do. Strange, as I'm looking it over it looks remarkably similar to my incomplete one. Not seeing any support for slices, I'll probably add that functionality.
May 27, 2012
Era Scarecrow:

>  I'll go over it and see what I can do.

Take also a look in Bugzilla, there are few small enhancement requests about BitArray (like a fast population count method).

Bye,
bearophile
May 27, 2012
On Sunday, 27 May 2012 at 06:53:33 UTC, Alex Rønne Petersen wrote:
> std.bitmanip.BitArray.

And also std.container.Array ... it has a specialization that packs bools. It also appears to be more modern.
May 27, 2012
On Sunday, 27 May 2012 at 17:26:33 UTC, Chris Cain wrote:
> And also std.container.Array ... it has a specialization that packs bools. It also appears to be more modern.

 Unfortunately I'm not following, either in the documentation or glancing over the sources.
May 27, 2012
On Sunday, 27 May 2012 at 18:18:13 UTC, Era Scarecrow wrote:
> On Sunday, 27 May 2012 at 17:26:33 UTC, Chris Cain wrote:
>> And also std.container.Array ... it has a specialization that packs bools. It also appears to be more modern.
>
>  Unfortunately I'm not following, either in the documentation or glancing over the sources.


 Nevermind, was looking in std.array and not std.container.

 So should I work on std.bitmanip.BitArray?
« First   ‹ Prev
1 2 3 4