|
Top Document: comp.cad.autocad AutoLISP FAQ (part 1/2) - general Previous Document: [7] AutoLISP problems and bugs Next Document: [9] Recursion See reader questions & answers on this topic! - Help others by sharing your knowledge
In short: use VL-SORT (generic) or ACAD_STRLSORT (strings only),
but beware: VL-SORT removes duplicate entries (which are EQ)!
I've set up a AutoLISP sort overview at
http://xarch.tu-graz.ac.at/autocad/lisp/#sort
In LISP the mostly used sort method is merge sort (also used in
(str-sort) in AutoDesk's TABLES.LSP sample) because that's a natural
method for linked lists. Normally (e.g. in C) you use heap sort (for
any data) or qsort (for random data) and insertion sort for the small
lists (< 7) or sublists within the algorithm.
There is a LISP code for shell-sort, bubble-sort, insertion-sort,
quick-sort available for any data, lists of lists and indeces to
lists. In LISP you can pass the predicate function to sort which is
evaluated at run-time (here called 'method'). That's why you need
only one sort function for multiple data types (i.e. numbers,
points on x or y, strings, ...)
(sort data method) ;method: less-than-predicate
;default for numbers: '<
Some sample timings from
http://xarch.tu-graz.ac.at/autocad/lisp/sort/ur_sort.lsp
sorting 100 elements:
bubble sort : 13.639008 sec/ 30.08%
insertion sort: 13.368042 sec/ 29.48% (fast for sorted lists)
shell sort : 13.478973 sec/ 29.73% (poor implementation)
merge sort : 2.232971 sec/ 4.92%
quick sort : 2.433960 sec/ 5.37%
vl-sort : 0.099976 sec/ 0.22% (Visual/Vital LISP internal)
acad_strlsort : 0.089996 sec/ 0.20% (AutoLISP internal, strings)
User Contributions:Top Document: comp.cad.autocad AutoLISP FAQ (part 1/2) - general Previous Document: [7] AutoLISP problems and bugs Next Document: [9] Recursion Part1 - Part2 - Single Page [ Usenet FAQs | Web FAQs | Documents | RFC Index ] Send corrections/additions to the FAQ Maintainer: rurban@xarch.tu-graz.ac.at (Reini Urban)
Last Update March 27 2014 @ 02:11 PM
|

Comment about this article, ask questions, or add new information about this topic: