Thread overview | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
February 04, 2005 .sort property on dynamic array? | ||||
---|---|---|---|---|
| ||||
I can't tell if I'm not using the sort property of dynamic arrays correctly, or if something else is going on. I was using the recls module and gathering up a bunch of Entry objects in an array of Entries. When I go to sort the array using the sort property, I get an access violation. I'm not sure how to debug it from here. I don't know if I need to supply my own sort routine or if there's something else I should do. The Phobos doc. doesn't really speak to that. I'm using dmd 0.111. Here's the code: #import std.recls; # #void main() #{ # Entry[] entries; # entries.length = 1000; # # int i; # # Search path = new Search(".", "*.*", RECLS_FLAG.RECLS_F_RECURSIVE); # foreach (Entry e; path) # { # if (i == entries.length) # entries.length = entries.length * 2; # entries[i] = e; # i++; # } # # entries.sort; #} -Kramer |
February 04, 2005 Re: .sort property on dynamic array? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kramer | I haven't actually run this but try adding # entries = entries[0..i]; right before # entries.sort; since the sort algorithm is sorting all the null entries at the end of the array and it could be getting seg-v's trying to compare null against other items. That's just a hunch, though. |
February 04, 2005 Re: .sort property on dynamic array? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ben Hinkle | In article <cu0l9k$604$1@digitaldaemon.com>, Ben Hinkle says... > >I haven't actually run this but try adding ># entries = entries[0..i]; >right before ># entries.sort; >since the sort algorithm is sorting all the null entries at the end of the >array and it could be getting seg-v's trying to compare null against other >items. That's just a hunch, though. > > That works; no seg. fault. But, I'm just wondering, is that the way it should work? I guess maybe with more doc. on how the sort does it's thing I could figure out a solution (or be able to override it), but it might have taken me a while otherwise. It's not a problem for people familiar with D, but what about amatuers such as myself who think that sort should just do what it can (i.e., sort things in a consistent manner, either with nulls at the top, or the bottom, whatever) without complaining. True, everything has a learning curve, but arrays are a basic structure in languages, so someone coming over from c/c++ (or any other language) would probably not expect to have too much of a learning curve on D arrays. Although, I do recognize that they have qualities that /are/ different from other languages. Sorry if that sounded like a rant... just thinking out loud. :) -Kramer |
February 04, 2005 Re: .sort property on dynamic array? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kramer | In article <cu0nbo$7v7$1@digitaldaemon.com>, Kramer says... > >In article <cu0l9k$604$1@digitaldaemon.com>, Ben Hinkle says... >> >>I haven't actually run this but try adding >># entries = entries[0..i]; >>right before >># entries.sort; >>since the sort algorithm is sorting all the null entries at the end of the >>array and it could be getting seg-v's trying to compare null against other >>items. That's just a hunch, though. >> >> > >That works; no seg. fault. > >But, I'm just wondering, is that the way it should work? I guess maybe with more doc. on how the sort does it's thing I could figure out a solution (or be able to override it), but it might have taken me a while otherwise. It's not a problem for people familiar with D, but what about amatuers such as myself who think that sort should just do what it can (i.e., sort things in a consistent manner, either with nulls at the top, or the bottom, whatever) without complaining. True, everything has a learning curve, but arrays are a basic structure in languages, so someone coming over from c/c++ (or any other language) would probably not expect to have too much of a learning curve on D arrays. Although, I do recognize that they have qualities that /are/ different from other languages. > >Sorry if that sounded like a rant... just thinking out loud. :) > >-Kramer > I sympathize with the argument that it shouldn't seg-v on null. I had noticed this a while ago now that I think about it. The typeinfo for class objects ti_C.d has a compare function with the comment and if clause: // Regard null references as always being "less than" if (o1 != o2) which will not test as "less than" but will actually seg-v. If we change that != to !== (and maybe a few others in that file) it would probably be fine. The only possible problem could be with some logic identities but I can't really think of any problems. Also note that it might be better to say null is greater than everything so that it appears at the end of the array instead of at the front. |
February 06, 2005 Re: .sort property on dynamic array? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ben Hinkle | "Ben Hinkle" <Ben_member@pathlink.com> wrote in message news:cu120r$h0n$1@digitaldaemon.com... > // Regard null references as always being "less than" > if (o1 != o2) > which will not test as "less than" but will actually seg-v. If we change that != > to !== (and maybe a few others in that file) it would probably be fine. Fixed. -Walter |
February 09, 2005 Re: .sort property on dynamic array? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kramer | Does it do the same thing with int / some vanilla objects? "Kramer" <Kramer_member@pathlink.com> wrote in message news:cu0ih6$33h$1@digitaldaemon.com... >I can't tell if I'm not using the sort property of dynamic arrays correctly, or > if something else is going on. > > I was using the recls module and gathering up a bunch of Entry objects > in an > array of Entries. When I go to sort the array using the sort > property, I get an > access violation. I'm not sure how to debug it from here. I don't > know if I > need to supply my own sort routine or if there's something else I > should do. > The Phobos doc. doesn't really speak to that. > > I'm using dmd 0.111. > > Here's the code: > > #import std.recls; > # > #void main() > #{ > # Entry[] entries; > # entries.length = 1000; > # > # int i; > # > # Search path = new Search(".", "*.*", > RECLS_FLAG.RECLS_F_RECURSIVE); > # foreach (Entry e; path) > # { > # if (i == entries.length) > # entries.length = entries.length * 2; > # entries[i] = e; > # i++; > # } > # > # entries.sort; > #} > > -Kramer > > |
February 10, 2005 Re: .sort property on dynamic array? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Matthew | No. I tried it with an int array and a struct array with the struct consisting of a char[] field and an int field. They both passed the sort. For the recls code, the foreach loop works, but just not the sort routine on the array. Hmmm... Will dig around in the array sort routine. Maybe I'll trip over something... -Kramer In article <cubl3s$12b0$1@digitaldaemon.com>, Matthew says... > >Does it do the same thing with int / some vanilla objects? > >"Kramer" <Kramer_member@pathlink.com> wrote in message news:cu0ih6$33h$1@digitaldaemon.com... >>I can't tell if I'm not using the sort property of dynamic arrays correctly, or >> if something else is going on. >> >> I was using the recls module and gathering up a bunch of Entry objects >> in an >> array of Entries. When I go to sort the array using the sort >> property, I get an >> access violation. I'm not sure how to debug it from here. I don't >> know if I >> need to supply my own sort routine or if there's something else I >> should do. >> The Phobos doc. doesn't really speak to that. >> >> I'm using dmd 0.111. >> >> Here's the code: >> >> #import std.recls; >> # >> #void main() >> #{ >> # Entry[] entries; >> # entries.length = 1000; >> # >> # int i; >> # >> # Search path = new Search(".", "*.*", >> RECLS_FLAG.RECLS_F_RECURSIVE); >> # foreach (Entry e; path) >> # { >> # if (i == entries.length) >> # entries.length = entries.length * 2; >> # entries[i] = e; >> # i++; >> # } >> # >> # entries.sort; >> #} >> >> -Kramer >> >> > > |
February 10, 2005 Re: .sort property on dynamic array? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Kramer | It's not out of the question that it's a recls problem, although I'm struggling to fathom how. Do you want to send me a bit of illustrative code, and I'll delve with my latest version of recls here. If it is a bug, it'd be nice to have it fixed before I update Phobos with the new recls in the next week or so. "Kramer" <Kramer_member@pathlink.com> wrote in message news:cuete6$14am$1@digitaldaemon.com... > No. I tried it with an int array and a struct array with the struct > consisting > of a char[] field and an int field. They both passed the sort. For > the recls > code, the foreach loop works, but just not the sort routine on the > array. > Hmmm... Will dig around in the array sort routine. Maybe I'll trip > over > something... > > -Kramer > > In article <cubl3s$12b0$1@digitaldaemon.com>, Matthew says... >> >>Does it do the same thing with int / some vanilla objects? >> >>"Kramer" <Kramer_member@pathlink.com> wrote in message news:cu0ih6$33h$1@digitaldaemon.com... >>>I can't tell if I'm not using the sort property of dynamic arrays correctly, or >>> if something else is going on. >>> >>> I was using the recls module and gathering up a bunch of Entry >>> objects >>> in an >>> array of Entries. When I go to sort the array using the sort >>> property, I get an >>> access violation. I'm not sure how to debug it from here. I don't >>> know if I >>> need to supply my own sort routine or if there's something else I >>> should do. >>> The Phobos doc. doesn't really speak to that. >>> >>> I'm using dmd 0.111. >>> >>> Here's the code: >>> >>> #import std.recls; >>> # >>> #void main() >>> #{ >>> # Entry[] entries; >>> # entries.length = 1000; >>> # >>> # int i; >>> # >>> # Search path = new Search(".", "*.*", >>> RECLS_FLAG.RECLS_F_RECURSIVE); >>> # foreach (Entry e; path) >>> # { >>> # if (i == entries.length) >>> # entries.length = entries.length * 2; >>> # entries[i] = e; >>> # i++; >>> # } >>> # >>> # entries.sort; >>> #} >>> >>> -Kramer >>> >>> >> >> > > |
Copyright © 1999-2021 by the D Language Foundation