天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 83|回复: 0

【lisp】Interval Tree 区间树

[复制链接]
  • TA的每日心情
    开心
    2024-8-31 15:58
  • 签到天数: 89 天

    [LV.6]常住居民II

    488

    主题

    207

    回帖

    3366

    积分

    管理员

    积分
    3366
    发表于 2024-6-22 09:46:18 | 显示全部楼层 |阅读模式
    区间树

    考虑这样一种情况,我们有一组间隔,并且我们需要有效地执行以下操作。
    1) 加一个间隔
    2) 取消间隔
    3) 给定一个区间x,查找x是否与任何现有区间重叠。


    [code];;;http://www.theswamp.org/index.php?topic=49783.msg549758#msg549758
    (defun c:tt()

    (setq startIntervalLst
      '(
        ((0)     (15 20) 40)
        ((0 0)   (10 30) 30)
        ((0 0 0) ( 5 20) 20)
        ((0 0 1) (12 15) 15)
        ((0 1)   (17 19) 40)
        ((0 1 1) (30 40) 40)
      )
    )
    (setq intervalLst startIntervalLst)
    (setq intervalLst (IntervalTreeAdd intervalLst '(3 8) '(0)))
      )

    ;;;(
    ;;;  ((0 0 0 0) (3 8) 8)
    ;;;  ((0) (15 20) 40)
    ;;;  ((0 0) (10 30) 30)
    ;;;  ((0 0 0) (5 20) 20)
    ;;;  ((0 0 1) (12 15) 15)
    ;;;  ((0 1) (17 19) 40)
    ;;;  ((0 1 1) (30 40) 40)
    ;;;  )

      

    ; (setq intervalLst startIntervalLst)
    ; (setq intervalLst (IntervalTreeAdd intervalLst '(3 8) '(0)))
    (defun IntervalTreeAdd (intervalLst interval node / nodeLst)
      (if (setq nodeLst (assoc node intervalLst))
        (progn
          (if (< (caddr nodeLst) (cadr interval))
            (setq intervalLst
              (subst
                (list node (cadr nodeLst) (cadr interval)) ; New max value.
                nodeLst
                intervalLst
              )
            )
          )
          (IntervalTreeAdd
            intervalLst
            interval
            (append node (if (<= (car interval) (caadr nodeLst)) '(0) '(1))) ; Left or right branch.
          )
        )
        (cons
          (list node interval (cadr interval))
          intervalLst
        )
      )
    )

    ; (IntervalTreeOverlap intervalLst '(3 8) '(0)) nil
    ; Return value: first overlap found.
    (defun IntervalTreeOverlap (intervalLst interval node / nodeLst)
      (if (setq nodeLst (assoc node intervalLst))
        (cond
          ((> (car interval) (caddr nodeLst))
            nil
          )
          ((IntervalOverlap_P interval (cadr nodeLst))
            (cadr nodeLst)
          )
          ((IntervalTreeOverlap intervalLst interval (append node '(0)))
          )
          ((IntervalTreeOverlap intervalLst interval (append node '(1)))
          )
        )
      )
    )

    ; (IntervalOverlap_P '(1 5) '(3 8)) T
    (defun IntervalOverlap_P (intervalA intervalB / staA endA staB endB)
      (setq staA (car intervalA))
      (setq endA (cadr intervalA))
      (setq staB (car intervalB))
      (setq endB (cadr intervalB))
      (or
        (<= staA staB endA)
        (<= staA endB endA)
        (<= staB staA endB)
        (<= staB endA endB)
      )
    )[/code]

     

     

     

     

    【lisp】Interval Tree 区间树
    中国膜结构网打造全中国最好的膜结构综合平台 ,统一协调膜结构设计,膜结构施工,膜材采购,膜材定制,膜结构预算全方位服务。 中国空间膜结构协会合作单位。
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|Archiver|手机版|中国膜结构网|中国膜结构协会|进口膜材|国产膜材|ETFE|PVDF|PTFE|设计|施工|安装|车棚|看台|污水池| |网站地图

    GMT+8, 2024-9-8 10:43 , Processed in 0.064445 second(s), 26 queries .

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

    快速回复 返回顶部 返回列表