UUID Sorting Incorrect

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

UUID Sorting Incorrect

Runar Jordahl
Class UUID is included in beta in VisualWorks 7.8. It seems like #< is
implemented incorrect. If you evaluate the statement below it answers
true:

|a b|
a := UUID fromString: '0608b9dc-02e4-4dd0-9f8a-ea45160df641'.
b := UUID fromString: 'e85ae7ba-3ca3-4bae-9f62-cc2ce51c525e'.
(a > b) = (b > a)

The fix is to change the method to this:

< aMagnitude
        "Answer whether the receiver is less than the argument.  Add an
initial size check, in anticipation of greater than 128-bit
Smalltalk-specific UUID type."

        | ss ms |

        ss := self size.
        ms := aMagnitude size.
        ss < ms
                ifTrue: [^true]
                ifFalse: [
                        ss > ms
                                ifTrue: [^false]
                                ifFalse: [
                                        1 to: self size do: [:i |
                                                (self at: i) < (aMagnitude at: i) ifTrue: [^true].
                                                (self at: i) > (aMagnitude at: i) ifTrue: [^false]].
                                        ^false]]


Runar Jordahl
blog.epigent.com
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: UUID Sorting Incorrect

Alan Knight-2
Thanks. Created AR 64162



[hidden email]
25 October, 2011 7:13 AM


Class UUID is included in beta in VisualWorks 7.8. It seems like #< is
implemented incorrect. If you evaluate the statement below it answers
true:

|a b|
a := UUID fromString: '0608b9dc-02e4-4dd0-9f8a-ea45160df641'.
b := UUID fromString: 'e85ae7ba-3ca3-4bae-9f62-cc2ce51c525e'.
(a > b) = (b > a)

The fix is to change the method to this:

< aMagnitude
"Answer whether the receiver is less than the argument. Add an
initial size check, in anticipation of greater than 128-bit
Smalltalk-specific UUID type."

| ss ms |

ss := self size.
ms := aMagnitude size.
ss < ms
ifTrue: [^true]
ifFalse: [
ss > ms
ifTrue: [^false]
ifFalse: [
1 to: self size do: [:i |
(self at: i) < (aMagnitude at: i) ifTrue: [^true].
(self at: i) > (aMagnitude at: i) ifTrue: [^false]].
^false]]


Runar Jordahl
blog.epigent.com
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc