redict/tests/unit
antirez f50e658455 SDIFF is now able to select between two algorithms for speed.
SDIFF used an algorithm that was O(N) where N is the total number
of elements of all the sets involved in the operation.

The algorithm worked like that:

ALGORITHM 1:

1) For the first set, add all the members to an auxiliary set.
2) For all the other sets, remove all the members of the set from the
auxiliary set.

So it is an O(N) algorithm where N is the total number of elements in
all the sets involved in the diff operation.

Cristobal Viedma suggested to modify the algorithm to the following:

ALGORITHM 2:

1) Iterate all the elements of the first set.
2) For every element, check if the element also exists in all the other
remaining sets.
3) Add the element to the auxiliary set only if it does not exist in any
of the other sets.

The complexity of this algorithm on the worst case is O(N*M) where N is
the size of the first set and M the total number of sets involved in the
operation.

However when there are elements in common, with this algorithm we stop
the computation for a given element as long as we find a duplicated
element into another set.

I (antirez) added an additional step to algorithm 2 to make it faster,
that is to sort the set to subtract from the biggest to the
smallest, so that it is more likely to find a duplicate in a larger sets
that are checked before the smaller ones.

WHAT IS BETTER?

None of course, for instance if the first set is much larger than the
other sets the second algorithm does a lot more work compared to the
first algorithm.

Similarly if the first set is much smaller than the other sets, the
original algorithm will less work.

So this commit makes Redis able to guess the number of operations
required by each algorithm, and select the best at runtime according
to the input received.

However, since the second algorithm has better constant times and can do
less work if there are duplicated elements, an advantage is given to the
second algorithm.
2012-11-30 16:36:42 +01:00
..
type SDIFF is now able to select between two algorithms for speed. 2012-11-30 16:36:42 +01:00
aofrw.tcl Tests modified to account for INFO fields renaming. 2012-05-25 15:20:59 +02:00
auth.tcl Fix for issue #132. Now AUTH raises an error if no server password is configured. 2011-10-10 22:21:17 +02:00
basic.tcl Type mismatch errors are now prefixed with WRONGTYPE. 2012-11-06 20:25:34 +01:00
bitops.tcl Type mismatch errors are now prefixed with WRONGTYPE. 2012-11-06 20:25:34 +01:00
dump.tcl Test: more MIGRATE tests. 2012-11-14 12:12:52 +01:00
expire.tcl TTL API change: TTL returns -2 for non existing keys. 2012-11-12 23:04:36 +01:00
introspection.tcl Tests for MONITOR. 2012-04-07 11:26:24 +02:00
limits.tcl More robust maxclients test. 2012-04-18 11:34:18 +02:00
maxmemory.tcl Maxmemory test 2011-07-28 12:32:52 +02:00
multi.tcl Make an EXEC test more latency proof. 2012-11-29 16:12:14 +01:00
obuf-limits.tcl even less false positive on obuf-limits test. 2012-02-22 11:25:30 +01:00
other.tcl Test: MULTI/EXEC tests moved into multi.tcl. 2012-11-22 10:32:12 +01:00
printver.tcl Print version info before running the test 2011-05-20 11:44:54 +02:00
protocol.tcl New time limit for protocol desync test set to 30 seconds to reduce false positives. 2012-04-23 10:57:43 +02:00
pubsub.tcl more pub/sub tests 2010-06-16 11:03:23 +02:00
quit.tcl Add tests for OK on QUIT 2010-10-15 12:54:53 +02:00
scripting.tcl EVALSHA is now case insensitive. 2012-11-22 15:50:00 +01:00
slowlog.tcl Limit memory used by big SLOWLOG entries. 2012-04-21 20:34:45 +02:00
sort.tcl "SORT by nosort" (skip sorting) respect sorted set ordering. 2012-10-03 14:54:43 +02:00