📄 seq_node.htm
字号:
<title>Commented source code for BTPSEQ</title><h2>Commented source code for <tt>BTPSEQ</tt></h2><pre> C.BTPSEQ001 SUBROUTINE BTPSEQ(BFILE,NODE.ID,NODE.POS,PN,ADJKEY)002 * Find prev or next key in B-tree with nodes in following format:003 * AMC 0: Arbitrary node number.004 * AMC 1: Count of keys in node.005 * AMC 2: Keys, stored as a subvalue list.006 * AMC 3: (number of keys)+1 pointers to next nodes.007 * AMC 4: Pointer to parent if any.008 PREV = (PN="PREV") ;* Set direction flag009 IF PREV THEN PTR=NODE.POS ELSE PTR=NODE.POS+1010 READ NODE FROM BFILE, NODE.ID ELSE STOP "Can't find node"011 ORIG.ID = NODE<2,NODE.POS> ;* Remember for when we hit leaf012 100 NEXT.NODE.ID = NODE<3, PTR> ;* Get id of next node013 IF NEXT.NODE.ID # "" THEN ;* There's another node, keep looking for leaf014 NODE.ID = NEXT.NODE.ID015 READ NODE FROM BFILE, NODE.ID ELSE STOP016 IF PREV THEN PTR=NODE<1>+1 ELSE PTR=1017 GO TO 100018 END019 * Reached a leaf, is it also the one with the key?020 IF NODE<2, NODE.POS> # ORIG.ID THEN ;* No, this leaf has the adjacent key021 IF PREV THEN NODE.POS = NODE<1> ELSE NODE.POS = 1022 ADJKEY = NODE<2,NODE.POS>023 RETURN024 END025 IF PREV AND (NODE.POS > 1) THEN ;* Yes, prev key is right alongside026 NODE.POS=NODE.POS-1027 ADJKEY = NODE<2,NODE.POS>028 RETURN029 END030 IF NOT(PREV) AND (NODE.POS < NODE<1>) THEN ;* Yes, alongside031 NODE.POS=NODE.POS+1032 ADJKEY = NODE<2,NODE.POS> ;* Get adjacent key033 RETURN034 END035 200 * We're at one end of a node, adjacent key is some parent036 PARENT.ID = NODE<4>037 IF PARENT.ID # "" THEN ;* Parent exists038 READ PARENT FROM BFILE, PARENT.ID ELSE STOP "Can't reread"039 LOCATE(NODE.ID, PARENT, 3; NODE.POS) ELSE STOP "Forgot node"040 IF (PREV AND (NODE.POS=1)) OR (NOT(PREV) AND NODE.POS > PARENT<1>) THEN ;* Look higher041 NODE.ID = PARENT.ID042 NODE = PARENT043 GO TO 200044 END045 IF PREV THEN NODE.POS=NODE.POS-1046 ADJKEY = PARENT<2,NODE.POS>047 NODE.ID = PARENT.ID048 END ELSE ADJKEY = "" ;* No parent exists049 RETURN050 END</pre><hr><A HREF="btp.html">B-TREE-P</A> copyright © 1987-1999 by <A HREF="/home/contact.html">Semaphore Corporation</A>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -