Author Topic: Fast search pairing algorithm  (Read 576 times)

0 Members and 1 Guest are viewing this topic.

well20152016

  • Newt
  • Posts: 78
Fast search pairing algorithm
« on: October 18, 2017, 08:09:06 PM »
Code - Auto/Visual Lisp: [Select]
  1. (setq l1(list (list '(89 1)'(99 3)'(45 4)'(67 7)'(54 5)'(33 3)) "A"))
  2. (setq l2(list (list '(39 1)'(33 9)'(27 1)'(84 8)'(13 7)'(99 5)) "B")
  3. Result:
  4.        (setq l3 (list (list '('(99 3)'(33 3)) "A")
  5.                          (list '('(99 5)'(33 9)) "B")
  6.                        ))

ribarm

  • Water Moccasin
  • Posts: 2122
  • Marko Ribar, architect
Re: Fast search pairing algorithm
« Reply #1 on: October 19, 2017, 04:27:36 AM »
Quick and perhaps slow...

Code - Auto/Visual Lisp: [Select]
  1. (defun foo ( l1 l2 / x2 l31 l32 l3 )
  2.   (foreach x1 (car l1)
  3.     (if (setq x2 (assoc (car x1) (car l2)))
  4.       (setq l31 (cons x1 l31) l32 (cons x2 l32))
  5.     )
  6.   )
  7.   (setq l31 (reverse l31) l32 (reverse l32))
  8.   (setq l3 (list (list l31 (cadr l1)) (list l32 (cadr l2))))
  9.   l3
  10. )
  11.  
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

well20152016

  • Newt
  • Posts: 78
Re: Fast search pairing algorithm
« Reply #2 on: October 19, 2017, 10:24:33 AM »
Code - Auto/Visual Lisp: [Select]
  1. (defun foo1 ( l1 l2 / a1 b1)
  2. (setq a1 (vl-remove-if-not '(lambda (x) (assoc (car x) (car l2))) (car l1)))
  3. (setq b1 (vl-remove-if-not '(lambda (x) (assoc (car x) a1))       (car l2)))
  4. (list (list (vl-sort a1 '(lambda (e1 e2)(< (car e1)(car e2)))) (cadr l1))
  5.       (list (vl-sort b1 '(lambda (e1 e2)(< (car e1)(car e2)))) (cadr l2)))
  6. )
« Last Edit: October 19, 2017, 10:35:08 PM by well20152016 »

roy_043

  • Water Moccasin
  • Posts: 1710
  • BricsCAD 18
Re: Fast search pairing algorithm
« Reply #3 on: October 19, 2017, 01:23:57 PM »
Well no need for a benchmark test I think. Marko's code must be faster.