Here is some code sorting various array types. ////////////// // farray sort (purely functional) var fa = 3,2,1, 99, 78; var fb = sort fa; println$ "farray",fa,fb;
// farray sort, using pointer (in place) var ca = fa; var cb = &ca; sort cb; println$ "&farray", fa, *cb; // carray sort (in place) var xa = fa; var bxa = stl_begin (&xa); var exa = stl_end (&xa); Sort::stl_sort (bxa, exa); println$ "carray", fa, xa; // in place varray sort var va = varray fa; var vb = varray va; sort vb; println$ "varray",va, vb; // in place darray sort var da = darray fa; var db = darray da; sort db; println$ "darray",da,db; ////////////// Here, an array (farray = fixed length array) is an immutable value so the sort is functional. Carray isn't an array as such, since the length isn't known, so we use STL iterators to sort it. varray and darray sort in place because they're objects. [Note to self: we need to check how to copy arrays and make sure constructors don't confuse copying an array with making an array of one object, which, by mistake, happens to be an array! Consistent notation required!] Now we come to the sparse arrays. An sarray is conceptually infinite. However it has a fixed starting index, namely 0. If the default value, which is normally 0.0 for a sparse array of double, is greater than all other elements (meaning they're all negative for the default double case) then we can sort the array, otherwise we can't (because there would be an infinite number of zeros before any non-zero elements). If we have a sparse array with negative indices, however, we could do it. In fact we could set index 0 to 0.0, and sort the positive values at positive indicies and negative at negative. It's not entirely clear to me what use this would be: a sparse array is basically a distribution, and really the integer indices are a hack. A bounded sparse array could be sorted. It makes logical sense, and it would be efficient (only the non-zero values would be sorted physically). But again, I'm not sure what it would mean. Other operations: if we're sorting, finding min and max make sense too. in fact there are a huge number of things you can do with arrays! -- john skaller skal...@users.sourceforge.net http://felix-lang.org ------------------------------------------------------------------------------ LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial Remotely access PCs and mobile devices and provide instant support Improve your efficiency, and focus on delivering more value-add services Discover what IT Professionals Know. Rescue delivers http://p.sf.net/sfu/logmein_12329d2d _______________________________________________ Felix-language mailing list Felix-language@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/felix-language