[ Usenet FAQs | Search | Web FAQs | Documents | RFC Index ]
    Search the FAQ Archives

Part1 - Part2 - Single Page

Top Document: comp.cad.autocad AutoLISP FAQ (part 1/2) - general
Previous Document: [7] AutoLISP problems and bugs
Next Document: [9] Recursion


[8] Sorting with AutoLISP


  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)



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 | Search | Web FAQs | Documents | RFC Index ]

Send corrections/additions to the FAQ Maintainer:
rurban@xarch.tu-graz.ac.at (Reini Urban)

Last Update July 25 2008 @ 00:10 AM

© 2008 FAQS.ORG. All rights reserved.