[squeak-dev] large dense sets of 1..n

Nicolas Cellier nicolas.cellier.aka.nice at gmail.com
Mon Aug 23 12:15:39 UTC 2010


You can see example in WideCharacterSet in image, or also load
BitArray from SqueakMap.

See also these messages for playing with bits
http://lists.squeakfoundation.org/pipermail/squeak-dev/2009-December/141893.html

And other tricks like how to
enumerate bits in a byte...
My own answsers:

| x |
x := 16rE4.
{
[ | y |
y := 1. 0 to: 7 do: [:iBit | (x bitAnd: y) = 0 ifTrue: [iBit + 1]. y
:= y *2]] bench.

[| y pow2 iBit |
y := x.
pow2 := #[1 2 4 8 16 32 64 128].
[y == 0] whileFalse: [y := y - (pow2 at: (iBit := y
highBitOfPositiveReceiver)). iBit]] bench.

[| y h iBit |
y := x.
iBit := 8.
h := 128.
[y == 0] whileFalse: [[y < h] whileTrue: [h := h bitShift: -1. iBit :=
iBit - 1]. y := y - h. h := h bitShift: -1. iBit := iBit - 1]] bench.

[| y h iBit |
y := x.
iBit := 8.
pow2 := #[1 2 4 8 16 32 64 128].
[y == 0] whileFalse: [[y < (h := pow2 at: iBit)] whileTrue: [iBit :=
iBit - 1]. y := y - h. iBit]] bench.

[| y pow2 hb iBit |
y := x.
pow2 := #[1 2 4 8 16 32 64 128].
hb := #[1 2 2 3 3 3 3 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7
7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7
7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 8 8 8 8 8 8 8 8 8
8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8
8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8
8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8
8 8 8 8 8 8 8 8 8 8 8 8 8 8].
[y == 0] whileFalse: [y := y - (pow2 at: (iBit := hb at: y)). iBit]] bench.

Nicolas

2010/8/23 Ralph Boland <rpboland at gmail.com>:
> I need to create some dense sets which will contain
> subsets of the integers  1..n where n is very large.
> I don't want to use regular sets because they would use to much space.
> Instead I want to map each set to an array of approximately size
> n/8 bytes which, because my sets will be dense, will save space.
> Containment of a number k  in a set is to be determined by testing
> whether bit  k  is set or cleared.  Pretty standard stuff I think.
>
> Is there code already that does this?
>
> If not, I will create a class LargeDenseSet containing some instance
> bitMap that holds the necessary space.
> For  bitMap,  is it better for me to use an array of integers or a
> LargePositiveInteger.
> How about using a BltBit?
>
> Is  LargeDenseSet a sufficiently used class to be part of Squeak or at
> least part of
> some standard package?
>
> Regards,
>
> Ralph Boland
>
>



More information about the Squeak-dev mailing list