de inside a 'void main()' function
2) Pasting the code from the top of that page
and it works:
void main() {
int[string] aa; // Associative array of ints that are
// indexed by string keys.
// The KeyType is string.
aa["hello"] = 3; // set value associated with key "h
ld printfs it seems to be the case that the array is
being populated (elsewhere) with the expected correct values.
Taking out the if doesn’t seem to help either. I don’t have a
way of examining the contents of the dynamic array directly to
check that they are actually being stored as expected, other
t
On Friday, 30 June 2023 at 21:25:23 UTC, H. S. Teoh wrote:
On Fri, Jun 30, 2023 at 07:05:23PM +, Cecil Ward via
Digitalmars-d-learn wrote: [...]
It would help if you could post the complete code that
reproduces the problem. Or, if you do not wish to reveal your
code, reduce it to a
https://forum.dlang.org/thread/duetqujuoceancqtj...@forum.dlang.org
Try HashMap see if it is still a problem.
If no, then it's another example of the built in AA problem.
On Fri, Jun 30, 2023 at 07:05:23PM +, Cecil Ward via Digitalmars-d-learn
wrote:
[...]
It would help if you could post the complete code that reproduces the
problem. Or, if you do not wish to reveal your code, reduce it to a
minimal case that still exhibits the same problem, so that we can
On 6/30/23 13:16, Cecil Ward wrote:
On Friday, 30 June 2023 at 19:58:39 UTC, FeepingCreature wrote:
Note that you can do `uint ordinal = Decls.ordinals.get(str, -1);`.
Is the second argument an ‘else’ then, my friend?
Yes, .get and friends appear in this table:
On Friday, 30 June 2023 at 19:58:39 UTC, FeepingCreature wrote:
On Friday, 30 June 2023 at 19:05:23 UTC, Cecil Ward wrote:
I have code roughly like the following:
dstring str = "name"d;
uint ordinal = (( str in Decls.ordinals ) !is null) ?
Decls.ordinals[ str ] : -1;
struct Decls
On Friday, 30 June 2023 at 20:12:08 UTC, Ali Çehreli wrote:
On 6/30/23 12:05, Cecil Ward wrote:
> I have code roughly like the following:
>
> dstring str = "name"d;
Aside: One almost never needs dstring.
> uint ordinal = (( str in Decls.ordinals ) !is null) ?
> Decls.ordinals[ str ]
On 6/30/23 12:05, Cecil Ward wrote:
> I have code roughly like the following:
>
> dstring str = "name"d;
Aside: One almost never needs dstring.
> uint ordinal = (( str in Decls.ordinals ) !is null) ?
> Decls.ordinals[ str ] : -1;
>
> struct Decls
> {
> uint[ dstring]
On Friday, 30 June 2023 at 19:05:23 UTC, Cecil Ward wrote:
I have code roughly like the following:
dstring str = "name"d;
uint ordinal = (( str in Decls.ordinals ) !is null) ?
Decls.ordinals[ str ] : -1;
struct Decls
{
uint[ dstring] ordinals;
}
//and
it always returns ordinal== -1 from the
expression. Can you sort me out? I took this from the example
given in the language reference under arrays, testing for
membership (or similar, I forget the subssection title).
From good old printfs it seems to be the case that the array is
being
On Tuesday, 17 September 2019 at 15:51:34 UTC, Andrea Fontana
wrote:
On Tuesday, 17 September 2019 at 14:33:30 UTC, Brett wrote:
The idea is to basically use a dynamic array for most of the
items, then an array to get the rest.
T[] Base;
T[int] Rest;
Then if Base has a max size(usually
On Tuesday, 17 September 2019 at 14:33:30 UTC, Brett wrote:
The idea is to basically use a dynamic array for most of the
items, then an array to get the rest.
T[] Base;
T[int] Rest;
Then if Base has a max size(usually it might be fixed due to
some algorithm) the Rest AA can pick up any
On Tuesday, 17 September 2019 at 14:33:30 UTC, Brett wrote:
The idea is to basically use a dynamic array for most of the
items, then an array to get the rest.
T[] Base;
T[int] Rest;
Then if Base has a max size(usually it might be fixed due to
some algorithm) the Rest AA can pick up any
The idea is to basically use a dynamic array for most of the
items, then an array to get the rest.
T[] Base;
T[int] Rest;
Then if Base has a max size(usually it might be fixed due to some
algorithm) the Rest AA can pick up any outside values easily.
The idea here is to be able to combine
On Wednesday, 21 March 2018 at 18:31:29 UTC, tipdbmp wrote:
I see. I guess the other would be:
{
int[8192] bar;
int[8192][string] foo;
foo["a"] = bar;
foo["a"][8191] = -1;
}
https://run.dlang.io/is/AK2X2t
Are you looking to use static arrays or dynamic? You can't use
the new
I see. I guess the other would be:
{
int[8192] bar;
int[8192][string] foo;
foo["a"] = bar;
foo["a"][8191] = -1;
}
On Wednesday, 21 March 2018 at 15:53:32 UTC, tipdbmp wrote:
int[10][string] foo;
One option is to initialize like this
---
void main() {
int[10][string] foo;
if("a" !in foo)
foo["a"] = [0,0,0,0,0,0,0,0,0,0]; // set all to zero to create
the key
foo["a"][4] = 4; // now valid to
// foo is an associative array/hashtable with
// key type: string
// value type: int[10]
//
int[10][string] foo;
// foo["a"] = new int[10]; // Range violation at runtime
// foo["a"][0] = 1; // Range violation at runtime
On Wednesday, 22 June 2016 at 09:27:01 UTC, cym13 wrote:
what i meant is that "{}" should be fully equivalent to
"Struct()" ctor in terms of calling postblits, and it isn't.
On Wednesday, 22 June 2016 at 09:27:01 UTC, cym13 wrote:
On the other hand I don't see why you'd expect {} to call
postblit at
all.
'cause it essentially makes a copy. i gave the sample in
bugreport. it worth me a hour of debugging to find why my
refcounted struct keep crashing with invalid
On Wednesday, 22 June 2016 at 08:06:26 UTC, ketmar wrote:
On Wednesday, 22 June 2016 at 06:43:12 UTC, Paul wrote:
Why is initialisation via {} bad (in simple terms please :D)?
first, it is buggy. i.e. it doesn't always call postblit[1].
second, it's syntax is the same as the syntax of
On Wednesday, 22 June 2016 at 06:43:12 UTC, Paul wrote:
Why is initialisation via {} bad (in simple terms please :D)?
first, it is buggy. i.e. it doesn't always call postblit[1].
second, it's syntax is the same as the syntax of argument-less
lambda, which makes it context-dependent -- so
likely I need a better way to
store the information.
@ketmar:
Why is initialisation via {} bad (in simple terms please :D)? I
noticed while working on this bit of code that I could initialise
simple struct variables with {} but couldn't do the same with an
array of structs. I guess
On Tuesday, 21 June 2016 at 19:33:31 UTC, cym13 wrote:
i would want him to figure that by himself, tbh. just to remember
that "{}" struct initialization is BAD. ;-)
On Tuesday, 21 June 2016 at 19:15:56 UTC, Paul wrote:
Given these structures and declaration:
struct CoordList{
int x, y;
}
struct Part{
int x, y;
CoordList[] coords;
int nextNode, prevNode;
string nextEnter, prevEnter;
}
Part[10] trackTemplates;
Can
trackTemplates[0].coords = [ CoordList(0, 9), CoordList(1, 1),
CoordList(3, 6) ];
Given these structures and declaration:
struct CoordList{
int x, y;
}
struct Part{
int x, y;
CoordList[] coords;
int nextNode, prevNode;
string nextEnter, prevEnter;
}
Part[10] trackTemplates;
Can someone please tell me why I can't initialise
On Tuesday, 24 December 2013 at 14:39:16 UTC, Timon Gehr wrote:
On 12/24/2013 12:36 PM, Dfr wrote:
Let's say i have array of kind:
auto a = [[1,FF], [2, 00FF00], ...];
Is there simple way to turn it into associative array of kind:
string[string] b = [1: FF, 2: 00FF00, ...];
void
Dfr:
This example looks cleanest, but not compile with error:
Error: no property 'assocArray' for type 'MapResult!(__lambda9,
immutable(char[][])[])'
It compiles for me.
Bye,
bearophile
On Wednesday, 25 December 2013 at 14:44:57 UTC, bearophile wrote:
Dfr:
This example looks cleanest, but not compile with error:
Error: no property 'assocArray' for type
'MapResult!(__lambda9, immutable(char[][])[])'
It compiles for me.
Bye,
bearophile
Sorry, just forgot to import
Let's say i have array of kind:
auto a = [[1,FF], [2, 00FF00], ...];
Is there simple way to turn it into associative array of kind:
string[string] b = [1: FF, 2: 00FF00, ...];
On Tuesday, 24 December 2013 at 11:36:23 UTC, Dfr wrote:
Let's say i have array of kind:
auto a = [[1,FF], [2, 00FF00], ...];
Is there simple way to turn it into associative array of kind:
string[string] b = [1: FF, 2: 00FF00, ...];
You can if the initial array was comprised
On Tue, Dec 24, 2013 at 12:36 PM, Dfr defle...@yandex.ru wrote:
Let's say i have array of kind:
auto a = [[1,FF], [2, 00FF00], ...];
Is there simple way to turn it into associative array of kind:
string[string] b = [1: FF, 2: 00FF00, ...];
To build a value (your b) from a range
Philippe Sigaud:
auto a = [[1,FF], [2, 00FF00]];
import std.algorithm: reduce;
string[string] b;
b = reduce!((aa, pair) { aa[pair[0]] = pair[1]; return
aa;})(b,a);
writeln(b);
While this code seems correct (and I think it's kind of common in
Scala), I consider it an
On Tue, Dec 24, 2013 at 1:12 PM, bearophile bearophileh...@lycos.com wrote:
Philippe Sigaud:
auto a = [[1,FF], [2, 00FF00]];
import std.algorithm: reduce;
string[string] b;
b = reduce!((aa, pair) { aa[pair[0]] = pair[1]; return aa;})(b,a);
writeln(b);
While this
On Tuesday, 24 December 2013 at 12:33:13 UTC, Philippe Sigaud
wrote:
I don't know. I really consider `reduce` a nice way to collapse
a
structure down to a value. I find it in many different places.
Sure,
map and filter are more usual, but reduce is not far behind.
you use map and filter to
On 12/24/2013 12:36 PM, Dfr wrote:
Let's say i have array of kind:
auto a = [[1,FF], [2, 00FF00], ...];
Is there simple way to turn it into associative array of kind:
string[string] b = [1: FF, 2: 00FF00, ...];
void main(){
import std.array, std.algorithm, std.typecons
On Tue, Dec 24, 2013 at 3:07 PM, monarch_dodra monarchdo...@gmail.com wrote:
I don't know. I really consider `reduce` a nice way to collapse a
structure down to a value. I find it in many different places. Sure,
map and filter are more usual, but reduce is not far behind.
you use map and
On Mon, 02 Jan 2012 18:30:52 -0500, Timon Gehr timon.g...@gmx.ch wrote:
On 01/03/2012 12:02 AM, Mafi wrote:
Am 02.01.2012 23:33, schrieb Timon Gehr:
On 01/02/2012 11:21 PM, RenatoL wrote:
Just curious... the answer of the compiler it's a bit unclear to
me...
T[] is a dynamic array of type T
Steven Schveighoffer:
Interesting trivia, the compiler actually transforms the following:
struct S
{
int x;
}
auto s = new S;
into this:
auto s = (new S[1]).ptr;
Found that out when revamping the array allocation code. It's one thing
that still bugs me because this means
On Sat, 07 Jan 2012 13:29:25 -0500, bearophile bearophileh...@lycos.com
wrote:
Steven Schveighoffer:
Interesting trivia, the compiler actually transforms the following:
struct S
{
int x;
}
auto s = new S;
into this:
auto s = (new S[1]).ptr;
Found that out when revamping the array
Steven Schveighoffer:
Wasted space. An appendable array requires extra space at the end of the
block to store the 'used' length.
If the disadvantages are significant is this improvement in Bugzilla as
enhancement request?
It's not in bugzilla, but it's strictly a performance thing
On Sat, 07 Jan 2012 14:24:19 -0500, bearophile bearophileh...@lycos.com
wrote:
Steven Schveighoffer:
Wasted space. An appendable array requires extra space at the end of
the
block to store the 'used' length.
If the disadvantages are significant is this improvement in Bugzilla
Steven Schveighoffer:
http://d.puremagic.com/issues/show_bug.cgi?id=7243
Thank you :-) I think in Bugzilla there is space for few performance-related
enhancement requests too, if they are about very common/important parts of the
language :-)
Bye,
bearophile
auto r = new int[][5];
this is ok
auto r = new int[][];
this is not ok
Error: new can only create structs, dynamic arrays or class objects
, not int[][]'s
why?
Array(T){this(size_t length){...}}
auto r = new Array!(Array!int); // error: missing constructor argument
Just curious... the answer of the compiler it's a bit unclear to
me...
T[] is a dynamic array of type T.
T[][] is a dynamic array of T[]. But this doesn't work. Why?
On 01/02/2012 11:21 PM, RenatoL wrote:
Just curious... the answer of the compiler it's a bit unclear to
me...
T[] is a dynamic array of type T.
T[][] is a dynamic array of T[]. But this doesn't work. Why?
It does work. Why do you think it does not?
T[] a; // ok
T[][] b
Am 02.01.2012 23:33, schrieb Timon Gehr:
On 01/02/2012 11:21 PM, RenatoL wrote:
Just curious... the answer of the compiler it's a bit unclear to
me...
T[] is a dynamic array of type T.
T[][] is a dynamic array of T[]. But this doesn't work. Why?
It does work. Why do you think it does not?
T
I have:
auto r = new int[][];
Error: new can only create structs, dynamic arrays or class objects
, not int[][]'s
while
auto r = new int[][3];
is ok.
On 01/03/2012 12:03 AM, RenatoL wrote:
I have:
auto r = new int[][];
Error: new can only create structs, dynamic arrays or class objects
, not int[][]'s
while
auto r = new int[][3];
is ok.
new int[][3] is an alternate form of new int[][](3); new int[][3]
allocates an int[][] with 3
On 01/03/2012 12:02 AM, Mafi wrote:
Am 02.01.2012 23:33, schrieb Timon Gehr:
On 01/02/2012 11:21 PM, RenatoL wrote:
Just curious... the answer of the compiler it's a bit unclear to
me...
T[] is a dynamic array of type T.
T[][] is a dynamic array of T[]. But this doesn't work. Why?
It does
On 3 January 2012 00:27, Timon Gehr timon.g...@gmx.ch wrote:
On 01/03/2012 12:03 AM, RenatoL wrote:
I have:
auto r = new int[][];
Error: new can only create structs, dynamic arrays or class objects
, not int[][]'s
while
auto r = new int[][3];
is ok.
new int[][3] is an alternate
RenatoL wrote:
Error: new can only create structs,
dynamic arrays or class objects, not int[][]'s
There is an error in the error message:
new can only create _static_ arrays.
-manfred
On Monday, January 02, 2012 23:49:36 Manfred Nowak wrote:
RenatoL wrote:
Error: new can only create structs,
dynamic arrays or class objects, not int[][]'s
There is an error in the error message:
new can only create _static_ arrays.
Um no. new is used for creating _dynamic_ arrays, not
' and 'length'. 'ptr' is
a pointer to the first element of the array, and 'length' indicates how
many elements are in the array. int[] does not carry any data on its
own: it is only a reference to the data.
int[5] on the other hand is a data structure that contains 5 integers
with the indices
Jonathan M Davis wrote:
new is used for creating _dynamic_ arrays, not static arrays.
Correct, my fault. I meant something like statically initialized dynamic,
because `new' currently needs an `uint' number to allocate some space for
the elements of the outermost array.
The posting shows
Daniel Keep:
[1] Except for int-float. Oh, and objects. Really, this is one thing
I could just about strangle KR for: conflating value-preserving,
non-value-preserving *AND* unsafe conversions all into a single
construct. Walter, gets slapped with a fish for not putting a bullet in
cast's
negotiations. cast is specifically *designed* to circumvent
the type system's protections [1].
If you want to do a value conversion, *do a value conversion*. Allocate
a new array and convert each member. cast doesn't call the constructor
or the postblit because it's doing a pointer conversion.
Your code
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Ali Çehreli wrote:
Daniel Keep wrote:
...
snip
Well I forget the details, but it's been pointed out before
that D's cast is fundamentally broken.
You get one cast operator that hides the full set of c++
static, dynamic, const reinterpret casts.
Is the following cast legal with dmd 2.040?
struct MyChar
{
dchar d;
this(dchar param)
in {
assert(false); // not called
}
body
{
d = param;
assert(d != param); // not called
}
this(this)
in {
assert(false); //
is specifically *designed* to circumvent
the type system's protections [1].
If you want to do a value conversion, *do a value conversion*. Allocate
a new array and convert each member. cast doesn't call the constructor
or the postblit because it's doing a pointer conversion.
Your code
Mon, 8 Dec 2008 06:59:40 + (UTC), BCS wrote:
Reply to Bill,
On Mon, Dec 8, 2008 at 2:57 PM, BCS [EMAIL PROTECTED] wrote:
Reply to Michael P.,
rand() TYPES_OF_TILES
never use rand like that (the low order bit on many rands toggles
every
single time)
better (I think):
rand() /
Reply to Sergey,
Mon, 8 Dec 2008 06:59:40 + (UTC), BCS wrote:
better (I think):
rand() / (RAND_MAX / TYPES_OF_TILES)
Don't use rand() like this, ever. ;) RAND_MAX / TYPES_OF_TILES is
an integer expression, it rounds down, therefore your formula gives a
slightly greater range of
Michael P. Wrote:
Okay, I'm getting an array bounds error, and I have no clue why. Here is the
code that affect it:
//Constants
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int TILE_WIDTH = 20;
const int TILE_HEIGHT = 20; //how big one tile is, in pixels
const int
Okay, I'm getting an array bounds error, and I have no clue why. Here is the
code that affect it:
//Constants
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int TILE_WIDTH = 20;
const int TILE_HEIGHT = 20; //how big one tile is, in pixels
const int NUMBER_OF_TILES_WIDTH
Reply to Michael P.,
rand() TYPES_OF_TILES
never use rand like that (the low order bit on many rands toggles every single
time)
better (I think):
rand() / (TYPES_OF_TILES / RAND_MAX)
On Mon, Dec 8, 2008 at 2:57 PM, BCS [EMAIL PROTECTED] wrote:
Reply to Michael P.,
rand() TYPES_OF_TILES
never use rand like that (the low order bit on many rands toggles every
single time)
better (I think):
rand() / (TYPES_OF_TILES / RAND_MAX)
That's a divide by zero, so I don't think
Reply to Bill,
On Mon, Dec 8, 2008 at 2:57 PM, BCS [EMAIL PROTECTED] wrote:
Reply to Michael P.,
rand() TYPES_OF_TILES
never use rand like that (the low order bit on many rands toggles
every
single time)
better (I think):
rand() / (TYPES_OF_TILES / RAND_MAX)
That's a divide by zero, so I
70 matches
Mail list logo