mirror of
https://github.com/dlang/phobos.git
synced 2025-04-29 14:40:30 +03:00
Delete 6-year-old dead code.
This commit is contained in:
parent
3fb23fa606
commit
2f0b36f8e4
1 changed files with 0 additions and 271 deletions
|
@ -384,277 +384,6 @@ unittest
|
|||
assert(b == [ cast(ubyte) 0, cast(ubyte)2, cast(ubyte)1, cast(ubyte)6, cast(ubyte)5], text(b));
|
||||
}
|
||||
}
|
||||
/+
|
||||
|
||||
// topNIndexImpl
|
||||
// @@@BUG1904
|
||||
/*private*/ void topNIndexImpl(
|
||||
alias less,
|
||||
bool sortAfter,
|
||||
SwapStrategy ss,
|
||||
SRange, TRange)(SRange source, TRange target)
|
||||
{
|
||||
alias lessFun = binaryFun!(less);
|
||||
static assert(ss == SwapStrategy.unstable,
|
||||
"Stable indexing not yet implemented");
|
||||
alias SIter = Iterator!(SRange);
|
||||
alias TElem = std.iterator.ElementType!(TRange);
|
||||
enum usingInt = isIntegral!(TElem);
|
||||
|
||||
static if (usingInt)
|
||||
{
|
||||
enforce(source.length <= TElem.max,
|
||||
"Numeric overflow at risk in computing topNIndexImpl");
|
||||
}
|
||||
|
||||
// types and functions used within
|
||||
SIter index2iter(TElem a)
|
||||
{
|
||||
static if (!usingInt)
|
||||
return a;
|
||||
else
|
||||
return begin(source) + a;
|
||||
}
|
||||
bool indirectLess(TElem a, TElem b)
|
||||
{
|
||||
return lessFun(*index2iter(a), *index2iter(b));
|
||||
}
|
||||
void indirectCopy(SIter from, ref TElem to)
|
||||
{
|
||||
static if (!usingInt)
|
||||
to = from;
|
||||
else
|
||||
to = cast(TElem)(from - begin(source));
|
||||
}
|
||||
|
||||
// copy beginning of collection into the target
|
||||
auto sb = begin(source), se = end(source),
|
||||
tb = begin(target), te = end(target);
|
||||
for (; sb != se; ++sb, ++tb)
|
||||
{
|
||||
if (tb == te) break;
|
||||
indirectCopy(sb, *tb);
|
||||
}
|
||||
|
||||
// if the index's size is same as the source size, just quicksort it
|
||||
// otherwise, heap-insert stuff in it.
|
||||
if (sb == se)
|
||||
{
|
||||
// everything in source is now in target... just sort the thing
|
||||
static if (sortAfter) sort!(indirectLess, ss)(target);
|
||||
}
|
||||
else
|
||||
{
|
||||
// heap-insert
|
||||
te = tb;
|
||||
tb = begin(target);
|
||||
target = range(tb, te);
|
||||
makeHeap!(indirectLess)(target);
|
||||
// add stuff to heap
|
||||
for (; sb != se; ++sb)
|
||||
{
|
||||
if (!lessFun(*sb, *index2iter(*tb))) continue;
|
||||
// copy the source over the smallest
|
||||
indirectCopy(sb, *tb);
|
||||
heapify!(indirectLess)(target, tb);
|
||||
}
|
||||
static if (sortAfter) sortHeap!(indirectLess)(target);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
topNIndex
|
||||
*/
|
||||
void topNIndex(
|
||||
alias less,
|
||||
SwapStrategy ss = SwapStrategy.unstable,
|
||||
SRange, TRange)(SRange source, TRange target)
|
||||
{
|
||||
return .topNIndexImpl!(less, false, ss)(source, target);
|
||||
}
|
||||
|
||||
/// Ditto
|
||||
void topNIndex(
|
||||
string less,
|
||||
SwapStrategy ss = SwapStrategy.unstable,
|
||||
SRange, TRange)(SRange source, TRange target)
|
||||
{
|
||||
return .topNIndexImpl!(binaryFun!(less), false, ss)(source, target);
|
||||
}
|
||||
|
||||
// partialIndex
|
||||
/**
|
||||
Computes an index for $(D source) based on the comparison $(D less)
|
||||
and deposits the result in $(D target). It is acceptable that $(D
|
||||
target.length < source.length), in which case only the smallest $(D
|
||||
target.length) elements in $(D source) get indexed. The target
|
||||
provides a sorted "view" into $(D source). This technique is similar
|
||||
to sorting and partial sorting, but it is more flexible because (1) it
|
||||
allows "sorting" of immutable collections, (2) allows binary search
|
||||
even if the original collection does not offer random access, (3)
|
||||
allows multiple indexes, each on a different comparison criterion, (4)
|
||||
may be faster when dealing with large objects. However, using an index
|
||||
may also be slower under certain circumstances due to the extra
|
||||
indirection, and is always larger than a sorting-based solution
|
||||
because it needs space for the index in addition to the original
|
||||
collection. The complexity is $(BIGOH source.length *
|
||||
log(target.length)).
|
||||
|
||||
Two types of indexes are accepted. They are selected by simply passing
|
||||
the appropriate $(D target) argument: $(OL $(LI Indexes of type $(D
|
||||
Iterator!(Source)), in which case the index will be sorted with the
|
||||
predicate $(D less(*a, *b));) $(LI Indexes of an integral type
|
||||
(e.g. $(D size_t)), in which case the index will be sorted with the
|
||||
predicate $(D less(source[a], source[b])).))
|
||||
|
||||
Example:
|
||||
|
||||
----
|
||||
immutable arr = [ 2, 3, 1 ];
|
||||
int* index[3];
|
||||
partialIndex(arr, index);
|
||||
assert(*index[0] == 1 && *index[1] == 2 && *index[2] == 3);
|
||||
assert(isSorted!("*a < *b")(index));
|
||||
----
|
||||
*/
|
||||
void partialIndex(
|
||||
alias less,
|
||||
SwapStrategy ss = SwapStrategy.unstable,
|
||||
SRange, TRange)(SRange source, TRange target)
|
||||
{
|
||||
return .topNIndexImpl!(less, true, ss)(source, target);
|
||||
}
|
||||
|
||||
unittest
|
||||
{
|
||||
debug(std_algorithm) scope(success)
|
||||
writeln("unittest @", __FILE__, ":", __LINE__, " done.");
|
||||
immutable arr = [ 2, 3, 1 ];
|
||||
auto index = new immutable(int)*[3];
|
||||
partialIndex!(binaryFun!("a < b"))(arr, index);
|
||||
assert(*index[0] == 1 && *index[1] == 2 && *index[2] == 3);
|
||||
assert(isSorted!("*a < *b")(index));
|
||||
}
|
||||
|
||||
unittest
|
||||
{
|
||||
debug(std_algorithm) scope(success)
|
||||
writeln("unittest @", __FILE__, ":", __LINE__, " done.");
|
||||
static bool less(int a, int b) { return a < b; }
|
||||
{
|
||||
string[] x = ([ "c", "a", "b", "d" ]).dup;
|
||||
// test with integrals
|
||||
auto index1 = new size_t[x.length];
|
||||
partialIndex!(q{a < b})(x, index1);
|
||||
assert(index1[0] == 1 && index1[1] == 2 && index1[2] == 0
|
||||
&& index1[3] == 3);
|
||||
// half-sized
|
||||
index1 = new size_t[x.length / 2];
|
||||
partialIndex!(q{a < b})(x, index1);
|
||||
assert(index1[0] == 1 && index1[1] == 2);
|
||||
|
||||
// and with iterators
|
||||
auto index = new string*[x.length];
|
||||
partialIndex!(q{a < b})(x, index);
|
||||
assert(isSorted!(q{*a < *b})(index));
|
||||
assert(*index[0] == "a" && *index[1] == "b" && *index[2] == "c"
|
||||
&& *index[3] == "d");
|
||||
}
|
||||
|
||||
{
|
||||
immutable arr = [ 2, 3, 1 ];
|
||||
auto index = new immutable(int)*[arr.length];
|
||||
partialIndex!(less)(arr, index);
|
||||
assert(*index[0] == 1 && *index[1] == 2 && *index[2] == 3);
|
||||
assert(isSorted!(q{*a < *b})(index));
|
||||
}
|
||||
|
||||
// random data
|
||||
auto b = rndstuff!(string)();
|
||||
auto index = new string*[b.length];
|
||||
partialIndex!((a, b) => std.uni.toUpper(a) < std.uni.toUpper(b))(b, index);
|
||||
assert(isSorted!((a, b) => std.uni.toUpper(*a) < std.uni.toUpper(*b))(index));
|
||||
|
||||
// random data with indexes
|
||||
auto index1 = new size_t[b.length];
|
||||
bool cmp(string x, string y) { return std.uni.toUpper(x) < std.uni.toUpper(y); }
|
||||
partialIndex!(cmp)(b, index1);
|
||||
bool check(size_t x, size_t y) { return std.uni.toUpper(b[x]) < std.uni.toUpper(b[y]); }
|
||||
assert(isSorted!(check)(index1));
|
||||
}
|
||||
|
||||
// Commented out for now, needs reimplementation
|
||||
|
||||
// // schwartzMakeIndex
|
||||
// /**
|
||||
// Similar to $(D makeIndex) but using $(D schwartzSort) to sort the
|
||||
// index.
|
||||
|
||||
// Example:
|
||||
|
||||
// ----
|
||||
// string[] arr = [ "ab", "c", "Ab", "C" ];
|
||||
// auto index = schwartzMakeIndex!(toUpper, less, SwapStrategy.stable)(arr);
|
||||
// assert(*index[0] == "ab" && *index[1] == "Ab"
|
||||
// && *index[2] == "c" && *index[2] == "C");
|
||||
// assert(isSorted!("toUpper(*a) < toUpper(*b)")(index));
|
||||
// ----
|
||||
// */
|
||||
// Iterator!(Range)[] schwartzMakeIndex(
|
||||
// alias transform,
|
||||
// alias less,
|
||||
// SwapStrategy ss = SwapStrategy.unstable,
|
||||
// Range)(Range r)
|
||||
// {
|
||||
// alias Iter = Iterator!(Range);
|
||||
// auto result = new Iter[r.length];
|
||||
// // assume collection already ordered
|
||||
// size_t i = 0;
|
||||
// foreach (it; begin(r) .. end(r))
|
||||
// {
|
||||
// result[i++] = it;
|
||||
// }
|
||||
// // sort the index
|
||||
// alias Transformed = typeof(transform(*result[0]));
|
||||
// static bool indirectLess(Transformed a, Transformed b)
|
||||
// {
|
||||
// return less(a, b);
|
||||
// }
|
||||
// static Transformed indirectTransform(Iter a)
|
||||
// {
|
||||
// return transform(*a);
|
||||
// }
|
||||
// schwartzSort!(indirectTransform, less, ss)(result);
|
||||
// return result;
|
||||
// }
|
||||
|
||||
// /// Ditto
|
||||
// Iterator!(Range)[] schwartzMakeIndex(
|
||||
// alias transform,
|
||||
// string less = q{a < b},
|
||||
// SwapStrategy ss = SwapStrategy.unstable,
|
||||
// Range)(Range r)
|
||||
// {
|
||||
// return .schwartzMakeIndex!(
|
||||
// transform, binaryFun!(less), ss, Range)(r);
|
||||
// }
|
||||
|
||||
// version (wyda) unittest
|
||||
// {
|
||||
// string[] arr = [ "D", "ab", "c", "Ab", "C" ];
|
||||
// auto index = schwartzMakeIndex!(toUpper, "a < b",
|
||||
// SwapStrategy.stable)(arr);
|
||||
// assert(isSorted!(q{toUpper(*a) < toUpper(*b)})(index));
|
||||
// assert(*index[0] == "ab" && *index[1] == "Ab"
|
||||
// && *index[2] == "c" && *index[3] == "C");
|
||||
|
||||
// // random data
|
||||
// auto b = rndstuff!(string)();
|
||||
// auto index1 = schwartzMakeIndex!(toUpper)(b);
|
||||
// assert(isSorted!("toUpper(*a) < toUpper(*b)")(index1));
|
||||
// }
|
||||
|
||||
+/
|
||||
|
||||
// Internal random array generators
|
||||
version(unittest)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue