Re: Interval list
- From: Madhu <enometh@xxxxxxxx>
- Date: Fri, 05 Jan 2007 13:47:17 +0530
* "Geoffrey Summerhayes" <1166641110.485574.241490@xxxxxxxxxxxxxxxxxxxxxx> :
|
| The general idea is for the new interval to overwrite the entries
| in the current list.
|
| The list is sorted on 'from' consisting of (from attributes)
| with the next entry in the list indicating the end of the interval.
| Somewhat akin to run-length encoding.
|
| Precondition (start<end)
|
| Works AFAICT, but is there a better way?
Finally got around to using LOOP to figure out a worse way :)
(defun insert-interval (list start end new-attribs)
(loop with x ;X is non nil if we are inside the new interval
for (a b . rest) on list
for (from . attribs) = a and (to) = b
if (<= from start to)
do (assert (null x)) (setq x t)
and if (< from start) collect a end
and collect (cons start new-attribs)
else unless x collect a
if (<= from end to)
do (assert x)
and if (< end to) collect (cons end attribs) and do (setq x nil) end
if (endp rest) unless x collect b else collect (list end)
while rest))
[lightly tested. Does it meet your spec?]
--
Madhu
.
- Follow-Ups:
- Re: Interval list
- From: Geoffrey Summerhayes
- Re: Interval list
- Prev by Date: Re: bad-idea-p?
- Next by Date: Re: bad-idea-p?
- Previous by thread: Defining class methods in CLOS
- Next by thread: Re: Interval list
- Index(es):
Relevant Pages
|
|