Strange char[] behaviour
Thomas Kuehne
thomas-dloop at kuehne.cn
Mon Mar 20 15:49:51 PST 2006
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Jari-Matti Mäkelä schrieb am 2006-03-14:
> Jari-Matti Mäkelä wrote:
>> Somehow I though that the CoW prevents the misuse of strings. The
>> dchar-version works perfectly without .dup-cloning on any arbitrary long
>> input. The char-version doesn't work, if too many iterations/nodes are
>> created, but works perfectly when run once with short input strings. The
>> maximum input string length is then a constant. I guess it might be
>> valuable to end up with a short test case here. I'll try my best to
>> create one.
>
> Actually the dchar-version doesn't work perfectly either. I tried to use
> the code coverage (dmd -cov) and it "failed": (as you can see, it
> shouldn't be even possible to run those commented lines.)
>
> |import std.stdio, suffixnode, abstractsearcher;
> |
> |class SuffixTreeSearcher(T) : AbstractSearcher!(T) {
> | T[] catenatedStrings;
> | T[] sentinels;
> | alias SuffixNode!(T) GenericNode;
> | GenericNode root;
> 130| this(T[][] strings, T[] sentinels ...)
> | {
> 1| this.sentinels = sentinels;
> 1| catenatedStrings = strings[0]~sentinels[0]~
> strings[1]~sentinels[1];
> | }
> | public T[] searchLCS() {
> 1| root = new GenericNode();
> 206| for (int i = 0; i < catenatedStrings.length; ++i) {
> 185| root.addSuffix(catenatedStrings[i..$]);
> | }
> 84| return null;
> 388| //return root.mark(sentinels);
> | }
> 83|
> | char[] name() {
> 1| return "Suffix tree";
> | }
> |}
> suffixtreesearcher.d is 100% covered
>
> I works as it should only when I comment the addSuffix-line:
>
> |import std.stdio, suffixnode, abstractsearcher;
> |
> |class SuffixTreeSearcher(T) : AbstractSearcher!(T) {
> | T[] catenatedStrings;
> | T[] sentinels;
> | alias SuffixNode!(T) GenericNode;
> | GenericNode root;
> | this(T[][] strings, T[] sentinels ...)
> | {
> 1| this.sentinels = sentinels;
> 1| catenatedStrings = strings[0]~sentinels[0]~
> strings[1]~sentinels[1];
> | }
> | public T[] searchLCS() {
> 1| root = new GenericNode();
> 206| for (int i = 0; i < catenatedStrings.length; ++i) {
> |// root.addSuffix(catenatedStrings[i..$]);
> | }
> 1| return null;
> | //return root.mark(sentinels);
> | }
> |
> | char[] name() {
> 1| return "Suffix tree";
> | }
> |}
> suffixtreesearcher.d is 100% covered
>
> Well, the only think I can think of is that the algorithm truly corrupts
> the runtime code by using array slicing. I also noticed that although it
> works fine without -cov, running it >=2 times segfaults with -cov.
The code above isn't complete thus makes testing it a bit difficult.
As a start, let's try to find out the real coverage numbers:
replace
> for (int i = 0; i < catenatedStrings.length; ++i) {
> root.addSuffix(catenatedStrings[i..$]);
> }
with something like
> writefln("LOOP_PRE");
> for (int i = 0; writefln("LOOP_CHECK"), i < catenatedStrings.length; ++i, writefln("LOOP_INC")) {
> writefln("LOOP");
> root.addSuffix(catenatedStrings[i..$]);
> }
> writefln("LOOP_POST");
That isn't the kind of code I usually want to touch, but since the RT
(and maybe the line numbers in the debug info) might be corrupted...
Thomas
-----BEGIN PGP SIGNATURE-----
iD8DBQFEH0zB3w+/yD4P9tIRAqe/AJ9D9Tt8k9MNR0dfTMbSBVDoZhm8FQCcC3ff
552DecBfxViqJKyiEQiTx14=
=giOX
-----END PGP SIGNATURE-----
More information about the Digitalmars-d-bugs
mailing list