View previous topic :: View next topic |
Author |
Message |
reinerp
Joined: 08 Oct 2006 Posts: 4
|
Posted: Sat Oct 14, 2006 1:24 am Post subject: Patch to arrays.d |
|
|
I've got a patch here:
-Added join, split, splitLen, greedySplitLen, and made repeat and repeatSub constructive.
-Added support for unit tests without Mango (since I couldn't get mango to work properly )
I couldn't find any way to attach the diff file properly, so I just pasted it here:
Code: | Index: array.d
===================================================================
--- array.d (revision 21)
+++ array.d (working copy)
@@ -28,11 +28,14 @@
* Unit tests support.
*/
version (Unittest) {
- import mango .io .Stdout ;
+ version (UsingPhobos) { import std.stdio : writef, writefln; }
+ else import mango .io .Stdout ;
+ void main() {}
}
unittest {
- Stdout("Unittest: cashew.utils.array: begin").cr;
+ version (UsingPhobos) writefln("Unittest: cashew.utils.array: begin");
+ else Stdout("Unittest: cashew.utils.array: begin").cr;
}
/***********************************************************************************
@@ -43,11 +46,13 @@
return arr.dup;
}
unittest {
- Stdout("\t array(...) --------> ");
+ start("array(...)");
+
auto foo = array!(int)(1, 2, 3);
assert(foo.length == 3U);
assert(typeid(typeof(foo[0])) == typeid(typeof(1)));
- Stdout("Pass").cr;
+
+ stop();
}
/***********************************************************************************
@@ -58,11 +63,11 @@
return haystack.indexOf(needle) != size_t.max;
}
unittest {
- Stdout("\t.contains(T) -------> ");
+ start(".contains(T)");
auto foo = array!(int)(1, 2, 3);
assert( foo.contains(2));
assert(! foo.contains(4));
- Stdout("Pass").cr;
+ stop();
}
/***********************************************************************************
@@ -80,11 +85,11 @@
return result;
}
unittest {
- Stdout("\t.diff(T[]) ---------> ");
+ start(".diff(T[])");
auto foo = array!(int)(1, 2, 3, 4, 5);
auto bar = array!(int)(1, 3, 5);
assert(foo.diff(bar) == array!(int)(2, 4));
- Stdout("Pass").cr;
+ stop();
}
/***********************************************************************************
@@ -100,11 +105,11 @@
}
}
unittest {
- Stdout("\t.eat(N) ------------> ");
+ start(".eat(N)");
auto foo = array!(int)(1, 2, 3, 4, 5);
foo.eat(3U);
assert(foo == array!(int)(4, 5));
- Stdout("Pass").cr;
+ stop();
}
/***********************************************************************************
@@ -134,10 +139,10 @@
return result;
}
unittest {
- Stdout("\t.indexOf(T) --------> ");
+ start(".indexOf(T)");
auto foo = array!(int)(1, 2, 3);
assert(foo.indexOf(2) == 1U);
- Stdout("Pass").cr;
+ stop();
}
/***********************************************************************************
@@ -157,11 +162,11 @@
return result;
}
unittest {
- Stdout("\t.indexOfSub(T[]) ---> ");
+ start(".indexOfSub(T[])");
auto foo = array!(int)(1, 2, 3, 4, 5);
auto sub = array!(int)( 3, 4 );
assert(foo.indexOfSub(sub) == 2U);
- Stdout("Pass").cr;
+ stop();
}
/***********************************************************************************
@@ -183,10 +188,10 @@
return result;
}
unittest {
- Stdout("\t.rindexOf(T) -------> ");
+ start(".rindexOf(T)");
auto foo = array!(int)(1, 9, 2, 9, 3);
assert(foo.rindexOf(9) == 3U);
- Stdout("Pass").cr;
+ stop();
}
/***********************************************************************************
@@ -208,11 +213,11 @@
return result;
}
unittest {
- Stdout("\t.rindexOfSub(T[]) --> ");
+ start(".rindexOfSub(T[])");
auto foo = array!(int)(1, 2, 9, 8, 1, 2, 9, 8);
auto sub = array!(int)(1, 2 );
assert(foo.rindexOfSub(sub) == 4U);
- Stdout("Pass").cr;
+ stop();
}
/***********************************************************************************
@@ -245,11 +250,11 @@
return result;
}
unittest {
- Stdout("\t.intersect(A,A) ----> ");
+ start(".intersect(A,A)");
auto foo = array!(int)(1, 2, 3, 4, 5 );
auto bar = array!(int)( 3, 4, 5, 6, 7);
assert(foo.intersect(bar) == array!(int)(3, 4, 5));
- Stdout("Pass").cr;
+ stop();
}
/***********************************************************************************
@@ -264,11 +269,11 @@
}
}
unittest {
- Stdout("\t.remove(T) ---------> ");
+ start(".remove(T)");
auto foo = array!(int)(1, 2, 3);
foo.remove(2);
assert(foo == array!(int)(1, 3));
- Stdout("Pass").cr;
+ stop();
}
/***********************************************************************************
@@ -283,11 +288,11 @@
}
}
unittest {
- Stdout("\t.removeAll(T) ------> ");
+ start(".removeAll(T)");
auto foo = array!(int)(1, 2, 1, 3, 1, 4, 1, 5);
foo.removeAll(1);
assert(foo == array!(int)(2, 3, 4, 5));
- Stdout("Pass").cr;
+ stop();
}
/***********************************************************************************
@@ -301,11 +306,11 @@
haystack = haystack[0 .. index] ~ haystack[index + 1 .. haystack.length];
}
unittest {
- Stdout("\t.removeIndex(N) ----> ");
+ start(".removeIndex(N)");
auto foo = array!(int)(1, 2, 3, 4);
foo.removeIndex(2U);
assert(foo == array!(int)(1, 2, 4));
- Stdout("Pass").cr;
+ stop();
}
/***********************************************************************************
@@ -319,13 +324,14 @@
haystack = haystack[0 .. start] ~ haystack[wall .. haystack.length];
}
unittest {
- Stdout("\t.removerange(N,M) --> ");
+ start(".removerange(N,M)");
auto foo = array!(int)(0, 1, 2, 3, 4, 5);
foo.removeRange(1U, 4U);
assert(foo == array!(int)(0, 4, 5));
- Stdout("Pass").cr;
+ stop();
}
+/+
/***********************************************************************************
* Build an array by repeating an item.
*/
@@ -339,7 +345,7 @@
haystack[] = needle;
}
unittest {
- Stdout("\t.repeat(T [, N]) ---> ");
+ start(".repeat(T [, N])");
int[] foo ;
foo.repeat(3, 3U);
assert(foo == array!(int)(3, 3, 3));
@@ -347,7 +353,7 @@
auto bar = array!(int)(0, 0, 0, 0, 0, 0, 0);
bar.repeat(7);
assert(bar == array!(int)(7, 7, 7, 7, 7, 7, 7));
- Stdout("Pass").cr;
+ stop();
}
/***********************************************************************************
@@ -361,14 +367,14 @@
}
}
unittest {
- Stdout("\t.repeatSub(T[], N) -> ");
+ start(".repeatSub(T[], N)");
int[] foo ,
sub = array!(int)(4, 2) ;
foo.repeatSub(sub, 3U);
assert(foo == array!(int)(4, 2, 4, 2, 4, 2));
- Stdout("Pass").cr;
+ stop();
}
-
++/
/***********************************************************************************
* Fill an array with a given smaller array.
*/
@@ -384,12 +390,12 @@
haystack.length = len;
}
unittest {
- Stdout("\t.fill (T[] [, N]) --> ");
+ start(".fill (T[] [, N])");
auto foo = array!(int)(1, 2, 3, 4, 5);
auto sub = array!(int)(3, 2, 1 );
foo.fill(sub);
assert(foo == array!(int)(3, 2, 1, 3, 2));
- Stdout("Pass").cr;
+ stop();
}
/***********************************************************************************
@@ -408,11 +414,11 @@
}
}
unittest {
- Stdout("\t.unique() ----------> ");
+ start(".unique()");
auto foo = array!(int)(1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5);
foo.unique();
assert(foo == array!(int)(1, 2, 3, 4, 5));
- Stdout("Pass").cr;
+ stop();
}
/***********************************************************************************
@@ -431,12 +437,12 @@
return result;
}
unittest {
- Stdout("\t.pull(N) -----------> ");
+ start(".pull(N)");
auto foo = array!(int)(1, 2, 3, 4, 5);
auto bar = foo.pull(3U);
assert(foo == array!(int)( 4, 5));
assert(bar == array!(int)(1, 2, 3 ));
- Stdout("Pass").cr;
+ stop;
}
/***********************************************************************************
@@ -459,7 +465,7 @@
return result;
}
unittest {
- Stdout("\t.rpull(N) ----------> ");
+ start(".rpull(N)");
auto foo = array!(int)(1, 2, 3, 4, 5);
auto bar = foo.rpull(3U);
assert(foo == array!(int)(1, 2 ));
@@ -469,7 +475,7 @@
auto beta = alpha.rpull(4U);
assert(alpha == array!(int)( ));
assert(beta == array!(int)(1, 2, 3));
- Stdout("Pass").cr;
+ stop();
}
/***********************************************************************************
@@ -481,7 +487,7 @@
haystack = haystack[iter .. haystack.length] ~ haystack[0 .. iter];
}
unittest {
- Stdout("\t.rotl(N) -----------> ");
+ start(".rotl(N)");
auto foo = array!(int)(1, 2, 3, 4, 5, 6);
foo.rotl(2U);
assert(foo == array!(int)(3, 4, 5, 6 ,1, 2));
@@ -489,7 +495,7 @@
auto bar = array!(int)(1, 2, 3);
bar.rotl(4U);
assert(bar == array!(int)(2, 3, 1));
- Stdout("Pass").cr;
+ stop();
}
/***********************************************************************************
@@ -504,7 +510,7 @@
haystack = haystack[idx .. haystack.length] ~ haystack[0 .. idx];
}
unittest {
- Stdout("\t.rotr(N) -----------> ");
+ start(".rotr(N)");
auto foo = array!(int)(1, 2, 3, 4, 5, 6);
foo.rotr(2U);
assert(foo == array!(int)(5, 6, 1, 2, 3, 4));
@@ -512,7 +518,7 @@
auto bar = array!(int)(1, 2, 3);
bar.rotr(4U);
assert(bar == array!(int)(3, 1, 2));
- Stdout("Pass").cr;
+ stop();
}
/***********************************************************************************
@@ -523,11 +529,11 @@
haystack ~= bale;
}
unittest {
- Stdout("\t.push(...) ---------> ");
+ start(".push(...)");
auto foo = array!(int)(1, 2, 3);
foo.push(4, 5);
assert(foo == array!(int)(1, 2, 3, 4, 5));
- Stdout("Pass").cr;
+ stop();
}
/***********************************************************************************
@@ -541,12 +547,12 @@
return result;
}
unittest {
- Stdout("\t.pop() -------------> ");
+ start(".pop()");
auto foo = array!(int)(1, 2, 3);
auto elm = foo.pop();
assert(foo == array!(int)(1, 2));
assert(elm == 3);
- Stdout("Pass").cr;
+ stop();
}
/***********************************************************************************
@@ -558,11 +564,11 @@
haystack.rotr(bale.length);
}
unittest {
- Stdout("\t.backpush(...) -----> ");
+ start(".backpush(...)");
auto foo = array!(int)(3, 4);
foo.backpush(1, 2);
assert(foo == array!(int)(1, 2, 3, 4));
- Stdout("Pass").cr;
+ stop();
}
/***********************************************************************************
@@ -576,12 +582,12 @@
return result;
}
unittest {
- Stdout("\t.backpop() ---------> ");
+ start(".backpop()");
auto foo = array!(int)(1, 2, 3);
auto elm = foo.backpop();
assert(foo == array!(int)(2, 3));
assert(elm == 1);
- Stdout("Pass").cr;
+ stop();
}
/***********************************************************************************
@@ -599,12 +605,12 @@
return result;
}
unittest {
- Stdout("\t.shift(N) ----------> ");
+ start(".shift(N)");
auto foo = array!(int)(1, 2, 3, 4, 5);
auto sub = foo.shift(3U);
assert(foo == array!(int)( 4, 5));
assert(sub == array!(int)(1, 2, 3 ));
- Stdout("Pass").cr;
+ stop();
}
/***********************************************************************************
@@ -625,12 +631,12 @@
return result;
}
unittest {
- Stdout("\t.rshift(N) ---------> ");
+ start(".rshift(N)");
auto foo = array!(int)(1, 2, 3, 4, 5);
auto sub = foo.rshift(3U);
assert(foo == array!(int)(1, 2 ));
assert(sub == array!(int)( 3, 4, 5));
- Stdout("Pass").cr;
+ stop();
}
/***********************************************************************************
@@ -697,7 +703,7 @@
return result;
}
unittest {
- Stdout("\t assoc([],[]) ------> ");
+ start(" assoc([],[])");
auto foo = assoc!(int, char)(
[ 65 , 66 , 67 , 68 , 69 ] ,
[cast(char) 'A', 'B', 'C', 'D', 'E']
@@ -705,12 +711,194 @@
assert(foo.keys == [ 65 , 66 , 67 , 68 , 69 ]);
assert(foo.values == [cast(char) 'A', 'B', 'C', 'D', 'E']);
assert(foo[65] == 'A' );
- Stdout("Pass").cr;
+ stop();
}
+/******************************************************************
+ * Joins a list of subarrays with the given separator in between
+ * each subarray. No leading or trailing separator will be included.
+ */
+T[] join (T) (T[][] words, T[] separator)
+{
+ T[] result;
+ foreach (T[] word; words)
+ {
+ result ~= word;
+ result ~= separator;
+ }
+ if (words.length > 0) return result[0..$-separator.length];
+ else return result;
+}
+
+unittest {
+ start(".join(T[])");
+ char[][] words = ["once"[],"upon","a","time"];
+ char[] separator = ". ";
+ assert(words.join(separator) == "once. upon. a. time");
+ stop();
+}
+
+/************************************************************************
+ * Splits an array into subarrays by the delimeters passed. At least one
+ * delimiter must be passed
+ */
+T[][] split (T) (T[] arr, T[] delim ...)
+in { assert (delim.length > 0, "Splitting with no delimiters is useless"); }
+body
+{
+ T[][] results;
+ T[] token;
+
+ foreach (i, x; arr)
+ {
+ if (delim.contains(x))
+ {
+ if (token.length > 0)
+ {
+ results ~= token;
+ token.length = 0;
+ }
+ }
+ else
+ {
+ token ~= x;
+ }
+ }
+ if (token.length > 0) results ~= token;
+ return results;
+}
+
+unittest {
+ start(".split(...)");
+
+ auto bar = "cashew casehew";
+ auto result2 = bar.split('s', 'h');
+ assert(result2 == array!(char[])("ca"[], "ew ca", "e", "ew"));
+ stop();
+}
+
+/*******************************************************************
+ * Splits an array into subarrays of a given size. All subarrays
+ * returned will have the given size, which means that some elements
+ * of the original array may not be returned
+ */
+T[][] splitLen (T) (T[] arr, size_t size)
+{
+ auto results = new T[][arr.length/size];
+ size_t wall = arr.length - size;
+ for (size_t i = 0, counter = 0; i <= wall; i += size, counter++)
+ {
+ results[counter] = arr[i..i+size];
+ }
+ return results;
+}
+
+unittest {
+ start(".splitLen(N)");
+
+ auto bar = "0123456789"[];
+ auto result = bar.splitLen(2u);
+ assert(result == cast(char[][])["01", "23", "45", "67", "89"]);
+ bar ~= "0";
+ auto result2 = bar.splitLen(2u);
+ assert(result2 == result);
+ stop();
+}
+
+/***********************************************************************
+ * Splits an array into subarrays of a given size. The last array will
+ * be shorter if necessary, in order to guarantee it will return all
+ * the elements of t.
+ */
+T[][] greedySplitLen (T) (T[] arr, size_t size)
+{
+ auto results = arr.splitLen(size);
+ auto resultsSize = results.length * size;
+ if (resultsSize < arr.length)
+ {
+ results ~= arr[resultsSize .. $];
+ }
+ return results;
+}
+
+unittest {
+ start(".greedySplitLen(N)");
+
+ auto bar = "0123456789"[];
+ assert(bar.greedySplitLen(2u) == array!(char[])("01"[], "23", "45", "67", "89"));
+ bar ~= "0";
+ assert(bar.greedySplitLen(2u) == array!(char[])("01"[], "23", "45", "67", "89", "0"));
+
+ stop();
+}
+
+/***************************************************************************
+ * Constructs an array by repeating a single element
+ */
+T[] repeat (T) (T needle, size_t len)
+{
+ auto haystack = new T[len];
+ haystack[] = needle;
+ return haystack;
+}
+unittest {
+ start(" repeat(T, N)");
+ auto foo = repeat(3, 4u);
+ assert (foo == [3, 3, 3, 3]);
+ stop();
+}
+
+/*******************************************************************************
+ * Constructs an array made from a repeated subarray.
+ */
+T[] repeatSub (T) (T[] bale, size_t count)
+{
+ auto haystack = new T[count * bale.length];
+ haystack.length = 0;
+ for (int i = 0; i < count; i++) {
+ haystack ~= bale;
+ }
+ return haystack;
+}
+
+unittest {
+ start (" repeatSub(T[], N)");
+ auto foo = repeatSub([4, 5], 3u);
+ assert (foo == [4, 5, 4, 5, 4, 5]);
+ stop();
+}
+
/***********************************************************************************
* Unit tests support.
*/
unittest {
- Stdout("Unittest: cashew.utils.array: end").cr.cr;
+ version(UsingPhobos) writefln("Unittest: cashew.util.array: end\n");
+ else Stdout("Unittest: cashew.utils.array: end").cr.cr;
+}
+
+version(Unittest)
+{
+/***********************************************************************************
+ * Shows 'func() ------------->' formatted so that they all line up nicely
+ */
+void start(char[] text)
+{
+ text = "\t" ~ text ~ " ";
+ int count = 30 - text.length;
+ assert (count > 0, "Function name, " ~ text ~ ", is too long to fit in line. Increase the magic number in the line above");
+ char[] output = new char[32];
+ output[0..text.length] = text;
+ output[text.length..$-2] = '-';
+ output[$-2..$] = "> ";
+ version (UsingPhobos) writef(output);
+ else Stdout(output);
+}
+/**********************************************************************************
+ * Prints "Pass\n" using the correct printer (either writefln or Stdout)
+ */
+void stop()
+{
+ version (UsingPhobos) writefln("Pass");
+ else Stdout("Pass").cr;
+}
}
\ No newline at end of file
|
|
|
Back to top |
|
|
csauls
Joined: 27 Mar 2004 Posts: 278
|
Posted: Fri Oct 20, 2006 3:26 pm Post subject: |
|
|
Not bad stuff. I'll try to work it into the next commit. Any opinion on the progress of the other bits? I admit to not having a lot of time to spend on Cashew, but I do try. (Suggestions for CashewCGI are especially welcome.) _________________ Chris Nicholson-Sauls |
|
Back to top |
|
|
csauls
Joined: 27 Mar 2004 Posts: 278
|
Posted: Sat Oct 21, 2006 10:54 am Post subject: |
|
|
Okay, here is what I did.
I incorporated your option for Phobos support in the unittests, which I'll later migrate to its own module and use it throughout Cashew. I made a few small changes, but I do like it.
I did already have an undocumented join() function which I had slapped in for myself a little bit back (I'm horrible) so I compared our algorithms, found them essentially the same, and just gave it its docs and unittest.
I used your split() algorithm, but had to add a .dup to the token when concat'ing it to the result. Otherwise the result just contained several copies of the last token. Merf. As much as I love D, little things like that still bite me now and then.
Added a precondition to splitLen() to block lengths of zero. I just can't imagine any case where that would make any sense! I also reworked the code a little bit to come up with something I feel is a bit cleaner. The spirit is preserved, however.
I did leave out your repeat()/repeatSub() rewrite. I'll ponder on that for a while. The one advantage yours has, though:
Code: |
// currently
int[] foo; foo.repeat(0, 32U);
// your version
int[] foo = repeat(0, 32U);
// possible abuse method to the current?
int[] foo = [0].repeat(0, 32U);
|
I did however modify them to use a 'new' array anytime the length would have changed, so they do look closer to your version though they still operate inline on an array. This should stay true to the original idea of keeping memory usage in mind. (I think I first envisioned buffers being primarily used with .repeat/.repeatSub.)
All that said, its all in the new commit. _________________ Chris Nicholson-Sauls |
|
Back to top |
|
|
reinerp
Joined: 08 Oct 2006 Posts: 4
|
Posted: Fri Oct 27, 2006 12:44 am Post subject: |
|
|
csauls wrote: | I used your split() algorithm, but had to add a .dup to the token when concat'ing it to the result. Otherwise the result just contained several copies of the last token. Merf. As much as I love D, little things like that still bite me now and then. |
Are you sure about that, because this code is fine, and the unittests still pass without the dup.
Code: | unittest
{
char[] a = "abc";
char[] b = "DE";
a ~= b;
b = "FG";
a ~= b;
assert(a == "abcDEFG");
}
|
Quote: | I did leave out your repeat()/repeatSub() rewrite. I'll ponder on that for a while. The one advantage yours has, though:
Code: |
// currently
int[] foo; foo.repeat(0, 32U);
// your version
int[] foo = repeat(0, 32U);
|
|
What happens if you have another function, though:
Code: | void doSomething(int[] ) {...} |
and you want to call it with [0,1,0,1,0,1,0,1]? You could write:
Code: |
// currently
int[] foo; foo.repeatSub([0, 1], 4u).doSomething();
// mine
repeatSub([0,1],4).doSomething();
|
Quote: | This should stay true to the original idea of keeping memory usage in mind. (I think I first envisioned buffers being primarily used with .repeat/.repeatSub.) |
If you want to do it inline, why not just use fill? The name is also more intuitive.
Cheers,
Reiner |
|
Back to top |
|
|
reinerp
Joined: 08 Oct 2006 Posts: 4
|
Posted: Fri Oct 27, 2006 1:05 am Post subject: |
|
|
csauls wrote: | I used your split() algorithm, but had to add a .dup to the token when concat'ing it to the result. Otherwise the result just contained several copies of the last token. Merf. As much as I love D, little things like that still bite me now and then. |
Are you sure about that, because this code is fine, and the unittests still pass without the dup.
Code: | unittest
{
char[] a = "abc";
char[] b = "DE";
a ~= b;
b = "FG";
a ~= b;
assert(a == "abcDEFG");
}
|
Quote: | I did leave out your repeat()/repeatSub() rewrite. I'll ponder on that for a while. The one advantage yours has, though:
Code: |
// currently
int[] foo; foo.repeat(0, 32U);
// your version
int[] foo = repeat(0, 32U);
|
|
What happens if you have another function, though:
Code: | void doSomething(int[] ) {...} |
and you want to call it with [0,1,0,1,0,1,0,1]? You could write:
Code: |
// currently
int[] foo; foo.repeatSub([0, 1], 4u).doSomething();
// mine
repeatSub([0,1],4).doSomething();
|
Quote: | This should stay true to the original idea of keeping memory usage in mind. (I think I first envisioned buffers being primarily used with .repeat/.repeatSub.) |
If you want to do it inline, why not just use fill? The name is also more intuitive.
Cheers,
Reiner |
|
Back to top |
|
|
csauls
Joined: 27 Mar 2004 Posts: 278
|
Posted: Fri Oct 27, 2006 7:55 am Post subject: |
|
|
On the subject of repeat*Sub(), you make a good point. What I'm going to do, however, is rename the current functions fillRepeat*Sub, then add your suggested functions. That way, one still has the inline option with repitition, for use with buffers. Good call.
On the subject of split(): I plugged your char[] unittest back in (I changed it to int[] just to be consistant with the rest of the module... doesn't matter, I don't guess) and added some debug output, and this was what I got:
Quote: |
Iteration: 1
Iteration: 2
Iteration: 3
token: 'ca'
split results:
0: 'ca'
Iteration: 4
token: ''
split results:
0: 'ca'
Iteration: 5
Iteration: 6
Iteration: 7
Iteration: 8
Iteration: 9
Iteration: 10
token: 'ew ca'
split results:
0: 'ew'
1: 'ew ca'
Iteration: 11
Iteration: 12
token: 'e'
split results:
0: 'ew'
1: 'ew ca'
2: 'e'
Iteration: 13
Iteration: 14
token: 'ew'
split results:
0: 'ew'
1: 'ew ca'
2: 'e'
3: 'ew'
|
So, for some reason a slice of token is ending up in 'result' instead of a copy. Hence my adding the explicit .dup to it. If you see some silly mistake on my part, please let me know. That .dup just feels unneccessary to me. _________________ Chris Nicholson-Sauls |
|
Back to top |
|
|
csauls
Joined: 27 Mar 2004 Posts: 278
|
Posted: Fri Oct 27, 2006 4:03 pm Post subject: |
|
|
Okay. New update in svn now.
The old .fill() has been renamed .fillSub() and a new .fill() written (these take the place of the old .repeat*Sub() functions). Your .repeat*Sub() have been integrated.
Also, I moved your nifty unittest framework into its own module (cashew.utils.utest) so I can use it throughout. Made some modifications to that end, but its essentially the same.
Third, I think I know why we're getting different results from .split(), or at least I have a theory. By any chance are you using DMD 0.169 or older? Apparently in the recent releases setting .length to 0 no longer reallocates the array. A nifty new 'feature' sure, but I wonder how many other people have written code that silently relies on the old behavior... oh well, it comes with using a pre-1.0 language I suppose. _________________ Chris Nicholson-Sauls |
|
Back to top |
|
|
reinerp
Joined: 08 Oct 2006 Posts: 4
|
Posted: Mon Oct 30, 2006 12:10 am Post subject: |
|
|
My mistake; my example above was actually irrelevant, and the bug wasn't caught in the unittest because I was using DMD 0.169. |
|
Back to top |
|
|
csauls
Joined: 27 Mar 2004 Posts: 278
|
Posted: Mon Oct 30, 2006 8:58 am Post subject: |
|
|
No worries; I'm just glad to have it sorted out. I was starting to worry it might be an OS distinction toward the negative. But no, just 'feature change'. Oh well... time to go looking for any other times I've used this in code... _________________ Chris Nicholson-Sauls |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|