Re: [lisp-snmp] Memory usage of ASN.1 library
Brought to you by:
binghe
From: Chun T. (binghe) <bin...@gm...> - 2009-05-01 05:57:47
|
Your version equal to this one: (and it works) (defun oid-< (oid-1 oid-2) "test if oid-1 is oid-2's child" (unless (<= (oid-length oid-1) (oid-length oid-2)) (loop for x-1 in (oid-number-list oid-1) for x-2 in (oid-number-list oid-2) always (= x-1 x-2)))) I'm so stupid in this function ... :) Thank you, I'll commit it as ASN.1 4.16 and into trunk. --binghe 在 2009-5-1,13:47, John Fremlin 写道: > "Chun Tian (binghe)" <bin...@gm...> writes: > >> Great! >> >> And, please use my more updated version of ASN.1:OID-< as a work >> base: > > Sorry, I already made a new version, is it okay? > > (defun oid-< (oid-1 oid-2) > "test if oid-1 is oid-2's child" > (let ((o-1 (oid-number-list oid-1)) > (o-2 (oid-number-list oid-2)) > (o-1-len (oid-length oid-1)) > (o-2-len (oid-length oid-2))) > (unless (<= o-1-len o-2-len) > (loop for x-1 in o-1 > for x-2 in o-2 > always (equal x-1 x-2))))) > > In the old version with O(n) lengths this is suboptimal but in the new > version with O(1) lengths we are better off with checking the length > first > >> >> (defun oid-< (oid-1 oid-2) >> "test if oid-1 is oid-2's child" >> (let ((o-1-len (oid-length oid-1)) >> (o-2-len (oid-length oid-2))) >> (if (<= o-1-len o-2-len) nil >> (let ((o-1 (reverse (oid-number-list oid-1))) >> (o-2 (reverse (oid-number-list oid-2)))) >> (equal o-2 (nthcdr (- o-1-len o-2-len) o-1)))))) >> >> I believe it's more sufficient than before. > > if test nil else === unless test else > > [...] > |