From aedac205ea3925dd2810105ccea8c327c7f41259 Mon Sep 17 00:00:00 2001 From: tchernobog Date: Fri, 8 Sep 2006 15:09:36 +0000 Subject: [PATCH] - Add a warning about quicksort being stable only with some operators git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@1066 3ecf2c5c-341e-0410-92b4-d18e462d057c --- plugins/pyloader/src/CPUPolicy.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/pyloader/src/CPUPolicy.py b/plugins/pyloader/src/CPUPolicy.py index 3204da3..ce37660 100644 --- a/plugins/pyloader/src/CPUPolicy.py +++ b/plugins/pyloader/src/CPUPolicy.py @@ -109,11 +109,11 @@ class CPUPolicy: # @code # # As a lambda anonymous function (preferred) # # (x and y are two DynamicSchedulable objects) - # cmpf = lambda x,y: x.someProperty() < y.someProperty() + # cmpf = lambda x,y: x.someProperty() <= y.someProperty() # # # As a normal *global* function # def compare(a,b): - # return a.someProperty < b.someProperty() + # return a.someProperty <= b.someProperty() # cmpf = compare # @endcode # @@ -124,6 +124,12 @@ class CPUPolicy: # self.sort(queue, cmpf) # @endcode # + # Since queue.sort() uses a in-place version of the + # quicksort algorithm, note the effect of using "<" + # instead than "<=": quicksort wouldn't be stable anymore. + # You have been warned. If your policy behaves strangely, + # this may be the cause. + # # @param self The object caller # @param queue The ReadyQueue to be sorted in place # @param cmpf The binary function to use to compare elements