Thread overview | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
April 30, 2015 Ada to D - an array for storing values of each of the six bits which are sufficient | ||||
---|---|---|---|---|
| ||||
Hi, There is an array of values to store each of which sufficiently 6 bits. As it is written down on the D? ----- With Ada.Text_IO; Use Ada.Text_IO; With Ada.Integer_Text_IO; Use Ada.Integer_Text_IO; procedure Program is type T_Type is range -10 .. 27; for T_Type'Size use 6; type Vector is array(1 .. 100) of T_Type; Pragma Pack(Vector); My_Array : constant Vector := (1 => -5, 2 => 22, others => 10); begin Put_Line(Integer'Image(My_Array'Size)); end Program; ----- http://ideone.com/uAzl41 |
April 30, 2015 Re: Ada to D - an array for storing values of each of the six bits which are sufficient | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dennis Ritchie | Dennis Ritchie:
> There is an array of values to store each of which sufficiently 6 bits.
> As it is written down on the D?
You can't do it directly in D. Someone has to write a packed array data structure to do it.
Bye,
bearophile
|
May 01, 2015 Re: Ada to D - an array for storing values of each of the six bits which are sufficient | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | On Thursday, 30 April 2015 at 11:20:55 UTC, bearophile wrote:
> Dennis Ritchie:
>
>> There is an array of values to store each of which sufficiently 6 bits.
>> As it is written down on the D?
>
> You can't do it directly in D. Someone has to write a packed array data structure to do it.
>
> Bye,
> bearophile
Thanks.
Anybody can write a packed array on the D? I once badly represent the means by which we can write a packed array. Maybe for this you should use core.simd or unions?
|
May 01, 2015 Re: Ada to D - an array for storing values of each of the six bits which are sufficient | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dennis Ritchie | Dennis Ritchie:
> Anybody can write a packed array on the D? I once badly represent the means by which we can write a packed array. Maybe for this you should use core.simd or unions?
SIMD could be useful for some fancy bulk operations. But you should be able to write a good basic packed array without SIMD, perhaps about as nice as the Ada ones (D sometimes offers good enough tools to build what you need).
Posible use:
PackedDynamicArray!6 pa; // On heap.
PackedFixedArray!(6, 300) pfa; // On stack.
Bye,
bearophile
|
May 01, 2015 Re: Ada to D - an array for storing values of each of the six bits which are sufficient | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | Maybe someone will show a primitive packed array. I really can not imagine how to do it on D. |
May 03, 2015 Re: Ada to D - an array for storing values of each of the six bits which are sufficient | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dennis Ritchie | On Friday, 1 May 2015 at 23:22:31 UTC, Dennis Ritchie wrote: > Maybe someone will show a primitive packed array. I really can not imagine how to do it on D. Maybe you can somehow use bitfields. While what happened is something like this: ----- import std.stdio, std.bitmanip; struct A { mixin(bitfields!( uint, "bit", 6, bool, "flag1", 1, bool, "flag2", 1)); } void main() { A obj; int[] a; foreach (e; 0 .. 64) { obj.bit = e; a ~= e; } writeln(a); // obj.bit = 64; // Value is greater than //the maximum value of bitfield 'bit' } ----- http://ideone.com/Opr4zM |
May 03, 2015 Re: Ada to D - an array for storing values of each of the six bits which are sufficient | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dennis Ritchie | On Friday, 1 May 2015 at 23:22:31 UTC, Dennis Ritchie wrote: > Maybe someone will show a primitive packed array. I really can not imagine how to do it on D. Look at BitArray for an example https://github.com/D-Programming-Language/phobos/blob/12187d7be8b15b2f5f8ff6889cdb5ea3afb93dd1/std/bitmanip.d#L702. Here is an implementation in C++ that could be easily adopted. http://pempek.net/articles/2013/08/03/bit-packing-with-packedarray/ |
May 03, 2015 Re: Ada to D - an array for storing values of each of the six bits which are sufficient | ||||
---|---|---|---|---|
| ||||
Posted in reply to Martin Nowak | On Sunday, 3 May 2015 at 14:49:55 UTC, Martin Nowak wrote:
> On Friday, 1 May 2015 at 23:22:31 UTC, Dennis Ritchie wrote:
>> Maybe someone will show a primitive packed array. I really can not imagine how to do it on D.
>
> Look at BitArray for an example https://github.com/D-Programming-Language/phobos/blob/12187d7be8b15b2f5f8ff6889cdb5ea3afb93dd1/std/bitmanip.d#L702.
>
> Here is an implementation in C++ that could be easily adopted.
> http://pempek.net/articles/2013/08/03/bit-packing-with-packedarray/
Thank you. This should help.
|
May 05, 2015 Re: Ada to D - an array for storing values of each of the six bits which are sufficient | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dennis Ritchie | Realized bitmap, sorry that does not work with DMD 2.067.1: http://vlang.org/docs/Data_Types/Bits_and_Logic.html https://github.com/coverify/vlang/blob/master/src/esdl/data/bvec.d |
Copyright © 1999-2021 by the D Language Foundation