<?xml version='1.0' encoding='UTF-8' standalone='no'?>
<doxygen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="compound.xsd" version="1.8.16">
  <compounddef id="btree_8cpp" kind="file" language="C++">
    <compoundname>btree.cpp</compoundname>
    <briefdescription>
    </briefdescription>
    <detaileddescription>
    </detaileddescription>
    <programlisting>
<codeline lineno="1"><highlight class="comment">//<sp/>http://www.cs.msstate.edu/~cs2314/global/BTreeAnimation/algorithm.html</highlight><highlight class="normal"></highlight></codeline>
<codeline lineno="2"><highlight class="normal"></highlight></codeline>
<codeline lineno="3"><highlight class="normal"></highlight><highlight class="comment">/*</highlight></codeline>
<codeline lineno="4"><highlight class="comment"></highlight></codeline>
<codeline lineno="5"><highlight class="comment">#include<sp/>&lt;stdlib.h&gt;</highlight></codeline>
<codeline lineno="6"><highlight class="comment">#include<sp/>&lt;string.h&gt;</highlight></codeline>
<codeline lineno="7"><highlight class="comment">#include<sp/>&lt;stdio.h&gt;</highlight></codeline>
<codeline lineno="8"><highlight class="comment">#include<sp/>&lt;unistd.h&gt;</highlight></codeline>
<codeline lineno="9"><highlight class="comment">#include<sp/>&lt;iostream&gt;</highlight></codeline>
<codeline lineno="10"><highlight class="comment">#include<sp/>&lt;assert.h&gt;</highlight></codeline>
<codeline lineno="11"><highlight class="comment">#include<sp/>&quot;btree.h&quot;</highlight></codeline>
<codeline lineno="12"><highlight class="comment">#include<sp/>&quot;ubixfs.h&quot;</highlight></codeline>
<codeline lineno="13"><highlight class="comment"></highlight></codeline>
<codeline lineno="14"><highlight class="comment">using<sp/>namespace<sp/>std;</highlight></codeline>
<codeline lineno="15"><highlight class="comment">#define<sp/>VERIFY(x,<sp/>y,<sp/>z,<sp/>n)<sp/>if<sp/>((x)<sp/>!=<sp/>(y))<sp/>{<sp/>cout<sp/>&lt;&lt;<sp/>&quot;verify<sp/>&quot;<sp/>&lt;&lt;<sp/>z<sp/>&lt;&lt;<sp/>&quot;<sp/>failed&quot;<sp/>&lt;&lt;<sp/>endl;<sp/>PrintWholeTree();<sp/>}</highlight></codeline>
<codeline lineno="16"><highlight class="comment"></highlight></codeline>
<codeline lineno="17"><highlight class="comment">bTree::bTree(UbixFS<sp/>*<sp/>filesystem,<sp/>fileDescriptor<sp/>*<sp/>myfd)<sp/>{</highlight></codeline>
<codeline lineno="18"><highlight class="comment"><sp/><sp/>size_t<sp/>result<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="19"><highlight class="comment"></highlight></codeline>
<codeline lineno="20"><highlight class="comment"><sp/><sp/>root<sp/>=<sp/>NULL;</highlight></codeline>
<codeline lineno="21"><highlight class="comment"><sp/><sp/>tag<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="22"><highlight class="comment"><sp/><sp/>fs<sp/>=<sp/>filesystem;</highlight></codeline>
<codeline lineno="23"><highlight class="comment"><sp/><sp/>fd<sp/>=<sp/>myfd;</highlight></codeline>
<codeline lineno="24"><highlight class="comment"><sp/><sp/>header<sp/>=<sp/>new<sp/>bTreeHeader;</highlight></codeline>
<codeline lineno="25"><highlight class="comment"><sp/><sp/>assert(header);</highlight></codeline>
<codeline lineno="26"><highlight class="comment"><sp/><sp/>memset(header,<sp/>0,<sp/>sizeof(bTreeHeader));</highlight></codeline>
<codeline lineno="27"><highlight class="comment"><sp/><sp/>assert(fs);</highlight></codeline>
<codeline lineno="28"><highlight class="comment"><sp/><sp/>result<sp/>=<sp/>fs-&gt;vfs_read(fd,<sp/>header,<sp/>0,<sp/>sizeof(bTreeHeader));</highlight></codeline>
<codeline lineno="29"><highlight class="comment"><sp/><sp/>assert(result<sp/>==<sp/>sizeof(bTreeHeader));</highlight></codeline>
<codeline lineno="30"><highlight class="comment"></highlight></codeline>
<codeline lineno="31"><highlight class="comment"><sp/><sp/>//<sp/>If<sp/>there<sp/>are<sp/>any<sp/>files<sp/>in<sp/>this<sp/>dir,<sp/>load<sp/>the<sp/>first<sp/>node<sp/>of<sp/>the<sp/>b+tree</highlight></codeline>
<codeline lineno="32"><highlight class="comment"><sp/><sp/>if<sp/>(header-&gt;treeLeafCount<sp/>!=<sp/>0)<sp/>{</highlight></codeline>
<codeline lineno="33"><highlight class="comment"><sp/><sp/><sp/><sp/>assert(header-&gt;firstNodeOffset<sp/>!=<sp/>0);</highlight></codeline>
<codeline lineno="34"><highlight class="comment"><sp/><sp/><sp/><sp/>root<sp/>=<sp/>new<sp/>bNode;</highlight></codeline>
<codeline lineno="35"><highlight class="comment"><sp/><sp/><sp/><sp/>assert(root);</highlight></codeline>
<codeline lineno="36"><highlight class="comment"><sp/><sp/><sp/><sp/>result<sp/>=<sp/>fs-&gt;vfs_read(fd,<sp/>root,<sp/>header-&gt;firstNodeOffset,<sp/>sizeof(bNode));</highlight></codeline>
<codeline lineno="37"><highlight class="comment"><sp/><sp/><sp/><sp/>assert(result<sp/>==<sp/>sizeof(bNode));</highlight></codeline>
<codeline lineno="38"><highlight class="comment"><sp/><sp/>}<sp/>//<sp/>if<sp/></highlight></codeline>
<codeline lineno="39"><highlight class="comment"></highlight></codeline>
<codeline lineno="40"><highlight class="comment">}<sp/>//<sp/>bTree::bTree</highlight></codeline>
<codeline lineno="41"><highlight class="comment"></highlight></codeline>
<codeline lineno="42"><highlight class="comment">bTree::bTree(const<sp/>char<sp/>*<sp/>key,<sp/>ubixfsInode<sp/>*<sp/>inode)<sp/>{</highlight></codeline>
<codeline lineno="43"><highlight class="comment">//<sp/>once<sp/>the<sp/>FS<sp/>and<sp/>the<sp/>bTree<sp/>are<sp/>interfaced,<sp/>this<sp/>should<sp/>go<sp/>away</highlight></codeline>
<codeline lineno="44"><highlight class="comment"><sp/><sp/>root<sp/>=<sp/>NULL;</highlight></codeline>
<codeline lineno="45"><highlight class="comment"><sp/><sp/>tag<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="46"><highlight class="comment"><sp/><sp/>header<sp/>=<sp/>new<sp/>bTreeHeader;</highlight></codeline>
<codeline lineno="47"><highlight class="comment"><sp/><sp/>assert(header);</highlight></codeline>
<codeline lineno="48"><highlight class="comment"><sp/><sp/>memset(header,<sp/>0,<sp/>sizeof(bTreeHeader));</highlight></codeline>
<codeline lineno="49"><highlight class="comment"><sp/><sp/>header-&gt;treeDepth<sp/>=<sp/>1;</highlight></codeline>
<codeline lineno="50"><highlight class="comment"><sp/><sp/>header-&gt;treeWidth<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="51"><highlight class="comment"><sp/><sp/>header-&gt;treeLeafCount<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="52"><highlight class="comment"><sp/><sp/>header-&gt;firstDeleted<sp/>=<sp/>-1;</highlight></codeline>
<codeline lineno="53"><highlight class="comment"><sp/><sp/>header-&gt;firstNodeOffset<sp/>=<sp/>sizeof(bTreeHeader);</highlight></codeline>
<codeline lineno="54"><highlight class="comment"></highlight></codeline>
<codeline lineno="55"><highlight class="comment"><sp/><sp/>if<sp/>(inode<sp/>==<sp/>NULL)<sp/>return;</highlight></codeline>
<codeline lineno="56"><highlight class="comment"><sp/><sp/>root<sp/>=<sp/>allocEmptyNode();</highlight></codeline>
<codeline lineno="57"><highlight class="comment"><sp/><sp/>if<sp/>(root<sp/>==<sp/>NULL)<sp/>return;</highlight></codeline>
<codeline lineno="58"><highlight class="comment"><sp/><sp/>root-&gt;used<sp/>=<sp/>1;</highlight></codeline>
<codeline lineno="59"><highlight class="comment"><sp/><sp/>root-&gt;parent.bPtr<sp/>=<sp/>NULL;</highlight></codeline>
<codeline lineno="60"><highlight class="comment"><sp/><sp/>root-&gt;leaf<sp/>=<sp/>true;</highlight></codeline>
<codeline lineno="61"><highlight class="comment"><sp/><sp/>root-&gt;childCount[1]<sp/>=<sp/>1;</highlight></codeline>
<codeline lineno="62"><highlight class="comment"></highlight></codeline>
<codeline lineno="63"><highlight class="comment">//<sp/>cout<sp/>&lt;&lt;<sp/>&quot;---Creating<sp/>&quot;<sp/>&lt;&lt;<sp/>inode-&gt;name<sp/>&lt;&lt;<sp/>&quot;@&quot;<sp/>&lt;&lt;<sp/>inode<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="64"><highlight class="comment"><sp/><sp/>strncpy(root-&gt;keys[0],<sp/>key,<sp/>B_MAX_NAME_LENGTH);</highlight></codeline>
<codeline lineno="65"><highlight class="comment"><sp/><sp/>//<sp/>insert<sp/>pointer<sp/>to<sp/>data<sp/>page<sp/>to<sp/>the<sp/>right<sp/>of<sp/>the<sp/>data</highlight></codeline>
<codeline lineno="66"><highlight class="comment"><sp/><sp/>root-&gt;head[1].iPtr<sp/>=<sp/>inode;</highlight></codeline>
<codeline lineno="67"><highlight class="comment"><sp/><sp/>root-&gt;tail[1].iPtr<sp/>=<sp/>inode;</highlight></codeline>
<codeline lineno="68"><highlight class="comment"></highlight></codeline>
<codeline lineno="69"><highlight class="comment"><sp/><sp/>root-&gt;present[1]<sp/>=<sp/>true;</highlight></codeline>
<codeline lineno="70"><highlight class="comment"><sp/><sp/>if<sp/>(inode<sp/>!=<sp/>NULL)<sp/>{</highlight></codeline>
<codeline lineno="71"><highlight class="comment"><sp/><sp/><sp/><sp/>inode-&gt;next.bPtr<sp/>=<sp/>inode-&gt;prev.bPtr<sp/>=<sp/>NULL;</highlight></codeline>
<codeline lineno="72"><highlight class="comment"><sp/><sp/>}<sp/>//<sp/>if</highlight></codeline>
<codeline lineno="73"><highlight class="comment"><sp/><sp/>return;</highlight></codeline>
<codeline lineno="74"><highlight class="comment">}<sp/>//<sp/>bTree:bTree</highlight></codeline>
<codeline lineno="75"><highlight class="comment"></highlight></codeline>
<codeline lineno="76"><highlight class="comment">bool</highlight></codeline>
<codeline lineno="77"><highlight class="comment">bTree::Insert(const<sp/>char<sp/>*<sp/>key,<sp/>ubixfsInode<sp/>*<sp/>inode)<sp/>{</highlight></codeline>
<codeline lineno="78"><highlight class="comment"><sp/><sp/>bNode<sp/>*<sp/>bnode<sp/>=<sp/>root;</highlight></codeline>
<codeline lineno="79"><highlight class="comment"><sp/><sp/>ubixfsInode<sp/>*<sp/>tmpInode<sp/>=<sp/>NULL;</highlight></codeline>
<codeline lineno="80"><highlight class="comment"><sp/><sp/>unsigned<sp/>int<sp/>curSlot<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="81"><highlight class="comment"></highlight></codeline>
<codeline lineno="82"><highlight class="comment"><sp/><sp/>if<sp/>(inode<sp/>==<sp/>NULL)<sp/>return<sp/>false;</highlight></codeline>
<codeline lineno="83"><highlight class="comment"><sp/></highlight></codeline>
<codeline lineno="84"><highlight class="comment"><sp/><sp/>//<sp/>note:<sp/>this<sp/>code<sp/>is<sp/>right<sp/>out<sp/>of<sp/>the<sp/>constructor</highlight></codeline>
<codeline lineno="85"><highlight class="comment"><sp/><sp/>if<sp/>(root<sp/>==<sp/>NULL)<sp/>{</highlight></codeline>
<codeline lineno="86"><highlight class="comment"><sp/><sp/><sp/><sp/>if<sp/>(header<sp/>==<sp/>NULL)<sp/>header<sp/>=<sp/>new<sp/>bTreeHeader;</highlight></codeline>
<codeline lineno="87"><highlight class="comment"><sp/><sp/><sp/><sp/>assert(header);</highlight></codeline>
<codeline lineno="88"><highlight class="comment"><sp/><sp/><sp/><sp/>memset(header,<sp/>0,<sp/>sizeof(bTreeHeader));</highlight></codeline>
<codeline lineno="89"><highlight class="comment"><sp/><sp/><sp/><sp/>header-&gt;treeDepth<sp/>=<sp/>1;</highlight></codeline>
<codeline lineno="90"><highlight class="comment"><sp/><sp/><sp/><sp/>header-&gt;treeWidth<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="91"><highlight class="comment"><sp/><sp/><sp/><sp/>header-&gt;treeLeafCount<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="92"><highlight class="comment"><sp/><sp/><sp/><sp/>header-&gt;firstDeleted<sp/>=<sp/>-1;</highlight></codeline>
<codeline lineno="93"><highlight class="comment"><sp/><sp/><sp/><sp/>header-&gt;firstNodeOffset<sp/>=<sp/>sizeof(bTreeHeader);</highlight></codeline>
<codeline lineno="94"><highlight class="comment"></highlight></codeline>
<codeline lineno="95"><highlight class="comment"><sp/><sp/><sp/><sp/>root<sp/>=<sp/>allocEmptyNode();</highlight></codeline>
<codeline lineno="96"><highlight class="comment"><sp/><sp/><sp/><sp/>assert(root);</highlight></codeline>
<codeline lineno="97"><highlight class="comment"><sp/><sp/><sp/><sp/>if<sp/>(root<sp/>==<sp/>NULL)<sp/>return<sp/>false;</highlight></codeline>
<codeline lineno="98"><highlight class="comment"><sp/><sp/><sp/><sp/></highlight></codeline>
<codeline lineno="99"><highlight class="comment"><sp/><sp/><sp/><sp/>root-&gt;used<sp/>=<sp/>1;</highlight></codeline>
<codeline lineno="100"><highlight class="comment"><sp/><sp/><sp/><sp/>root-&gt;parent.bPtr<sp/>=<sp/>NULL;</highlight></codeline>
<codeline lineno="101"><highlight class="comment"><sp/><sp/><sp/><sp/>root-&gt;leaf<sp/>=<sp/>true;</highlight></codeline>
<codeline lineno="102"><highlight class="comment"><sp/><sp/><sp/><sp/>root-&gt;childCount[1]<sp/>=<sp/>1;</highlight></codeline>
<codeline lineno="103"><highlight class="comment"></highlight></codeline>
<codeline lineno="104"><highlight class="comment"><sp/><sp/><sp/><sp/>strncpy(root-&gt;keys[0],<sp/>key,<sp/>B_MAX_NAME_LENGTH);</highlight></codeline>
<codeline lineno="105"><highlight class="comment"><sp/><sp/><sp/><sp/>//<sp/>insert<sp/>pointer<sp/>to<sp/>data<sp/>page<sp/>to<sp/>the<sp/>right<sp/>of<sp/>the<sp/>data</highlight></codeline>
<codeline lineno="106"><highlight class="comment"><sp/><sp/><sp/><sp/>root-&gt;head[1].iPtr<sp/>=<sp/>inode;</highlight></codeline>
<codeline lineno="107"><highlight class="comment"><sp/><sp/><sp/><sp/>root-&gt;tail[1].iPtr<sp/>=<sp/>inode;</highlight></codeline>
<codeline lineno="108"><highlight class="comment"></highlight></codeline>
<codeline lineno="109"><highlight class="comment"><sp/><sp/><sp/><sp/>root-&gt;present[1]<sp/>=<sp/>true;</highlight></codeline>
<codeline lineno="110"><highlight class="comment"><sp/><sp/><sp/><sp/>inode-&gt;next.iPtr<sp/>=<sp/>inode-&gt;prev.iPtr<sp/>=<sp/>NULL;</highlight></codeline>
<codeline lineno="111"><highlight class="comment"><sp/><sp/><sp/><sp/>return<sp/>true;</highlight></codeline>
<codeline lineno="112"><highlight class="comment"><sp/><sp/>}<sp/>//<sp/>if</highlight></codeline>
<codeline lineno="113"><highlight class="comment"><sp/><sp/><sp/><sp/></highlight></codeline>
<codeline lineno="114"><highlight class="comment"><sp/><sp/>tmpInode<sp/>=<sp/>Find(key);</highlight></codeline>
<codeline lineno="115"><highlight class="comment"><sp/><sp/>if<sp/>(tmpInode<sp/>!=<sp/>NULL)<sp/>return<sp/>false;</highlight></codeline>
<codeline lineno="116"><highlight class="comment">//<sp/><sp/>PrintWholeTree();</highlight></codeline>
<codeline lineno="117"><highlight class="comment">//<sp/>cout<sp/>&lt;&lt;<sp/>&quot;Insert(&quot;<sp/>&lt;&lt;<sp/>key<sp/>&lt;&lt;<sp/>&quot;)&quot;<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="118"><highlight class="comment">//Info(bnode);</highlight></codeline>
<codeline lineno="119"><highlight class="comment"><sp/><sp/>++header-&gt;treeLeafCount;</highlight></codeline>
<codeline lineno="120"><highlight class="comment"><sp/><sp/>//Find<sp/>the<sp/>leaf<sp/>node<sp/>the<sp/>inode<sp/>goes<sp/>into</highlight></codeline>
<codeline lineno="121"><highlight class="comment"></highlight></codeline>
<codeline lineno="122"><highlight class="comment"><sp/><sp/>assert(bnode-&gt;used);</highlight></codeline>
<codeline lineno="123"><highlight class="comment">//<sp/>cout<sp/>&lt;&lt;<sp/>&quot;---Inserting<sp/>&quot;<sp/>&lt;&lt;<sp/>inode-&gt;name<sp/>&lt;&lt;<sp/>&quot;<sp/>@<sp/>&quot;<sp/>&lt;&lt;<sp/>inode<sp/>&lt;&lt;<sp/>endl;<sp/></highlight></codeline>
<codeline lineno="124"><highlight class="comment"><sp/><sp/>while<sp/>(bnode<sp/>!=<sp/>NULL<sp/>&amp;&amp;<sp/>!bnode-&gt;leaf)<sp/>{</highlight></codeline>
<codeline lineno="125"><highlight class="comment"><sp/><sp/><sp/><sp/>if<sp/>(strcmp(key,<sp/>bnode-&gt;keys[0])<sp/>&lt;<sp/>0)<sp/>{</highlight></codeline>
<codeline lineno="126"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>bnode<sp/>=<sp/>bnode-&gt;head[0].bPtr;</highlight></codeline>
<codeline lineno="127"><highlight class="comment"><sp/><sp/><sp/><sp/>}<sp/>else<sp/>{</highlight></codeline>
<codeline lineno="128"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>if<sp/>(strcmp(key,<sp/>bnode-&gt;keys[bnode-&gt;used-1])<sp/>&gt;=<sp/>0)<sp/>{</highlight></codeline>
<codeline lineno="129"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>bnode<sp/>=<sp/>bnode-&gt;head[bnode-&gt;used].bPtr;</highlight></codeline>
<codeline lineno="130"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>}<sp/>else<sp/>{</highlight></codeline>
<codeline lineno="131"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>for<sp/>(unsigned<sp/>int<sp/>i<sp/>=<sp/>1;<sp/>i<sp/>&lt;<sp/>bnode-&gt;used;<sp/>i++)<sp/>{</highlight></codeline>
<codeline lineno="132"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>if<sp/>(strcmp(key,<sp/>bnode-&gt;keys[i])<sp/>&lt;<sp/>0)<sp/>{</highlight></codeline>
<codeline lineno="133"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>bnode<sp/>=<sp/>bnode-&gt;head[i].bPtr;</highlight></codeline>
<codeline lineno="134"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>break;</highlight></codeline>
<codeline lineno="135"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>}<sp/>//<sp/>if</highlight></codeline>
<codeline lineno="136"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>}<sp/>//<sp/>for<sp/>i</highlight></codeline>
<codeline lineno="137"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>}<sp/>//<sp/>else</highlight></codeline>
<codeline lineno="138"><highlight class="comment"><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="139"><highlight class="comment"><sp/><sp/>}<sp/>//<sp/>while</highlight></codeline>
<codeline lineno="140"><highlight class="comment"></highlight></codeline>
<codeline lineno="141"><highlight class="comment"></highlight></codeline>
<codeline lineno="142"><highlight class="comment">assert(bnode);</highlight></codeline>
<codeline lineno="143"><highlight class="comment">if<sp/>(bnode-&gt;leaf<sp/>!=<sp/>true)<sp/>cout<sp/>&lt;&lt;<sp/>&quot;leafnode!=true&quot;<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="144"><highlight class="comment">assert(inode);</highlight></codeline>
<codeline lineno="145"><highlight class="comment"></highlight></codeline>
<codeline lineno="146"><highlight class="comment"><sp/><sp/>if<sp/>(strcmp(key,<sp/>bnode-&gt;keys[curSlot<sp/>=<sp/>0])<sp/>&lt;<sp/>0)</highlight></codeline>
<codeline lineno="147"><highlight class="comment"><sp/><sp/><sp/><sp/>tmpInode<sp/>=<sp/>bnode-&gt;head[curSlot].iPtr;</highlight></codeline>
<codeline lineno="148"><highlight class="comment"><sp/><sp/>else</highlight></codeline>
<codeline lineno="149"><highlight class="comment"><sp/><sp/><sp/><sp/>if<sp/>(strcmp(key,<sp/>bnode-&gt;keys[(curSlot<sp/>=<sp/>bnode-&gt;used)-1])<sp/>&gt;=<sp/>0)</highlight></codeline>
<codeline lineno="150"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>tmpInode<sp/>=<sp/>bnode-&gt;head[bnode-&gt;used].iPtr;</highlight></codeline>
<codeline lineno="151"><highlight class="comment"><sp/><sp/><sp/><sp/>else<sp/>{</highlight></codeline>
<codeline lineno="152"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>for<sp/>(curSlot<sp/>=<sp/>1;<sp/>curSlot<sp/>&lt;<sp/>bnode-&gt;used;<sp/>curSlot++)<sp/>{</highlight></codeline>
<codeline lineno="153"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>if<sp/>(strcmp(key,<sp/>bnode-&gt;keys[curSlot])<sp/>&lt;<sp/>0)<sp/>{</highlight></codeline>
<codeline lineno="154"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>tmpInode<sp/>=<sp/>bnode-&gt;head[curSlot].iPtr;</highlight></codeline>
<codeline lineno="155"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>break;</highlight></codeline>
<codeline lineno="156"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>}<sp/>//<sp/>if</highlight></codeline>
<codeline lineno="157"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>}<sp/>//<sp/>for<sp/>curSlot</highlight></codeline>
<codeline lineno="158"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>tmpInode<sp/>=<sp/>bnode-&gt;head[curSlot].iPtr;</highlight></codeline>
<codeline lineno="159"><highlight class="comment"><sp/><sp/><sp/><sp/>}<sp/>//<sp/>else</highlight></codeline>
<codeline lineno="160"><highlight class="comment"></highlight></codeline>
<codeline lineno="161"><highlight class="comment"></highlight></codeline>
<codeline lineno="162"><highlight class="comment"><sp/><sp/>if<sp/>(tmpInode<sp/>==<sp/>NULL)<sp/>{</highlight></codeline>
<codeline lineno="163"><highlight class="comment"><sp/><sp/><sp/><sp/>//<sp/>This<sp/>is<sp/>the<sp/>first<sp/>node<sp/>in<sp/>this<sp/>leaf</highlight></codeline>
<codeline lineno="164"><highlight class="comment"><sp/><sp/><sp/><sp/>bnode-&gt;head[curSlot].iPtr<sp/>=<sp/>bnode-&gt;tail[curSlot].iPtr<sp/>=<sp/>inode;</highlight></codeline>
<codeline lineno="165"><highlight class="comment"><sp/><sp/><sp/><sp/>bnode-&gt;present[curSlot]<sp/>=<sp/>true;</highlight></codeline>
<codeline lineno="166"><highlight class="comment"></highlight></codeline>
<codeline lineno="167"><highlight class="comment"><sp/><sp/><sp/><sp/>if<sp/>(curSlot<sp/>==<sp/>0)<sp/>{</highlight></codeline>
<codeline lineno="168"><highlight class="comment"></highlight></codeline>
<codeline lineno="169"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>if<sp/>(bnode-&gt;head[1].iPtr<sp/>!=<sp/>NULL)<sp/><sp/>{</highlight></codeline>
<codeline lineno="170"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>ubixfsInode<sp/>*<sp/>iptr<sp/>=<sp/>bnode-&gt;head[1].iPtr;</highlight></codeline>
<codeline lineno="171"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>inode-&gt;prev.iPtr<sp/>=<sp/>iptr-&gt;prev.iPtr;</highlight></codeline>
<codeline lineno="172"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>inode-&gt;next.iPtr<sp/>=<sp/>iptr;</highlight></codeline>
<codeline lineno="173"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>iptr-&gt;prev.iPtr<sp/>=<sp/>inode;</highlight></codeline>
<codeline lineno="174"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>if<sp/>(inode-&gt;prev.iPtr<sp/>!=<sp/>NULL)<sp/></highlight></codeline>
<codeline lineno="175"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>inode-&gt;prev.iPtr-&gt;next.iPtr<sp/>=<sp/>inode;</highlight></codeline>
<codeline lineno="176"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>}<sp/>else<sp/>{</highlight></codeline>
<codeline lineno="177"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>inode-&gt;next.iPtr<sp/>=<sp/>inode-&gt;prev.iPtr<sp/>=<sp/>NULL;</highlight></codeline>
<codeline lineno="178"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>}<sp/>//<sp/>else</highlight></codeline>
<codeline lineno="179"><highlight class="comment"></highlight></codeline>
<codeline lineno="180"><highlight class="comment"><sp/><sp/><sp/><sp/>}<sp/>else<sp/>{</highlight></codeline>
<codeline lineno="181"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>++bnode-&gt;used;<sp/></highlight></codeline>
<codeline lineno="182"><highlight class="comment"><sp/><sp/><sp/><sp/>}<sp/>//<sp/>else</highlight></codeline>
<codeline lineno="183"><highlight class="comment"></highlight></codeline>
<codeline lineno="184"><highlight class="comment"><sp/><sp/>}<sp/>else<sp/>{</highlight></codeline>
<codeline lineno="185"><highlight class="comment"><sp/><sp/><sp/><sp/>//<sp/>Add<sp/>node<sp/>to<sp/>leaf<sp/>page.<sp/>Scan<sp/>through<sp/>to<sp/>find<sp/>where<sp/>it<sp/>goes.</highlight></codeline>
<codeline lineno="186"><highlight class="comment"></highlight></codeline>
<codeline lineno="187"><highlight class="comment"><sp/><sp/><sp/><sp/>if<sp/>(strcmp(key,<sp/>bnode-&gt;head[curSlot].iPtr-&gt;name)<sp/>&lt;<sp/>0)</highlight></codeline>
<codeline lineno="188"><highlight class="comment"><sp/><sp/><sp/><sp/>{</highlight></codeline>
<codeline lineno="189"><highlight class="comment"></highlight></codeline>
<codeline lineno="190"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>inode-&gt;next.iPtr<sp/>=<sp/>bnode-&gt;head[curSlot].iPtr;</highlight></codeline>
<codeline lineno="191"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>inode-&gt;prev.iPtr<sp/>=<sp/>inode-&gt;next.iPtr-&gt;prev.iPtr;</highlight></codeline>
<codeline lineno="192"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>inode-&gt;next.iPtr-&gt;prev.iPtr<sp/>=<sp/>inode;</highlight></codeline>
<codeline lineno="193"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>if<sp/>(inode-&gt;prev.iPtr<sp/>!=<sp/>NULL)<sp/>inode-&gt;prev.iPtr-&gt;next.iPtr<sp/>=<sp/>inode;</highlight></codeline>
<codeline lineno="194"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>bnode-&gt;head[curSlot].iPtr<sp/>=<sp/>inode;</highlight></codeline>
<codeline lineno="195"><highlight class="comment"></highlight></codeline>
<codeline lineno="196"><highlight class="comment"><sp/><sp/><sp/><sp/>}<sp/>else<sp/>{</highlight></codeline>
<codeline lineno="197"><highlight class="comment"></highlight></codeline>
<codeline lineno="198"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>if<sp/>(strcmp(key,<sp/>bnode-&gt;tail[curSlot].iPtr-&gt;name)<sp/>&gt;<sp/>0)<sp/>{</highlight></codeline>
<codeline lineno="199"><highlight class="comment"></highlight></codeline>
<codeline lineno="200"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>inode-&gt;prev.iPtr<sp/>=<sp/>bnode-&gt;tail[curSlot].iPtr;</highlight></codeline>
<codeline lineno="201"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>inode-&gt;next.iPtr<sp/>=<sp/>inode-&gt;prev.iPtr-&gt;next.iPtr;</highlight></codeline>
<codeline lineno="202"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>inode-&gt;prev.iPtr-&gt;next.iPtr<sp/>=<sp/>inode;</highlight></codeline>
<codeline lineno="203"><highlight class="comment"></highlight></codeline>
<codeline lineno="204"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>if<sp/>(inode-&gt;next.iPtr<sp/>!=<sp/>NULL)<sp/>inode-&gt;next.iPtr-&gt;prev.iPtr<sp/>=<sp/>inode;</highlight></codeline>
<codeline lineno="205"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>bnode-&gt;tail[curSlot].iPtr<sp/>=<sp/>inode;</highlight></codeline>
<codeline lineno="206"><highlight class="comment"></highlight></codeline>
<codeline lineno="207"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>}<sp/>else<sp/>{</highlight></codeline>
<codeline lineno="208"><highlight class="comment"></highlight></codeline>
<codeline lineno="209"><highlight class="comment"></highlight></codeline>
<codeline lineno="210"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>ubixfsInode<sp/>*<sp/>tmpInode<sp/>=<sp/>bnode-&gt;head[curSlot].iPtr;</highlight></codeline>
<codeline lineno="211"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>for<sp/>(unsigned<sp/>int<sp/>i<sp/>=<sp/>0;<sp/>i<sp/>&lt;<sp/>bnode-&gt;childCount[curSlot];<sp/>i++)<sp/>{</highlight></codeline>
<codeline lineno="212"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>if<sp/>(strcmp(key,<sp/>tmpInode-&gt;name)<sp/>&lt;<sp/>0)<sp/>{</highlight></codeline>
<codeline lineno="213"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>inode-&gt;next.iPtr<sp/>=<sp/>tmpInode;</highlight></codeline>
<codeline lineno="214"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>inode-&gt;prev.iPtr<sp/>=<sp/>tmpInode-&gt;prev.iPtr;</highlight></codeline>
<codeline lineno="215"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>inode-&gt;next.iPtr-&gt;prev.iPtr<sp/>=<sp/>inode;</highlight></codeline>
<codeline lineno="216"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>inode-&gt;prev.iPtr-&gt;next.iPtr<sp/>=<sp/>inode;</highlight></codeline>
<codeline lineno="217"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>break;</highlight></codeline>
<codeline lineno="218"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>}<sp/>//<sp/>if</highlight></codeline>
<codeline lineno="219"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>tmpInode<sp/>=<sp/>tmpInode-&gt;next.iPtr;<sp/></highlight></codeline>
<codeline lineno="220"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>}<sp/>//<sp/>for<sp/>i</highlight></codeline>
<codeline lineno="221"><highlight class="comment"></highlight></codeline>
<codeline lineno="222"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>}<sp/>//<sp/>else</highlight></codeline>
<codeline lineno="223"><highlight class="comment"></highlight></codeline>
<codeline lineno="224"><highlight class="comment"><sp/><sp/><sp/><sp/>}<sp/>//<sp/>else</highlight></codeline>
<codeline lineno="225"><highlight class="comment"></highlight></codeline>
<codeline lineno="226"><highlight class="comment"><sp/><sp/>}<sp/>//<sp/>else</highlight></codeline>
<codeline lineno="227"><highlight class="comment"></highlight></codeline>
<codeline lineno="228"><highlight class="comment"></highlight></codeline>
<codeline lineno="229"><highlight class="comment"></highlight></codeline>
<codeline lineno="230"><highlight class="comment"><sp/><sp/>if<sp/>(++bnode-&gt;childCount[curSlot]<sp/>==<sp/>B_MAX_CHILD_COUNT)<sp/>{</highlight></codeline>
<codeline lineno="231"><highlight class="comment"></highlight></codeline>
<codeline lineno="232"><highlight class="comment">//<sp/>cout<sp/>&lt;&lt;<sp/>&quot;----<sp/>before<sp/>split<sp/>----&quot;<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="233"><highlight class="comment">//<sp/>Info(bnode);</highlight></codeline>
<codeline lineno="234"><highlight class="comment"></highlight></codeline>
<codeline lineno="235"><highlight class="comment"><sp/><sp/><sp/><sp/>if<sp/>(curSlot<sp/>!=<sp/>bnode-&gt;used)<sp/>{</highlight></codeline>
<codeline lineno="236"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>int<sp/>shift<sp/>=<sp/>bnode-&gt;used<sp/>-<sp/>curSlot<sp/>+1;</highlight></codeline>
<codeline lineno="237"><highlight class="comment"></highlight></codeline>
<codeline lineno="238"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>memmove(&amp;bnode-&gt;head[curSlot+1],</highlight></codeline>
<codeline lineno="239"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>&amp;bnode-&gt;head[curSlot],</highlight></codeline>
<codeline lineno="240"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>sizeof(bnode-&gt;head[0])<sp/>*<sp/>shift);</highlight></codeline>
<codeline lineno="241"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>memmove(&amp;bnode-&gt;tail[curSlot+1],</highlight></codeline>
<codeline lineno="242"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>&amp;bnode-&gt;tail[curSlot],</highlight></codeline>
<codeline lineno="243"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>sizeof(bnode-&gt;tail[0])<sp/>*<sp/>shift);</highlight></codeline>
<codeline lineno="244"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>memmove(&amp;bnode-&gt;present[curSlot+1],</highlight></codeline>
<codeline lineno="245"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>&amp;bnode-&gt;present[curSlot],</highlight></codeline>
<codeline lineno="246"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>sizeof(bnode-&gt;present[0])<sp/>*<sp/>shift);</highlight></codeline>
<codeline lineno="247"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>memmove(&amp;bnode-&gt;childCount[curSlot+1],</highlight></codeline>
<codeline lineno="248"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>&amp;bnode-&gt;childCount[curSlot],</highlight></codeline>
<codeline lineno="249"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>sizeof(bnode-&gt;childCount[0])<sp/>*<sp/>shift);</highlight></codeline>
<codeline lineno="250"><highlight class="comment"></highlight></codeline>
<codeline lineno="251"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>memmove(&amp;bnode-&gt;keys[curSlot+1],</highlight></codeline>
<codeline lineno="252"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>&amp;bnode-&gt;keys[curSlot],</highlight></codeline>
<codeline lineno="253"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>sizeof(bnode-&gt;keys[0])<sp/>*<sp/>(shift-1));</highlight></codeline>
<codeline lineno="254"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>memset(bnode-&gt;keys[curSlot],<sp/>0,<sp/>B_MAX_NAME_LENGTH);</highlight></codeline>
<codeline lineno="255"><highlight class="comment"><sp/><sp/><sp/><sp/>}<sp/>else<sp/>{</highlight></codeline>
<codeline lineno="256"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>bnode-&gt;head[curSlot+1]<sp/>=<sp/>bnode-&gt;head[curSlot];</highlight></codeline>
<codeline lineno="257"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>bnode-&gt;tail[curSlot+1]<sp/>=<sp/>bnode-&gt;tail[curSlot];</highlight></codeline>
<codeline lineno="258"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>bnode-&gt;childCount[curSlot+1]<sp/>=<sp/>bnode-&gt;childCount[curSlot];</highlight></codeline>
<codeline lineno="259"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>bnode-&gt;present[curSlot+1]<sp/>=<sp/>bnode-&gt;present[curSlot];</highlight></codeline>
<codeline lineno="260"><highlight class="comment"><sp/><sp/><sp/><sp/>}<sp/>//<sp/>else</highlight></codeline>
<codeline lineno="261"><highlight class="comment"></highlight></codeline>
<codeline lineno="262"><highlight class="comment"><sp/><sp/><sp/><sp/>ubixfsInode<sp/>*<sp/>tmpInode<sp/>=<sp/>bnode-&gt;head[curSlot].iPtr;</highlight></codeline>
<codeline lineno="263"><highlight class="comment"></highlight></codeline>
<codeline lineno="264"><highlight class="comment"><sp/><sp/><sp/><sp/>for<sp/>(unsigned<sp/>int<sp/>i<sp/>=<sp/>0;<sp/>i<sp/>&lt;<sp/>(B_MAX_CHILD_COUNT+1)<sp/>&gt;&gt;<sp/>1;<sp/>i++)<sp/>{</highlight></codeline>
<codeline lineno="265"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>assert(tmpInode);</highlight></codeline>
<codeline lineno="266"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>tmpInode<sp/>=<sp/>tmpInode-&gt;next.iPtr;</highlight></codeline>
<codeline lineno="267"><highlight class="comment"><sp/><sp/><sp/><sp/>}<sp/>//<sp/>for<sp/>i</highlight></codeline>
<codeline lineno="268"><highlight class="comment"></highlight></codeline>
<codeline lineno="269"><highlight class="comment"><sp/><sp/><sp/><sp/>strncpy(bnode-&gt;keys[curSlot],<sp/>tmpInode-&gt;name,<sp/>B_MAX_NAME_LENGTH);</highlight></codeline>
<codeline lineno="270"><highlight class="comment"><sp/><sp/><sp/><sp/>bnode-&gt;head[curSlot+1].iPtr<sp/>=<sp/>tmpInode;</highlight></codeline>
<codeline lineno="271"><highlight class="comment"><sp/><sp/><sp/><sp/>bnode-&gt;tail[curSlot].iPtr<sp/>=<sp/>tmpInode-&gt;prev.iPtr;</highlight></codeline>
<codeline lineno="272"><highlight class="comment"><sp/><sp/><sp/><sp/>bnode-&gt;childCount[curSlot]<sp/>=<sp/>(B_MAX_CHILD_COUNT+1)<sp/>&gt;&gt;<sp/>1;</highlight></codeline>
<codeline lineno="273"><highlight class="comment"><sp/><sp/><sp/><sp/>bnode-&gt;childCount[curSlot+1]<sp/>-=<sp/>bnode-&gt;childCount[curSlot];</highlight></codeline>
<codeline lineno="274"><highlight class="comment"><sp/><sp/><sp/><sp/>bnode-&gt;present[curSlot]<sp/>=<sp/>true;</highlight></codeline>
<codeline lineno="275"><highlight class="comment"><sp/><sp/><sp/><sp/>++header-&gt;treeWidth;</highlight></codeline>
<codeline lineno="276"><highlight class="comment"><sp/><sp/><sp/><sp/>if<sp/>(++bnode-&gt;used<sp/>==<sp/>B_MAX_KEYS)<sp/>splitNode(bnode);</highlight></codeline>
<codeline lineno="277"><highlight class="comment"></highlight></codeline>
<codeline lineno="278"><highlight class="comment"><sp/><sp/>}<sp/>//<sp/>if<sp/>leaf<sp/>is<sp/>full</highlight></codeline>
<codeline lineno="279"><highlight class="comment">//<sp/>Info(bnode);</highlight></codeline>
<codeline lineno="280"><highlight class="comment"><sp/><sp/>return<sp/>true;</highlight></codeline>
<codeline lineno="281"><highlight class="comment">}<sp/>//<sp/>bTree::Insert</highlight></codeline>
<codeline lineno="282"><highlight class="comment"></highlight></codeline>
<codeline lineno="283"><highlight class="comment">void<sp/></highlight></codeline>
<codeline lineno="284"><highlight class="comment">bTree::splitNode(bNode<sp/>*<sp/>oldNode)<sp/>{</highlight></codeline>
<codeline lineno="285"><highlight class="comment"><sp/><sp/>ubixfsInode<sp/>*<sp/>tmpInode<sp/>=<sp/>NULL;</highlight></codeline>
<codeline lineno="286"><highlight class="comment"><sp/><sp/>assert(oldNode);</highlight></codeline>
<codeline lineno="287"><highlight class="comment"><sp/><sp/>if<sp/>(oldNode<sp/>==<sp/>NULL)<sp/>return;</highlight></codeline>
<codeline lineno="288"><highlight class="comment"><sp/><sp/>if<sp/>(oldNode-&gt;used<sp/>!=<sp/>B_MAX_KEYS)<sp/>return;</highlight></codeline>
<codeline lineno="289"><highlight class="comment"></highlight></codeline>
<codeline lineno="290"><highlight class="comment"><sp/><sp/>bNode<sp/>*<sp/>newNode<sp/>=<sp/>allocEmptyNode();</highlight></codeline>
<codeline lineno="291"><highlight class="comment"><sp/><sp/>if<sp/>(newNode<sp/>==<sp/>NULL)<sp/>return;</highlight></codeline>
<codeline lineno="292"><highlight class="comment"></highlight></codeline>
<codeline lineno="293"><highlight class="comment"><sp/><sp/>unsigned<sp/>int<sp/>shift<sp/>=<sp/>B_MAX_KEYS<sp/>&gt;&gt;<sp/>1;</highlight></codeline>
<codeline lineno="294"><highlight class="comment"><sp/><sp/>unsigned<sp/>int<sp/>splitLoc<sp/>=<sp/>B_MAX_KEYS<sp/>-<sp/>shift;</highlight></codeline>
<codeline lineno="295"><highlight class="comment"><sp/><sp/>++<sp/>shift;</highlight></codeline>
<codeline lineno="296"><highlight class="comment">//<sp/>cout<sp/>&lt;&lt;<sp/>&quot;oldNode<sp/>before<sp/>split:<sp/>&quot;<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="297"><highlight class="comment">//<sp/>Info(oldNode);</highlight></codeline>
<codeline lineno="298"><highlight class="comment">//<sp/>cout<sp/>&lt;&lt;<sp/>&quot;splitLoc:<sp/>&quot;<sp/>&lt;&lt;<sp/>splitLoc<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="299"><highlight class="comment">//<sp/>cout<sp/>&lt;&lt;<sp/>&quot;shift:<sp/>&quot;<sp/>&lt;&lt;<sp/>shift<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="300"><highlight class="comment"></highlight></codeline>
<codeline lineno="301"><highlight class="comment"><sp/><sp/>newNode-&gt;used<sp/>=<sp/>oldNode-&gt;used<sp/>=<sp/>B_MAX_KEYS<sp/>&gt;&gt;<sp/>1;</highlight></codeline>
<codeline lineno="302"><highlight class="comment"><sp/><sp/>newNode-&gt;parent.bPtr<sp/>=<sp/>oldNode-&gt;parent.bPtr;</highlight></codeline>
<codeline lineno="303"><highlight class="comment"><sp/><sp/>newNode-&gt;leaf<sp/>=<sp/>oldNode-&gt;leaf;</highlight></codeline>
<codeline lineno="304"><highlight class="comment"></highlight></codeline>
<codeline lineno="305"><highlight class="comment">//<sp/>cout<sp/>&lt;&lt;<sp/>&quot;newNode-&gt;used:<sp/>&quot;<sp/>&lt;&lt;<sp/>newNode-&gt;used<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="306"><highlight class="comment">//<sp/>cout<sp/>&lt;&lt;<sp/>&quot;oldNode-&gt;used:<sp/>&quot;<sp/>&lt;&lt;<sp/>oldNode-&gt;used<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="307"><highlight class="comment"></highlight></codeline>
<codeline lineno="308"><highlight class="comment"><sp/><sp/>memcpy(&amp;newNode-&gt;keys[0],</highlight></codeline>
<codeline lineno="309"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>&amp;oldNode-&gt;keys[splitLoc],</highlight></codeline>
<codeline lineno="310"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>sizeof(newNode-&gt;keys[0])<sp/>*<sp/>(shift-1));</highlight></codeline>
<codeline lineno="311"><highlight class="comment"><sp/><sp/></highlight></codeline>
<codeline lineno="312"><highlight class="comment"><sp/><sp/>memset(&amp;oldNode-&gt;keys[splitLoc],<sp/>0,<sp/>sizeof(newNode-&gt;keys[0])<sp/>*<sp/>(shift-1));</highlight></codeline>
<codeline lineno="313"><highlight class="comment"></highlight></codeline>
<codeline lineno="314"><highlight class="comment"><sp/><sp/>memcpy(&amp;newNode-&gt;present[0],</highlight></codeline>
<codeline lineno="315"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>&amp;oldNode-&gt;present[splitLoc],</highlight></codeline>
<codeline lineno="316"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>sizeof(newNode-&gt;present[0])<sp/>*<sp/>shift);</highlight></codeline>
<codeline lineno="317"><highlight class="comment"></highlight></codeline>
<codeline lineno="318"><highlight class="comment"><sp/><sp/>memset(&amp;oldNode-&gt;present[splitLoc],<sp/>0,<sp/>sizeof(newNode-&gt;present[0])<sp/>*<sp/>shift);</highlight></codeline>
<codeline lineno="319"><highlight class="comment"></highlight></codeline>
<codeline lineno="320"><highlight class="comment"><sp/><sp/>memcpy(&amp;newNode-&gt;head[0],</highlight></codeline>
<codeline lineno="321"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>&amp;oldNode-&gt;head[splitLoc],</highlight></codeline>
<codeline lineno="322"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>sizeof(newNode-&gt;head[0])<sp/>*<sp/>shift);</highlight></codeline>
<codeline lineno="323"><highlight class="comment"></highlight></codeline>
<codeline lineno="324"><highlight class="comment"><sp/><sp/>memset(&amp;oldNode-&gt;head[splitLoc],<sp/>0,<sp/></highlight></codeline>
<codeline lineno="325"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>sizeof(newNode-&gt;head[0])<sp/>*<sp/>shift);</highlight></codeline>
<codeline lineno="326"><highlight class="comment"></highlight></codeline>
<codeline lineno="327"><highlight class="comment"><sp/><sp/>memcpy(&amp;newNode-&gt;tail[0],</highlight></codeline>
<codeline lineno="328"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>&amp;oldNode-&gt;tail[splitLoc],</highlight></codeline>
<codeline lineno="329"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>sizeof(newNode-&gt;tail[0])<sp/>*<sp/>shift);</highlight></codeline>
<codeline lineno="330"><highlight class="comment"></highlight></codeline>
<codeline lineno="331"><highlight class="comment"><sp/><sp/>memset(&amp;oldNode-&gt;tail[splitLoc],<sp/>0,<sp/></highlight></codeline>
<codeline lineno="332"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>sizeof(newNode-&gt;tail[0])<sp/>*<sp/>shift);</highlight></codeline>
<codeline lineno="333"><highlight class="comment"></highlight></codeline>
<codeline lineno="334"><highlight class="comment"><sp/><sp/>memcpy(&amp;newNode-&gt;childCount[0],</highlight></codeline>
<codeline lineno="335"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>&amp;oldNode-&gt;childCount[splitLoc],</highlight></codeline>
<codeline lineno="336"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>sizeof(newNode-&gt;childCount[0])<sp/>*<sp/>shift);</highlight></codeline>
<codeline lineno="337"><highlight class="comment"></highlight></codeline>
<codeline lineno="338"><highlight class="comment"><sp/><sp/>memset(&amp;oldNode-&gt;childCount[splitLoc],<sp/>0,<sp/></highlight></codeline>
<codeline lineno="339"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>sizeof(newNode-&gt;childCount[0])<sp/>*<sp/>shift);</highlight></codeline>
<codeline lineno="340"><highlight class="comment"></highlight></codeline>
<codeline lineno="341"><highlight class="comment"><sp/><sp/>if<sp/>(!newNode-&gt;leaf)<sp/>{</highlight></codeline>
<codeline lineno="342"><highlight class="comment"><sp/><sp/><sp/><sp/>for<sp/>(unsigned<sp/>int<sp/>i<sp/>=<sp/>0;<sp/>i<sp/>&lt;=<sp/>newNode-&gt;used;<sp/>i++)<sp/>{</highlight></codeline>
<codeline lineno="343"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>newNode-&gt;head[i].bPtr-&gt;parent.bPtr<sp/>=<sp/>newNode;</highlight></codeline>
<codeline lineno="344"><highlight class="comment"><sp/><sp/><sp/><sp/>}<sp/>//<sp/>for<sp/>i</highlight></codeline>
<codeline lineno="345"><highlight class="comment"><sp/><sp/>}<sp/>//<sp/>if<sp/>newNode<sp/>isn&apos;t<sp/>a<sp/>leaf</highlight></codeline>
<codeline lineno="346"><highlight class="comment"></highlight></codeline>
<codeline lineno="347"><highlight class="comment"><sp/><sp/>tmpInode<sp/>=<sp/>GetFirstNode(newNode);</highlight></codeline>
<codeline lineno="348"><highlight class="comment"><sp/><sp/>assert(tmpInode);</highlight></codeline>
<codeline lineno="349"><highlight class="comment"></highlight></codeline>
<codeline lineno="350"><highlight class="comment"><sp/><sp/>if<sp/>(oldNode<sp/>==<sp/>root)<sp/>{</highlight></codeline>
<codeline lineno="351"><highlight class="comment"><sp/><sp/><sp/><sp/>//<sp/>allocate<sp/>a<sp/>new<sp/>root<sp/>node</highlight></codeline>
<codeline lineno="352"><highlight class="comment"><sp/><sp/><sp/><sp/>++header-&gt;treeDepth;</highlight></codeline>
<codeline lineno="353"><highlight class="comment"><sp/><sp/><sp/><sp/>root<sp/>=<sp/>allocEmptyNode();</highlight></codeline>
<codeline lineno="354"><highlight class="comment"><sp/><sp/><sp/><sp/>oldNode-&gt;parent.bPtr<sp/>=<sp/>root;</highlight></codeline>
<codeline lineno="355"><highlight class="comment"><sp/><sp/><sp/><sp/>newNode-&gt;parent.bPtr<sp/>=<sp/>root;</highlight></codeline>
<codeline lineno="356"><highlight class="comment"><sp/>//<sp/><sp/><sp/>strncpy(root-&gt;keys[0],<sp/>newNode-&gt;keys[0],<sp/>B_MAX_NAME_LENGTH);</highlight></codeline>
<codeline lineno="357"><highlight class="comment"><sp/><sp/><sp/><sp/>strncpy(root-&gt;keys[0],<sp/>tmpInode-&gt;name,<sp/>B_MAX_NAME_LENGTH);</highlight></codeline>
<codeline lineno="358"><highlight class="comment"><sp/><sp/><sp/><sp/>root-&gt;head[0].bPtr<sp/>=<sp/>oldNode;</highlight></codeline>
<codeline lineno="359"><highlight class="comment"><sp/><sp/><sp/><sp/>root-&gt;tail[0].bPtr<sp/>=<sp/>root-&gt;tail[1].bPtr<sp/>=<sp/>NULL;</highlight></codeline>
<codeline lineno="360"><highlight class="comment"><sp/><sp/><sp/><sp/>root-&gt;head[1].bPtr<sp/>=<sp/>newNode;</highlight></codeline>
<codeline lineno="361"><highlight class="comment"><sp/><sp/><sp/><sp/>root-&gt;used<sp/>=<sp/>1;</highlight></codeline>
<codeline lineno="362"><highlight class="comment"><sp/><sp/><sp/><sp/>root-&gt;leaf<sp/>=<sp/>false;</highlight></codeline>
<codeline lineno="363"><highlight class="comment"><sp/><sp/><sp/><sp/>root-&gt;present[0]<sp/>=<sp/>root-&gt;present[1]<sp/>=<sp/>true;</highlight></codeline>
<codeline lineno="364"><highlight class="comment"><sp/><sp/><sp/><sp/>root-&gt;childCount[0]<sp/>=<sp/>root-&gt;childCount[1]<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="365"><highlight class="comment">//<sp/><sp/><sp/><sp/>root-&gt;childCount[0]<sp/>=<sp/>oldNode-&gt;used;</highlight></codeline>
<codeline lineno="366"><highlight class="comment">//<sp/><sp/><sp/><sp/>root-&gt;childCount[1]<sp/>=<sp/>newNode-&gt;used;</highlight></codeline>
<codeline lineno="367"><highlight class="comment"></highlight></codeline>
<codeline lineno="368"><highlight class="comment">//<sp/>cout<sp/>&lt;&lt;<sp/>&quot;parent&quot;<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="369"><highlight class="comment">//<sp/>Info(newNode-&gt;parent);</highlight></codeline>
<codeline lineno="370"><highlight class="comment">//<sp/>cout<sp/>&lt;&lt;<sp/>&quot;oldNode&quot;<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="371"><highlight class="comment">//<sp/>Info(oldNode);</highlight></codeline>
<codeline lineno="372"><highlight class="comment">//<sp/>cout<sp/>&lt;&lt;<sp/>&quot;-----&quot;<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="373"><highlight class="comment">//<sp/>cout<sp/>&lt;&lt;<sp/>&quot;newNode&quot;<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="374"><highlight class="comment">//<sp/>Info(newNode);</highlight></codeline>
<codeline lineno="375"><highlight class="comment">//<sp/>cout<sp/>&lt;&lt;<sp/>&quot;-----&quot;<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="376"><highlight class="comment"></highlight></codeline>
<codeline lineno="377"><highlight class="comment"><sp/><sp/>}<sp/>else<sp/>{</highlight></codeline>
<codeline lineno="378"><highlight class="comment"><sp/><sp/><sp/><sp/>insertNode(newNode-&gt;parent.bPtr,<sp/>tmpInode-&gt;name,<sp/>newNode);</highlight></codeline>
<codeline lineno="379"><highlight class="comment"><sp/><sp/><sp/>//<sp/>if<sp/>(oldNode-&gt;parent-&gt;used<sp/>==<sp/>B_MAX_KEYS)<sp/>splitNode(oldNode-&gt;parent);</highlight></codeline>
<codeline lineno="380"><highlight class="comment"><sp/><sp/>}<sp/>//<sp/>else</highlight></codeline>
<codeline lineno="381"><highlight class="comment"><sp/><sp/>return;</highlight></codeline>
<codeline lineno="382"><highlight class="comment">}<sp/>//<sp/>bTree::splitNode</highlight></codeline>
<codeline lineno="383"><highlight class="comment"></highlight></codeline>
<codeline lineno="384"><highlight class="comment">void</highlight></codeline>
<codeline lineno="385"><highlight class="comment">bTree::insertNode(bNode<sp/>*<sp/>node,<sp/>const<sp/>char<sp/>*<sp/>key,<sp/>bNode<sp/>*<sp/>headPtr)<sp/>{</highlight></codeline>
<codeline lineno="386"><highlight class="comment"><sp/><sp/>unsigned<sp/>int<sp/>curSlot<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="387"><highlight class="comment"><sp/><sp/>if<sp/>(node<sp/>==<sp/>NULL<sp/>||<sp/>key<sp/>==<sp/>NULL)<sp/>return;</highlight></codeline>
<codeline lineno="388"><highlight class="comment"></highlight></codeline>
<codeline lineno="389"><highlight class="comment"><sp/><sp/>if<sp/>(strcmp(key,<sp/>node-&gt;keys[node-&gt;used-1])<sp/>&gt;=<sp/>0){</highlight></codeline>
<codeline lineno="390"><highlight class="comment"><sp/><sp/><sp/><sp/>curSlot<sp/>=<sp/>node-&gt;used;</highlight></codeline>
<codeline lineno="391"><highlight class="comment"><sp/><sp/><sp/><sp/>memset(node-&gt;keys[curSlot],<sp/>0,<sp/>B_MAX_NAME_LENGTH);</highlight></codeline>
<codeline lineno="392"><highlight class="comment"><sp/><sp/><sp/><sp/>strncpy(node-&gt;keys[curSlot],<sp/>key,<sp/>B_MAX_NAME_LENGTH);</highlight></codeline>
<codeline lineno="393"><highlight class="comment"><sp/><sp/><sp/><sp/>node-&gt;head[curSlot+1].bPtr<sp/>=<sp/>headPtr;</highlight></codeline>
<codeline lineno="394"><highlight class="comment"><sp/><sp/><sp/><sp/>node-&gt;tail[curSlot+1].bPtr<sp/>=<sp/>NULL;</highlight></codeline>
<codeline lineno="395"><highlight class="comment"><sp/><sp/><sp/><sp/>node-&gt;present[curSlot+1]<sp/>=<sp/>true;</highlight></codeline>
<codeline lineno="396"><highlight class="comment"><sp/><sp/><sp/><sp/>node-&gt;childCount[node-&gt;used]<sp/>=<sp/>0;<sp/>//<sp/>maybe?</highlight></codeline>
<codeline lineno="397"><highlight class="comment"></highlight></codeline>
<codeline lineno="398"><highlight class="comment"><sp/><sp/>}<sp/>else<sp/>{</highlight></codeline>
<codeline lineno="399"><highlight class="comment"></highlight></codeline>
<codeline lineno="400"><highlight class="comment"><sp/><sp/><sp/><sp/>for<sp/>(curSlot<sp/>=<sp/>0;<sp/>curSlot<sp/>&lt;<sp/>node-&gt;used;<sp/>curSlot++)<sp/>{</highlight></codeline>
<codeline lineno="401"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>if<sp/>(strcmp(key,<sp/>node-&gt;keys[curSlot])<sp/>&lt;<sp/>0)<sp/>break;</highlight></codeline>
<codeline lineno="402"><highlight class="comment"><sp/><sp/><sp/><sp/>}<sp/>//<sp/>for<sp/></highlight></codeline>
<codeline lineno="403"><highlight class="comment"></highlight></codeline>
<codeline lineno="404"><highlight class="comment"></highlight></codeline>
<codeline lineno="405"><highlight class="comment"><sp/><sp/><sp/><sp/>*/</highlight><highlight class="comment">/*</highlight></codeline>
<codeline lineno="406"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/>*<sp/>note<sp/>that<sp/>there<sp/>is<sp/>one<sp/>more<sp/>item<sp/>for<sp/>everything<sp/>but<sp/>keys</highlight></codeline>
<codeline lineno="407"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/>*<sp/>So,<sp/>make<sp/>the<sp/>shift<sp/>count<sp/>+1<sp/>and<sp/>just<sp/>subtract<sp/>it<sp/>from<sp/>the<sp/>key<sp/>shift</highlight></codeline>
<codeline lineno="408"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/>*<sp/>later</highlight></codeline>
<codeline lineno="409"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/>*/</highlight><highlight class="comment">/*</highlight></codeline>
<codeline lineno="410"><highlight class="comment"><sp/><sp/><sp/><sp/>int<sp/>shift<sp/>=<sp/>node-&gt;used<sp/>-<sp/>curSlot<sp/>+1;</highlight></codeline>
<codeline lineno="411"><highlight class="comment"></highlight></codeline>
<codeline lineno="412"><highlight class="comment"><sp/><sp/><sp/><sp/>memmove(&amp;node-&gt;head[curSlot+1],</highlight></codeline>
<codeline lineno="413"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>&amp;node-&gt;head[curSlot],</highlight></codeline>
<codeline lineno="414"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>sizeof(node-&gt;head[0])<sp/>*<sp/>shift);</highlight></codeline>
<codeline lineno="415"><highlight class="comment"><sp/><sp/><sp/><sp/>memmove(&amp;node-&gt;tail[curSlot+1],</highlight></codeline>
<codeline lineno="416"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>&amp;node-&gt;tail[curSlot],</highlight></codeline>
<codeline lineno="417"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>sizeof(node-&gt;tail[0])<sp/>*<sp/>shift);</highlight></codeline>
<codeline lineno="418"><highlight class="comment"><sp/><sp/><sp/><sp/>memmove(&amp;node-&gt;present[curSlot+1],</highlight></codeline>
<codeline lineno="419"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>&amp;node-&gt;present[curSlot],</highlight></codeline>
<codeline lineno="420"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>sizeof(node-&gt;present[0])<sp/>*<sp/>shift);</highlight></codeline>
<codeline lineno="421"><highlight class="comment"><sp/><sp/><sp/><sp/>memmove(&amp;node-&gt;childCount[curSlot+1],</highlight></codeline>
<codeline lineno="422"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>&amp;node-&gt;childCount[curSlot],</highlight></codeline>
<codeline lineno="423"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>sizeof(node-&gt;childCount[0])<sp/>*<sp/>shift);</highlight></codeline>
<codeline lineno="424"><highlight class="comment"></highlight></codeline>
<codeline lineno="425"><highlight class="comment"><sp/><sp/><sp/><sp/>memmove(&amp;node-&gt;keys[curSlot+1],</highlight></codeline>
<codeline lineno="426"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>&amp;node-&gt;keys[curSlot],</highlight></codeline>
<codeline lineno="427"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>sizeof(node-&gt;keys[0])<sp/>*<sp/>(shift-1));</highlight></codeline>
<codeline lineno="428"><highlight class="comment"><sp/><sp/><sp/><sp/></highlight></codeline>
<codeline lineno="429"><highlight class="comment"><sp/><sp/><sp/><sp/>memset(node-&gt;keys[curSlot],<sp/>0,<sp/>B_MAX_NAME_LENGTH);</highlight></codeline>
<codeline lineno="430"><highlight class="comment"><sp/><sp/><sp/><sp/>strncpy(node-&gt;keys[curSlot],<sp/>key,<sp/>B_MAX_NAME_LENGTH);</highlight></codeline>
<codeline lineno="431"><highlight class="comment"><sp/><sp/><sp/><sp/>node-&gt;head[curSlot+1].bPtr<sp/>=<sp/>headPtr;</highlight></codeline>
<codeline lineno="432"><highlight class="comment"><sp/><sp/><sp/><sp/>node-&gt;tail[curSlot+1].bPtr<sp/>=<sp/>NULL;</highlight></codeline>
<codeline lineno="433"><highlight class="comment"><sp/><sp/><sp/><sp/>node-&gt;present[curSlot+1]<sp/>=<sp/>true;</highlight></codeline>
<codeline lineno="434"><highlight class="comment">//<sp/><sp/><sp/><sp/>node-&gt;childCount[node-&gt;used]<sp/>=<sp/>?;</highlight></codeline>
<codeline lineno="435"><highlight class="comment"><sp/><sp/>}<sp/>//<sp/>else<sp/></highlight></codeline>
<codeline lineno="436"><highlight class="comment"><sp/><sp/>if<sp/>(++node-&gt;used<sp/>==<sp/>B_MAX_KEYS)<sp/>splitNode(node);<sp/></highlight></codeline>
<codeline lineno="437"><highlight class="comment"><sp/><sp/>return;</highlight></codeline>
<codeline lineno="438"><highlight class="comment">}<sp/>//<sp/>bTree::insertNode</highlight></codeline>
<codeline lineno="439"><highlight class="comment"></highlight></codeline>
<codeline lineno="440"><highlight class="comment">bNode<sp/>*</highlight></codeline>
<codeline lineno="441"><highlight class="comment">bTree::allocEmptyNode(void)<sp/>{</highlight></codeline>
<codeline lineno="442"><highlight class="comment"><sp/><sp/>bNode<sp/>*<sp/>newNode<sp/>=<sp/>new<sp/>bNode;</highlight></codeline>
<codeline lineno="443"><highlight class="comment"></highlight></codeline>
<codeline lineno="444"><highlight class="comment"><sp/><sp/>memset(newNode,<sp/>0,<sp/>sizeof(bNode));</highlight></codeline>
<codeline lineno="445"><highlight class="comment"><sp/><sp/>newNode-&gt;magic1<sp/>=<sp/>B_NODE_MAGIC_1;</highlight></codeline>
<codeline lineno="446"><highlight class="comment"><sp/><sp/>newNode-&gt;magic2<sp/>=<sp/>B_NODE_MAGIC_2;</highlight></codeline>
<codeline lineno="447"><highlight class="comment"><sp/><sp/>newNode-&gt;parent.bPtr<sp/>=<sp/>NULL;</highlight></codeline>
<codeline lineno="448"><highlight class="comment"><sp/><sp/>newNode-&gt;tag<sp/>=<sp/>++tag;<sp/>//<sp/>this<sp/>will<sp/>start<sp/>at<sp/>1<sp/>(0<sp/>is<sp/>the<sp/>header<sp/>node)</highlight></codeline>
<codeline lineno="449"><highlight class="comment"><sp/><sp/>return<sp/>newNode;</highlight></codeline>
<codeline lineno="450"><highlight class="comment">}<sp/>//<sp/>bTree::allocEmptyNode</highlight></codeline>
<codeline lineno="451"><highlight class="comment"></highlight></codeline>
<codeline lineno="452"><highlight class="comment">void</highlight></codeline>
<codeline lineno="453"><highlight class="comment">bTree::Info(const<sp/>bNode<sp/>*<sp/>node)<sp/>{</highlight></codeline>
<codeline lineno="454"><highlight class="comment"><sp/><sp/>ubixfsInode<sp/>*<sp/>inode<sp/>=<sp/>NULL;</highlight></codeline>
<codeline lineno="455"><highlight class="comment"><sp/><sp/>if<sp/>(node<sp/>==<sp/>NULL<sp/>||<sp/>root<sp/>==<sp/>NULL)<sp/>return;</highlight></codeline>
<codeline lineno="456"><highlight class="comment"><sp/><sp/>cout<sp/>&lt;&lt;<sp/><sp/>node<sp/>&lt;&lt;<sp/>&quot;<sp/>|<sp/>&quot;<sp/>&lt;&lt;<sp/>node-&gt;parent.bPtr<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="457"><highlight class="comment"><sp/><sp/>for<sp/>(unsigned<sp/>int<sp/>i<sp/>=<sp/>0;<sp/>i<sp/>&lt;=<sp/>node-&gt;used;<sp/>i++)<sp/>{</highlight></codeline>
<codeline lineno="458"><highlight class="comment"><sp/><sp/><sp/><sp/>inode<sp/>=<sp/>node-&gt;head[i].iPtr;</highlight></codeline>
<codeline lineno="459"><highlight class="comment">//<sp/><sp/><sp/><sp/>cout<sp/>&lt;&lt;<sp/>&quot;(&quot;<sp/>&lt;&lt;<sp/>node-&gt;childCount[i]<sp/>&lt;&lt;<sp/>&quot;)&quot;;</highlight></codeline>
<codeline lineno="460"><highlight class="comment"><sp/><sp/><sp/><sp/>for<sp/>(unsigned<sp/>int<sp/>k<sp/>=<sp/>0;<sp/>k<sp/>&lt;<sp/>node-&gt;childCount[i];<sp/>k++)<sp/>{</highlight></codeline>
<codeline lineno="461"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>cout<sp/>&lt;&lt;<sp/>&quot;[&quot;<sp/>&lt;&lt;<sp/>inode-&gt;name<sp/>&lt;&lt;<sp/>&quot;]&quot;;</highlight></codeline>
<codeline lineno="462"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>inode<sp/>=<sp/>inode-&gt;next.iPtr;</highlight></codeline>
<codeline lineno="463"><highlight class="comment"><sp/><sp/><sp/><sp/>}<sp/>//<sp/>for<sp/>k</highlight></codeline>
<codeline lineno="464"><highlight class="comment"><sp/><sp/><sp/><sp/>if<sp/>(i<sp/>!=<sp/>node-&gt;used)<sp/>cout<sp/>&lt;&lt;<sp/>&quot;<sp/>{&quot;<sp/>&lt;&lt;<sp/>node-&gt;keys[i]<sp/>&lt;&lt;<sp/>&quot;}<sp/>&quot;;</highlight></codeline>
<codeline lineno="465"><highlight class="comment"><sp/><sp/>}<sp/>//<sp/>for<sp/>i</highlight></codeline>
<codeline lineno="466"><highlight class="comment"><sp/><sp/>cout<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="467"><highlight class="comment"><sp/><sp/>return;</highlight></codeline>
<codeline lineno="468"><highlight class="comment">#if<sp/>0</highlight></codeline>
<codeline lineno="469"><highlight class="comment"><sp/><sp/>for<sp/>(unsigned<sp/>int<sp/>i<sp/>=<sp/>0;<sp/>i<sp/>&lt;<sp/>node-&gt;used;<sp/>i++)<sp/>{</highlight></codeline>
<codeline lineno="470"><highlight class="comment"><sp/><sp/><sp/><sp/>cout<sp/>&lt;&lt;<sp/>&quot;keys[&quot;<sp/>&lt;&lt;<sp/>i<sp/>&lt;&lt;<sp/>&quot;]:<sp/>&quot;<sp/>&lt;&lt;<sp/>node-&gt;keys[i]<sp/>&lt;&lt;<sp/>&quot;<sp/><sp/>&quot;;</highlight></codeline>
<codeline lineno="471"><highlight class="comment"><sp/><sp/>}<sp/>//<sp/>for<sp/>i</highlight></codeline>
<codeline lineno="472"><highlight class="comment"><sp/><sp/>cout<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="473"><highlight class="comment"><sp/><sp/>cout<sp/>&lt;&lt;<sp/>&quot;node-&gt;used:<sp/>&quot;<sp/>&lt;&lt;<sp/>node-&gt;used<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="474"><highlight class="comment"><sp/><sp/>cout<sp/>&lt;&lt;<sp/>&quot;leaf:<sp/>&quot;<sp/>&lt;&lt;<sp/>node-&gt;leaf<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="475"><highlight class="comment"><sp/><sp/>for<sp/>(unsigned<sp/>int<sp/>i<sp/>=<sp/>0;<sp/>i<sp/>&lt;=<sp/>node-&gt;used;<sp/>i++)<sp/>{</highlight></codeline>
<codeline lineno="476"><highlight class="comment"><sp/><sp/><sp/><sp/>inode<sp/>=<sp/>(ubixfsInode<sp/>*)node-&gt;head[i];</highlight></codeline>
<codeline lineno="477"><highlight class="comment">cout<sp/>&lt;&lt;<sp/>&quot;node-&gt;childCount[&quot;&lt;&lt;i&lt;&lt;&quot;]:<sp/>&quot;<sp/>&lt;&lt;<sp/>node-&gt;childCount[i]<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="478"><highlight class="comment"><sp/><sp/><sp/><sp/>for<sp/>(unsigned<sp/>int<sp/>j<sp/>=<sp/>0;<sp/>j<sp/>&lt;<sp/>node-&gt;childCount[i];<sp/>j++)<sp/>{</highlight></codeline>
<codeline lineno="479"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>assert(inode);</highlight></codeline>
<codeline lineno="480"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>cout<sp/>&lt;&lt;<sp/>&quot;[&quot;<sp/>&lt;&lt;<sp/>i<sp/>&lt;&lt;<sp/>&quot;].[&quot;<sp/>&lt;&lt;<sp/>j<sp/>&lt;&lt;<sp/>&quot;]-&gt;&quot;<sp/>&lt;&lt;<sp/>inode-&gt;name<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="481"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>inode<sp/>=<sp/>inode-&gt;next;</highlight></codeline>
<codeline lineno="482"><highlight class="comment"><sp/><sp/><sp/><sp/>}<sp/>//<sp/>for<sp/>j</highlight></codeline>
<codeline lineno="483"><highlight class="comment"><sp/><sp/>}<sp/>//<sp/>for<sp/>i</highlight></codeline>
<codeline lineno="484"><highlight class="comment">#endif</highlight></codeline>
<codeline lineno="485"><highlight class="comment">}<sp/>//<sp/>bTree::Info</highlight></codeline>
<codeline lineno="486"><highlight class="comment"></highlight></codeline>
<codeline lineno="487"><highlight class="comment">void</highlight></codeline>
<codeline lineno="488"><highlight class="comment">bTree::Info(void)<sp/>{</highlight></codeline>
<codeline lineno="489"><highlight class="comment"><sp/><sp/>ubixfsInode<sp/>*<sp/>inode<sp/>=<sp/>NULL;</highlight></codeline>
<codeline lineno="490"><highlight class="comment"></highlight></codeline>
<codeline lineno="491"><highlight class="comment"><sp/><sp/>cout<sp/>&lt;&lt;<sp/>&quot;tree<sp/>depth:<sp/>&quot;<sp/>&lt;&lt;<sp/>header-&gt;treeDepth<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="492"><highlight class="comment"><sp/><sp/>cout<sp/>&lt;&lt;<sp/>&quot;tree<sp/>width:<sp/>&quot;<sp/>&lt;&lt;<sp/>header-&gt;treeWidth<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="493"><highlight class="comment"><sp/><sp/>cout<sp/>&lt;&lt;<sp/>&quot;tree<sp/>leaf<sp/>count:<sp/>&quot;<sp/>&lt;&lt;<sp/>header-&gt;treeLeafCount<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="494"><highlight class="comment"><sp/><sp/>cout<sp/>&lt;&lt;<sp/>&quot;tag:<sp/>&quot;<sp/>&lt;&lt;<sp/>tag<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="495"><highlight class="comment"></highlight></codeline>
<codeline lineno="496"><highlight class="comment"><sp/><sp/>if<sp/>(root<sp/>==<sp/>NULL)<sp/>return;</highlight></codeline>
<codeline lineno="497"><highlight class="comment"></highlight></codeline>
<codeline lineno="498"><highlight class="comment"><sp/><sp/>for<sp/>(unsigned<sp/>int<sp/>i<sp/>=<sp/>0;<sp/>i<sp/>&lt;=<sp/>root-&gt;used;<sp/>i++)<sp/>{</highlight></codeline>
<codeline lineno="499"><highlight class="comment"><sp/><sp/><sp/><sp/>cout<sp/>&lt;&lt;<sp/>&quot;CC[&quot;<sp/>&lt;&lt;<sp/>i<sp/>&lt;&lt;<sp/>&quot;]:<sp/>&quot;<sp/>&lt;&lt;<sp/>root-&gt;childCount[i]<sp/>&lt;&lt;<sp/>&quot;<sp/><sp/>&quot;;</highlight></codeline>
<codeline lineno="500"><highlight class="comment"><sp/><sp/>}<sp/>//<sp/>for<sp/>i</highlight></codeline>
<codeline lineno="501"><highlight class="comment"></highlight></codeline>
<codeline lineno="502"><highlight class="comment"><sp/><sp/>cout<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="503"><highlight class="comment"><sp/><sp/>for<sp/>(unsigned<sp/>int<sp/>i<sp/>=<sp/>0;<sp/>i<sp/>&lt;=<sp/>root-&gt;used;<sp/>i++)<sp/>{</highlight></codeline>
<codeline lineno="504"><highlight class="comment"><sp/><sp/><sp/><sp/>cout<sp/>&lt;&lt;<sp/>&quot;CH[&quot;<sp/>&lt;&lt;<sp/>i<sp/>&lt;&lt;<sp/>&quot;]:<sp/>&quot;<sp/>&lt;&lt;<sp/>root-&gt;head[i].bPtr<sp/>&lt;&lt;<sp/>&quot;<sp/><sp/>&quot;;</highlight></codeline>
<codeline lineno="505"><highlight class="comment"><sp/><sp/>}<sp/>//<sp/>for<sp/>i</highlight></codeline>
<codeline lineno="506"><highlight class="comment"></highlight></codeline>
<codeline lineno="507"><highlight class="comment"><sp/><sp/>cout<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="508"><highlight class="comment"><sp/><sp/>for<sp/>(unsigned<sp/>int<sp/>i<sp/>=<sp/>0;<sp/>i<sp/>&lt;=root-&gt;used;<sp/>i++)<sp/>{</highlight></codeline>
<codeline lineno="509"><highlight class="comment"><sp/><sp/><sp/><sp/>cout<sp/>&lt;&lt;<sp/>&quot;CT[&quot;<sp/>&lt;&lt;<sp/>i<sp/>&lt;&lt;<sp/>&quot;]:<sp/>&quot;<sp/>&lt;&lt;<sp/>root-&gt;tail[i].bPtr<sp/>&lt;&lt;<sp/>&quot;<sp/><sp/>&quot;;</highlight></codeline>
<codeline lineno="510"><highlight class="comment"><sp/><sp/>}<sp/>//<sp/>for<sp/>i</highlight></codeline>
<codeline lineno="511"><highlight class="comment"><sp/><sp/>cout<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="512"><highlight class="comment"><sp/><sp/>for<sp/>(unsigned<sp/>int<sp/>i<sp/>=<sp/>0;<sp/>i<sp/>&lt;<sp/>root-&gt;used;<sp/>i++)<sp/>{</highlight></codeline>
<codeline lineno="513"><highlight class="comment"><sp/><sp/><sp/><sp/>cout<sp/>&lt;&lt;<sp/>&quot;keys[&quot;<sp/>&lt;&lt;<sp/>i<sp/>&lt;&lt;<sp/>&quot;]:<sp/>&quot;<sp/>&lt;&lt;<sp/>root-&gt;keys[i]<sp/>&lt;&lt;<sp/>&quot;<sp/><sp/>&quot;;</highlight></codeline>
<codeline lineno="514"><highlight class="comment"><sp/><sp/>}<sp/>//<sp/>for<sp/>i</highlight></codeline>
<codeline lineno="515"><highlight class="comment"><sp/><sp/>cout<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="516"><highlight class="comment"></highlight></codeline>
<codeline lineno="517"><highlight class="comment">cout<sp/>&lt;&lt;<sp/>&quot;root-&gt;used:<sp/>&quot;<sp/>&lt;&lt;<sp/>root-&gt;used<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="518"><highlight class="comment"><sp/><sp/><sp/><sp/>for<sp/>(unsigned<sp/>int<sp/>i<sp/>=<sp/>0;<sp/>i<sp/>&lt;=<sp/>root-&gt;used;<sp/>i++)<sp/>{</highlight></codeline>
<codeline lineno="519"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>inode<sp/>=<sp/>root-&gt;head[i].iPtr;</highlight></codeline>
<codeline lineno="520"><highlight class="comment">cout<sp/>&lt;&lt;<sp/>&quot;root-&gt;childCount[&quot;&lt;&lt;i&lt;&lt;&quot;]:<sp/>&quot;<sp/>&lt;&lt;<sp/>root-&gt;childCount[i]<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="521"><highlight class="comment"><sp/><sp/><sp/><sp/>if<sp/>(root-&gt;leaf)<sp/>{</highlight></codeline>
<codeline lineno="522"><highlight class="comment">cout<sp/>&lt;&lt;<sp/>&quot;root<sp/>contains<sp/>leaf<sp/>node&quot;<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="523"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>for<sp/>(unsigned<sp/>int<sp/>j<sp/>=<sp/>0;<sp/>j<sp/>&lt;<sp/>root-&gt;childCount[i];<sp/>j++)<sp/>{</highlight></codeline>
<codeline lineno="524"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>assert(inode);</highlight></codeline>
<codeline lineno="525"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>cout<sp/>&lt;&lt;<sp/>&quot;[&quot;<sp/>&lt;&lt;<sp/>i<sp/>&lt;&lt;<sp/>&quot;].[&quot;<sp/>&lt;&lt;<sp/>j<sp/>&lt;&lt;<sp/>&quot;]-&gt;&quot;<sp/>&lt;&lt;<sp/>inode-&gt;name<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="526"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>inode<sp/>=<sp/>inode-&gt;next.iPtr;</highlight></codeline>
<codeline lineno="527"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>}<sp/>//<sp/>for<sp/>j</highlight></codeline>
<codeline lineno="528"><highlight class="comment"><sp/><sp/><sp/><sp/>}<sp/>//<sp/>if<sp/>root-&gt;leaf</highlight></codeline>
<codeline lineno="529"><highlight class="comment"><sp/><sp/>}<sp/>//<sp/>for<sp/>i</highlight></codeline>
<codeline lineno="530"><highlight class="comment">}<sp/>//<sp/>bTree::Info</highlight></codeline>
<codeline lineno="531"><highlight class="comment"></highlight></codeline>
<codeline lineno="532"><highlight class="comment">void</highlight></codeline>
<codeline lineno="533"><highlight class="comment">bTree::Print(void)<sp/>{</highlight></codeline>
<codeline lineno="534"><highlight class="comment"><sp/><sp/>ubixfsInode<sp/>*<sp/>node<sp/>=<sp/>GetFirstNode();</highlight></codeline>
<codeline lineno="535"><highlight class="comment"><sp/><sp/>while<sp/>(node<sp/>!=<sp/>NULL)<sp/>{</highlight></codeline>
<codeline lineno="536"><highlight class="comment"><sp/><sp/><sp/><sp/>cout<sp/>&lt;&lt;<sp/>node-&gt;name<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="537"><highlight class="comment"><sp/><sp/><sp/><sp/>node<sp/>=<sp/>node-&gt;next.iPtr;</highlight></codeline>
<codeline lineno="538"><highlight class="comment"><sp/><sp/>}</highlight></codeline>
<codeline lineno="539"><highlight class="comment">}<sp/>//<sp/>bTree::Print</highlight></codeline>
<codeline lineno="540"><highlight class="comment"></highlight></codeline>
<codeline lineno="541"><highlight class="comment">ubixfsInode<sp/>*</highlight></codeline>
<codeline lineno="542"><highlight class="comment">bTree::Find(const<sp/>char<sp/>*<sp/>key)<sp/>{</highlight></codeline>
<codeline lineno="543"><highlight class="comment"></highlight></codeline>
<codeline lineno="544"><highlight class="comment">*/</highlight><highlight class="comment">/*</highlight></codeline>
<codeline lineno="545"><highlight class="comment"><sp/><sp/>ubixfsInode<sp/>*<sp/>tmp<sp/>=<sp/>GetFirstNode();</highlight></codeline>
<codeline lineno="546"><highlight class="comment"><sp/><sp/>while<sp/>(tmp!=NULL)<sp/>{</highlight></codeline>
<codeline lineno="547"><highlight class="comment"><sp/><sp/><sp/><sp/>if<sp/>(strcmp(tmp-&gt;name,<sp/>key)<sp/>==<sp/>0)<sp/>return<sp/>tmp;</highlight></codeline>
<codeline lineno="548"><highlight class="comment"><sp/><sp/><sp/><sp/>tmp<sp/>=<sp/>tmp-&gt;next.iPtr;</highlight></codeline>
<codeline lineno="549"><highlight class="comment"><sp/><sp/>}</highlight></codeline>
<codeline lineno="550"><highlight class="comment"><sp/><sp/>return<sp/>NULL;</highlight></codeline>
<codeline lineno="551"><highlight class="comment">*/</highlight><highlight class="comment">/*</highlight></codeline>
<codeline lineno="552"><highlight class="comment"><sp/><sp/>return<sp/>treeSearch(root,<sp/>key);</highlight></codeline>
<codeline lineno="553"><highlight class="comment">}<sp/>//<sp/>bTree::Find</highlight></codeline>
<codeline lineno="554"><highlight class="comment"></highlight></codeline>
<codeline lineno="555"><highlight class="comment">ubixfsInode<sp/>*</highlight></codeline>
<codeline lineno="556"><highlight class="comment">bTree::inodeSearch(ubixfsInode<sp/>*<sp/>inode,<sp/>const<sp/>char<sp/>*<sp/>key)<sp/>{</highlight></codeline>
<codeline lineno="557"><highlight class="comment"><sp/><sp/>if<sp/>(inode<sp/>==<sp/>NULL<sp/>||<sp/>key<sp/>==<sp/>NULL)<sp/>return<sp/>NULL;</highlight></codeline>
<codeline lineno="558"><highlight class="comment"><sp/><sp/>int<sp/>result<sp/>=<sp/>strcmp(inode-&gt;name,<sp/>key);</highlight></codeline>
<codeline lineno="559"><highlight class="comment"><sp/><sp/>if<sp/>(result<sp/>==<sp/>0)<sp/>return<sp/>inode;</highlight></codeline>
<codeline lineno="560"><highlight class="comment"></highlight></codeline>
<codeline lineno="561"><highlight class="comment"><sp/><sp/>if<sp/>(result<sp/>&lt;<sp/>0)<sp/>{</highlight></codeline>
<codeline lineno="562"><highlight class="comment"><sp/><sp/><sp/><sp/>inode<sp/>=<sp/>inode-&gt;next.iPtr;</highlight></codeline>
<codeline lineno="563"><highlight class="comment"><sp/><sp/><sp/><sp/>while<sp/>(inode<sp/>!=<sp/>NULL<sp/>&amp;&amp;<sp/>((result<sp/>=<sp/>strcmp(inode-&gt;name,<sp/>key))<sp/>&lt;<sp/>0))<sp/>{</highlight></codeline>
<codeline lineno="564"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>inode<sp/>=<sp/>inode-&gt;next.iPtr;</highlight></codeline>
<codeline lineno="565"><highlight class="comment"><sp/><sp/><sp/><sp/>}<sp/>//<sp/>while</highlight></codeline>
<codeline lineno="566"><highlight class="comment"><sp/><sp/>}<sp/>else<sp/>{</highlight></codeline>
<codeline lineno="567"><highlight class="comment"><sp/><sp/><sp/><sp/>inode<sp/>=<sp/>inode-&gt;prev.iPtr;</highlight></codeline>
<codeline lineno="568"><highlight class="comment"><sp/><sp/><sp/><sp/>while<sp/>(inode<sp/>!=<sp/>NULL<sp/>&amp;&amp;<sp/>((result<sp/>=<sp/>strcmp(inode-&gt;name,<sp/>key))<sp/>&gt;<sp/>0))<sp/>{</highlight></codeline>
<codeline lineno="569"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>inode<sp/>=<sp/>inode-&gt;prev.iPtr;</highlight></codeline>
<codeline lineno="570"><highlight class="comment"><sp/><sp/><sp/><sp/>}<sp/>//<sp/>while</highlight></codeline>
<codeline lineno="571"><highlight class="comment"><sp/><sp/>}<sp/>//<sp/>else</highlight></codeline>
<codeline lineno="572"><highlight class="comment"><sp/><sp/>return<sp/>(result<sp/>==<sp/>0<sp/>?<sp/>inode<sp/>:<sp/>NULL);</highlight></codeline>
<codeline lineno="573"><highlight class="comment">}<sp/>//<sp/>bTree::inodeSearch</highlight></codeline>
<codeline lineno="574"><highlight class="comment"></highlight></codeline>
<codeline lineno="575"><highlight class="comment">ubixfsInode<sp/>*</highlight></codeline>
<codeline lineno="576"><highlight class="comment">bTree::treeSearch(bNode<sp/>*<sp/>bnode,<sp/>const<sp/>char<sp/>*<sp/>key)<sp/>{</highlight></codeline>
<codeline lineno="577"><highlight class="comment"></highlight></codeline>
<codeline lineno="578"><highlight class="comment"><sp/><sp/>if<sp/>(bnode<sp/>==<sp/>NULL<sp/>||<sp/>key<sp/>==<sp/>NULL<sp/>||<sp/>bnode-&gt;used<sp/>==<sp/>0)<sp/>return<sp/>NULL;</highlight></codeline>
<codeline lineno="579"><highlight class="comment"><sp/></highlight></codeline>
<codeline lineno="580"><highlight class="comment"><sp/><sp/>if<sp/>(bnode-&gt;leaf)<sp/></highlight></codeline>
<codeline lineno="581"><highlight class="comment"><sp/><sp/><sp/><sp/>return<sp/>inodeSearch(GetFirstNode(bnode),<sp/>key);</highlight></codeline>
<codeline lineno="582"><highlight class="comment"></highlight></codeline>
<codeline lineno="583"><highlight class="comment"><sp/><sp/>if<sp/>(strcmp(key,<sp/>bnode-&gt;keys[0])<sp/>&lt;<sp/>0)<sp/>{</highlight></codeline>
<codeline lineno="584"><highlight class="comment"><sp/><sp/><sp/><sp/>return<sp/>treeSearch(bnode-&gt;head[0].bPtr,<sp/>key);</highlight></codeline>
<codeline lineno="585"><highlight class="comment"><sp/><sp/>}<sp/>//<sp/>if</highlight></codeline>
<codeline lineno="586"><highlight class="comment"></highlight></codeline>
<codeline lineno="587"><highlight class="comment"><sp/><sp/>if<sp/>(strcmp(key,<sp/>bnode-&gt;keys[bnode-&gt;used-1])<sp/>&gt;=<sp/>0)<sp/>{</highlight></codeline>
<codeline lineno="588"><highlight class="comment"><sp/><sp/><sp/><sp/>return<sp/>treeSearch(bnode-&gt;head[bnode-&gt;used].bPtr,<sp/>key);</highlight></codeline>
<codeline lineno="589"><highlight class="comment"><sp/><sp/>}<sp/>//<sp/>if</highlight></codeline>
<codeline lineno="590"><highlight class="comment"></highlight></codeline>
<codeline lineno="591"><highlight class="comment"><sp/><sp/>for<sp/>(unsigned<sp/>int<sp/>i<sp/>=<sp/>1;<sp/>i<sp/>&lt;<sp/>bnode-&gt;used;<sp/>i++)<sp/>{</highlight></codeline>
<codeline lineno="592"><highlight class="comment"><sp/><sp/><sp/><sp/>if<sp/>(strcmp(key,<sp/>bnode-&gt;keys[i])<sp/>&lt;<sp/>0)<sp/>{</highlight></codeline>
<codeline lineno="593"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>return<sp/>treeSearch(bnode-&gt;head[i].bPtr,<sp/>key);</highlight></codeline>
<codeline lineno="594"><highlight class="comment"><sp/><sp/><sp/><sp/>}<sp/>//<sp/>if</highlight></codeline>
<codeline lineno="595"><highlight class="comment"><sp/><sp/>}<sp/>//<sp/>for<sp/>i</highlight></codeline>
<codeline lineno="596"><highlight class="comment"></highlight></codeline>
<codeline lineno="597"><highlight class="comment"><sp/><sp/>return<sp/>NULL;</highlight></codeline>
<codeline lineno="598"><highlight class="comment">}<sp/>//<sp/>bTree::treeSearch</highlight></codeline>
<codeline lineno="599"><highlight class="comment"></highlight></codeline>
<codeline lineno="600"><highlight class="comment">ubixfsInode<sp/>*<sp/></highlight></codeline>
<codeline lineno="601"><highlight class="comment">bTree::GetFirstNode(void)<sp/>{</highlight></codeline>
<codeline lineno="602"><highlight class="comment"><sp/><sp/>return<sp/>GetFirstNode(root);</highlight></codeline>
<codeline lineno="603"><highlight class="comment">}<sp/>//<sp/>bTree::GetFirstNode</highlight></codeline>
<codeline lineno="604"><highlight class="comment"></highlight></codeline>
<codeline lineno="605"><highlight class="comment">ubixfsInode<sp/>*</highlight></codeline>
<codeline lineno="606"><highlight class="comment">bTree::GetFirstNode(bNode<sp/>*<sp/>node)<sp/>{</highlight></codeline>
<codeline lineno="607"><highlight class="comment"><sp/><sp/>bNode<sp/>*<sp/>tmpNode<sp/>=<sp/>node;</highlight></codeline>
<codeline lineno="608"><highlight class="comment"></highlight></codeline>
<codeline lineno="609"><highlight class="comment"><sp/><sp/>if<sp/>(tmpNode<sp/>==<sp/>NULL)<sp/>return<sp/>NULL;</highlight></codeline>
<codeline lineno="610"><highlight class="comment"></highlight></codeline>
<codeline lineno="611"><highlight class="comment"><sp/><sp/>while<sp/>(!tmpNode-&gt;leaf)<sp/>{</highlight></codeline>
<codeline lineno="612"><highlight class="comment"><sp/><sp/><sp/><sp/>for<sp/>(unsigned<sp/>int<sp/>i<sp/>=<sp/>0;<sp/>i<sp/>&lt;<sp/>tmpNode-&gt;used;<sp/>i++)<sp/>{</highlight></codeline>
<codeline lineno="613"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>if<sp/>(tmpNode-&gt;head[i].bPtr<sp/>!=<sp/>NULL)<sp/>{</highlight></codeline>
<codeline lineno="614"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>tmpNode<sp/>=<sp/>tmpNode-&gt;head[i].bPtr;</highlight></codeline>
<codeline lineno="615"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/><sp/><sp/>break;</highlight></codeline>
<codeline lineno="616"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>}<sp/><sp/>//<sp/>if</highlight></codeline>
<codeline lineno="617"><highlight class="comment"><sp/><sp/><sp/><sp/>}<sp/>//<sp/>for<sp/>i</highlight></codeline>
<codeline lineno="618"><highlight class="comment"><sp/><sp/>}<sp/>//<sp/>while</highlight></codeline>
<codeline lineno="619"><highlight class="comment"></highlight></codeline>
<codeline lineno="620"><highlight class="comment"><sp/><sp/>for<sp/>(unsigned<sp/>int<sp/>i<sp/>=<sp/>0;<sp/>i<sp/>&lt;<sp/>tmpNode-&gt;used;<sp/>i++)<sp/>{</highlight></codeline>
<codeline lineno="621"><highlight class="comment"><sp/><sp/><sp/><sp/>if<sp/>(tmpNode-&gt;head[i].iPtr<sp/>!=<sp/>NULL)<sp/>return<sp/>tmpNode-&gt;head[i].iPtr;</highlight></codeline>
<codeline lineno="622"><highlight class="comment"><sp/><sp/>}<sp/>//<sp/>for<sp/>i</highlight></codeline>
<codeline lineno="623"><highlight class="comment"><sp/><sp/>return<sp/>NULL;</highlight></codeline>
<codeline lineno="624"><highlight class="comment">}<sp/>//<sp/>bTree::GetFirstNode</highlight></codeline>
<codeline lineno="625"><highlight class="comment"></highlight></codeline>
<codeline lineno="626"><highlight class="comment">bNode<sp/>*</highlight></codeline>
<codeline lineno="627"><highlight class="comment">bTree::findLeafNode(bNode<sp/>*<sp/>node,<sp/>const<sp/>char<sp/>*<sp/>key)<sp/>{</highlight></codeline>
<codeline lineno="628"><highlight class="comment"><sp/><sp/>assert(node);</highlight></codeline>
<codeline lineno="629"><highlight class="comment"><sp/><sp/>assert(key);</highlight></codeline>
<codeline lineno="630"><highlight class="comment"><sp/><sp/>if<sp/>(node<sp/>==<sp/>NULL<sp/>||<sp/>key<sp/>==<sp/>NULL)<sp/>return<sp/>NULL;</highlight></codeline>
<codeline lineno="631"><highlight class="comment"><sp/><sp/>assert(node-&gt;used);</highlight></codeline>
<codeline lineno="632"><highlight class="comment"><sp/><sp/>if<sp/>(node-&gt;leaf)<sp/>return<sp/>node;</highlight></codeline>
<codeline lineno="633"><highlight class="comment"></highlight></codeline>
<codeline lineno="634"><highlight class="comment"><sp/><sp/>if<sp/>(strcmp(key,<sp/>node-&gt;keys[0])<sp/>&lt;<sp/>0)<sp/></highlight></codeline>
<codeline lineno="635"><highlight class="comment"><sp/><sp/><sp/><sp/>return<sp/>findLeafNode(node-&gt;head[0].bPtr,<sp/>key);</highlight></codeline>
<codeline lineno="636"><highlight class="comment"></highlight></codeline>
<codeline lineno="637"><highlight class="comment"><sp/><sp/>if<sp/>(strcmp(key,<sp/>node-&gt;keys[node-&gt;used-1])<sp/>&gt;=<sp/>0)<sp/></highlight></codeline>
<codeline lineno="638"><highlight class="comment"><sp/><sp/><sp/><sp/>return<sp/>findLeafNode(node-&gt;head[node-&gt;used].bPtr,<sp/>key);</highlight></codeline>
<codeline lineno="639"><highlight class="comment"><sp/><sp/></highlight></codeline>
<codeline lineno="640"><highlight class="comment"><sp/><sp/>for<sp/>(unsigned<sp/>int<sp/>i<sp/>=<sp/>1;<sp/>i<sp/>&lt;<sp/>node-&gt;used;<sp/>i++)<sp/>{</highlight></codeline>
<codeline lineno="641"><highlight class="comment"><sp/><sp/><sp/><sp/>if<sp/>(strcmp(key,<sp/>node-&gt;keys[i])<sp/>&lt;<sp/>0)<sp/></highlight></codeline>
<codeline lineno="642"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>return<sp/>findLeafNode(node-&gt;head[i].bPtr,<sp/>key);</highlight></codeline>
<codeline lineno="643"><highlight class="comment"><sp/><sp/>}<sp/>//<sp/>for<sp/>i</highlight></codeline>
<codeline lineno="644"><highlight class="comment"><sp/><sp/></highlight></codeline>
<codeline lineno="645"><highlight class="comment"><sp/><sp/>return<sp/>NULL;</highlight></codeline>
<codeline lineno="646"><highlight class="comment">}<sp/>//<sp/>bTree::findLeafNode</highlight></codeline>
<codeline lineno="647"><highlight class="comment"></highlight></codeline>
<codeline lineno="648"><highlight class="comment">void</highlight></codeline>
<codeline lineno="649"><highlight class="comment">bTree::saveNode(FILE<sp/>*<sp/>fd,<sp/>bNode<sp/>*<sp/>node,<sp/>void<sp/>*<sp/>tmpPtr)<sp/>{</highlight></codeline>
<codeline lineno="650"><highlight class="comment"><sp/></highlight></codeline>
<codeline lineno="651"><highlight class="comment"><sp/><sp/>bNode<sp/>*<sp/>ptr<sp/>=<sp/>(bNode<sp/>*)tmpPtr;</highlight></codeline>
<codeline lineno="652"><highlight class="comment"><sp/><sp/>assert(tmpPtr);</highlight></codeline>
<codeline lineno="653"><highlight class="comment"><sp/><sp/>assert(fd);</highlight></codeline>
<codeline lineno="654"><highlight class="comment"><sp/><sp/>assert(node);</highlight></codeline>
<codeline lineno="655"><highlight class="comment"><sp/><sp/>cout<sp/>&lt;&lt;<sp/>&quot;writing<sp/>tag:<sp/>&quot;<sp/>&lt;&lt;<sp/>node-&gt;tag<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="656"><highlight class="comment"></highlight></codeline>
<codeline lineno="657"><highlight class="comment"><sp/><sp/>memcpy(tmpPtr,<sp/>node,<sp/>sizeof(bNode));<sp/><sp/></highlight></codeline>
<codeline lineno="658"><highlight class="comment"></highlight></codeline>
<codeline lineno="659"><highlight class="comment"><sp/><sp/>if<sp/>(node-&gt;parent.bPtr<sp/>!=<sp/>NULL)</highlight></codeline>
<codeline lineno="660"><highlight class="comment"><sp/><sp/><sp/><sp/>ptr-&gt;parent.offset<sp/>=<sp/>node-&gt;parent.bPtr-&gt;tag<sp/>*<sp/>sizeof(bNode);</highlight></codeline>
<codeline lineno="661"><highlight class="comment"><sp/><sp/>else</highlight></codeline>
<codeline lineno="662"><highlight class="comment"><sp/><sp/><sp/><sp/>ptr-&gt;parent.offset<sp/>=<sp/>0;</highlight></codeline>
<codeline lineno="663"><highlight class="comment"></highlight></codeline>
<codeline lineno="664"><highlight class="comment"><sp/><sp/>for<sp/>(unsigned<sp/>int<sp/>i<sp/>=<sp/>0;<sp/>i<sp/>&lt;=<sp/>node-&gt;used;<sp/>i++)<sp/>{</highlight></codeline>
<codeline lineno="665"><highlight class="comment"><sp/><sp/><sp/><sp/>bNode<sp/>*<sp/>bPtr<sp/>=<sp/>node-&gt;head[i].bPtr;</highlight></codeline>
<codeline lineno="666"><highlight class="comment"></highlight></codeline>
<codeline lineno="667"><highlight class="comment"><sp/><sp/><sp/><sp/>if<sp/>(bPtr<sp/>!=<sp/>NULL)</highlight></codeline>
<codeline lineno="668"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>ptr-&gt;head[i].offset<sp/>=<sp/>bPtr-&gt;tag<sp/>*<sp/>sizeof(bNode);</highlight></codeline>
<codeline lineno="669"><highlight class="comment"><sp/><sp/><sp/><sp/>else</highlight></codeline>
<codeline lineno="670"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>ptr-&gt;head[i].offset<sp/>=<sp/>~0;</highlight></codeline>
<codeline lineno="671"><highlight class="comment"><sp/><sp/><sp/><sp/>ptr-&gt;present[i]<sp/>=<sp/>false;</highlight></codeline>
<codeline lineno="672"><highlight class="comment"><sp/><sp/>}<sp/>//<sp/>for<sp/>i</highlight></codeline>
<codeline lineno="673"><highlight class="comment"><sp/><sp/></highlight></codeline>
<codeline lineno="674"><highlight class="comment"><sp/><sp/>if<sp/>(node-&gt;leaf)<sp/>{</highlight></codeline>
<codeline lineno="675"><highlight class="comment"></highlight></codeline>
<codeline lineno="676"><highlight class="comment"><sp/><sp/><sp/><sp/>for<sp/>(unsigned<sp/>int<sp/>i<sp/>=<sp/>0;<sp/>i<sp/>&lt;=<sp/>node-&gt;used;<sp/>i++)<sp/>{</highlight></codeline>
<codeline lineno="677"><highlight class="comment"><sp/><sp/>//<sp/><sp/><sp/><sp/>ubixfsInode<sp/>*<sp/>inode<sp/>=<sp/>node-&gt;head[i].iPtr;</highlight></codeline>
<codeline lineno="678"><highlight class="comment"><sp/><sp/>//<sp/>mji<sp/><sp/><sp/><sp/>if<sp/>(inode<sp/>!=<sp/>NULL)<sp/>tmp-&gt;head[i]<sp/>=<sp/>inode-&gt;</highlight></codeline>
<codeline lineno="679"><highlight class="comment"><sp/><sp/><sp/><sp/>}<sp/>//<sp/>for<sp/>i</highlight></codeline>
<codeline lineno="680"><highlight class="comment"><sp/><sp/>}<sp/>else<sp/>{</highlight></codeline>
<codeline lineno="681"><highlight class="comment"></highlight></codeline>
<codeline lineno="682"><highlight class="comment"><sp/><sp/><sp/><sp/>for<sp/>(unsigned<sp/>int<sp/>i<sp/>=<sp/>0;<sp/>i<sp/>&lt;=<sp/>node-&gt;used;<sp/>i++)<sp/>{</highlight></codeline>
<codeline lineno="683"><highlight class="comment"></highlight></codeline>
<codeline lineno="684"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>if<sp/>(node-&gt;head[i].bPtr<sp/>!=<sp/>NULL)<sp/>saveNode(fd,<sp/>node-&gt;head[i].bPtr,<sp/>tmpPtr);</highlight></codeline>
<codeline lineno="685"><highlight class="comment"></highlight></codeline>
<codeline lineno="686"><highlight class="comment"><sp/><sp/><sp/><sp/>}<sp/>//<sp/>for<sp/>i</highlight></codeline>
<codeline lineno="687"><highlight class="comment"></highlight></codeline>
<codeline lineno="688"><highlight class="comment"><sp/><sp/>}<sp/>//<sp/>else</highlight></codeline>
<codeline lineno="689"><highlight class="comment"></highlight></codeline>
<codeline lineno="690"><highlight class="comment"><sp/><sp/>return;</highlight></codeline>
<codeline lineno="691"><highlight class="comment">}<sp/>//<sp/>bTree::saveNode<sp/></highlight></codeline>
<codeline lineno="692"><highlight class="comment"></highlight></codeline>
<codeline lineno="693"><highlight class="comment">bool<sp/></highlight></codeline>
<codeline lineno="694"><highlight class="comment">bTree::Save(const<sp/>char<sp/>*<sp/>filename)<sp/>{</highlight></codeline>
<codeline lineno="695"><highlight class="comment"><sp/><sp/>ubixfsInode<sp/>*<sp/>uPtr<sp/>=<sp/>NULL;</highlight></codeline>
<codeline lineno="696"><highlight class="comment"><sp/><sp/>if<sp/>(filename<sp/>==<sp/>NULL)<sp/>return<sp/>false;</highlight></codeline>
<codeline lineno="697"><highlight class="comment"><sp/><sp/>FILE<sp/>*<sp/>fd<sp/>=<sp/>NULL;</highlight></codeline>
<codeline lineno="698"><highlight class="comment"><sp/><sp/>if<sp/>((fd<sp/>=<sp/>fopen(filename,<sp/>&quot;wb+&quot;))<sp/>==<sp/>NULL)<sp/>return<sp/>false;</highlight></codeline>
<codeline lineno="699"><highlight class="comment"></highlight></codeline>
<codeline lineno="700"><highlight class="comment">cout<sp/>&lt;&lt;<sp/>&quot;tags:<sp/>&quot;<sp/>&lt;&lt;<sp/>tag<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="701"><highlight class="comment"><sp/><sp/>lseek(fileno(fd),<sp/>tag<sp/>*<sp/>sizeof(bNode),<sp/>SEEK_END);</highlight></codeline>
<codeline lineno="702"><highlight class="comment"></highlight></codeline>
<codeline lineno="703"><highlight class="comment"><sp/><sp/>header-&gt;firstNodeOffset<sp/>=<sp/>sizeof(bNode);</highlight></codeline>
<codeline lineno="704"><highlight class="comment"><sp/><sp/>header-&gt;firstDeleted<sp/>=<sp/>-1;</highlight></codeline>
<codeline lineno="705"><highlight class="comment"><sp/><sp/>void<sp/>*<sp/>tmpPtr<sp/>=<sp/>malloc(sizeof(bNode));</highlight></codeline>
<codeline lineno="706"><highlight class="comment"><sp/><sp/>assert(tmpPtr);</highlight></codeline>
<codeline lineno="707"><highlight class="comment"><sp/><sp/>uPtr<sp/>=<sp/>(ubixfsInode<sp/>*)tmpPtr;</highlight></codeline>
<codeline lineno="708"><highlight class="comment"><sp/><sp/>memset(tmpPtr,<sp/>0,<sp/>sizeof(bNode));</highlight></codeline>
<codeline lineno="709"><highlight class="comment"><sp/><sp/>fwrite(header,<sp/>sizeof(bTreeHeader),<sp/>1,<sp/>fd);<sp/></highlight></codeline>
<codeline lineno="710"><highlight class="comment"><sp/><sp/>saveNode(fd,<sp/>root,<sp/>tmpPtr);</highlight></codeline>
<codeline lineno="711"><highlight class="comment"><sp/><sp/></highlight></codeline>
<codeline lineno="712"><highlight class="comment"><sp/><sp/>fclose(fd);</highlight></codeline>
<codeline lineno="713"><highlight class="comment"><sp/><sp/>free(tmpPtr);</highlight></codeline>
<codeline lineno="714"><highlight class="comment"><sp/><sp/>return<sp/>true;</highlight></codeline>
<codeline lineno="715"><highlight class="comment">}<sp/>//<sp/>bTree::Save</highlight></codeline>
<codeline lineno="716"><highlight class="comment"></highlight></codeline>
<codeline lineno="717"><highlight class="comment">bool</highlight></codeline>
<codeline lineno="718"><highlight class="comment">bTree::Load(const<sp/>char<sp/>*<sp/>filename)<sp/>{</highlight></codeline>
<codeline lineno="719"><highlight class="comment"><sp/><sp/>if<sp/>(filename<sp/>==<sp/>NULL)<sp/>return<sp/>false;</highlight></codeline>
<codeline lineno="720"><highlight class="comment"><sp/><sp/>return<sp/>true;</highlight></codeline>
<codeline lineno="721"><highlight class="comment">}<sp/>//<sp/>bTree::Load</highlight></codeline>
<codeline lineno="722"><highlight class="comment"></highlight></codeline>
<codeline lineno="723"><highlight class="comment">bool</highlight></codeline>
<codeline lineno="724"><highlight class="comment">bTree::Delete(const<sp/>char<sp/>*<sp/>key)<sp/>{</highlight></codeline>
<codeline lineno="725"><highlight class="comment"></highlight></codeline>
<codeline lineno="726"><highlight class="comment"><sp/><sp/>if<sp/>(key<sp/>==<sp/>NULL)<sp/>return<sp/>false;</highlight></codeline>
<codeline lineno="727"><highlight class="comment"><sp/><sp/>return<sp/>true;</highlight></codeline>
<codeline lineno="728"><highlight class="comment">}<sp/>//<sp/>bTree::Delete</highlight></codeline>
<codeline lineno="729"><highlight class="comment"></highlight></codeline>
<codeline lineno="730"><highlight class="comment">bool</highlight></codeline>
<codeline lineno="731"><highlight class="comment">bTree::Verify(void)<sp/>{</highlight></codeline>
<codeline lineno="732"><highlight class="comment"><sp/><sp/>ubixfsInode<sp/>*<sp/>node<sp/>=<sp/>GetFirstNode();</highlight></codeline>
<codeline lineno="733"><highlight class="comment"><sp/><sp/>if<sp/>(node<sp/>==<sp/>NULL)<sp/>return<sp/>true;</highlight></codeline>
<codeline lineno="734"><highlight class="comment"><sp/></highlight></codeline>
<codeline lineno="735"><highlight class="comment"><sp/><sp/>while<sp/>(node<sp/>!=<sp/>NULL)<sp/>{</highlight></codeline>
<codeline lineno="736"><highlight class="comment"><sp/><sp/><sp/><sp/>ubixfsInode<sp/>*<sp/>next<sp/>=<sp/>node-&gt;next.iPtr;</highlight></codeline>
<codeline lineno="737"><highlight class="comment"><sp/><sp/><sp/><sp/>if<sp/>(next<sp/>!=<sp/>NULL)<sp/>{</highlight></codeline>
<codeline lineno="738"><highlight class="comment"><sp/><sp/>//<sp/><sp/>cout<sp/>&lt;&lt;<sp/>node-&gt;name<sp/>&lt;&lt;<sp/>&quot;::&quot;<sp/>&lt;&lt;<sp/>node-&gt;next-&gt;name<sp/>&lt;&lt;<sp/>&quot;:::&quot;<sp/>&lt;&lt;<sp/>strcmp(node-&gt;name,<sp/>node-&gt;next-&gt;name)<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="739"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>if<sp/>(strcmp(node-&gt;name,<sp/>next-&gt;name)<sp/>&gt;<sp/>0)<sp/>return<sp/>false;</highlight></codeline>
<codeline lineno="740"><highlight class="comment"><sp/><sp/><sp/><sp/>}</highlight></codeline>
<codeline lineno="741"><highlight class="comment"><sp/><sp/><sp/><sp/>node<sp/>=<sp/>next;</highlight></codeline>
<codeline lineno="742"><highlight class="comment"><sp/><sp/>}<sp/>//<sp/>while</highlight></codeline>
<codeline lineno="743"><highlight class="comment"><sp/><sp/>return<sp/>true;</highlight></codeline>
<codeline lineno="744"><highlight class="comment">}<sp/>//<sp/>bTree::Verify</highlight></codeline>
<codeline lineno="745"><highlight class="comment"></highlight></codeline>
<codeline lineno="746"><highlight class="comment">void<sp/></highlight></codeline>
<codeline lineno="747"><highlight class="comment">bTree::Print(bNode<sp/>*<sp/>node)<sp/>{</highlight></codeline>
<codeline lineno="748"><highlight class="comment"><sp/><sp/>if<sp/>(node<sp/>==<sp/>NULL)<sp/>return;</highlight></codeline>
<codeline lineno="749"><highlight class="comment"><sp/><sp/>Info(node);</highlight></codeline>
<codeline lineno="750"><highlight class="comment"><sp/><sp/>if<sp/>(!node-&gt;leaf)</highlight></codeline>
<codeline lineno="751"><highlight class="comment"><sp/><sp/><sp/><sp/>for<sp/>(unsigned<sp/>int<sp/>i<sp/>=<sp/>0;<sp/>i<sp/>&lt;=<sp/>node-&gt;used;<sp/>i++)<sp/>{</highlight></codeline>
<codeline lineno="752"><highlight class="comment"><sp/><sp/><sp/><sp/><sp/><sp/>Print(node-&gt;head[i].bPtr);</highlight></codeline>
<codeline lineno="753"><highlight class="comment"><sp/><sp/><sp/><sp/>}<sp/>//<sp/>for<sp/>i</highlight></codeline>
<codeline lineno="754"><highlight class="comment">}<sp/>//<sp/>bTree::Print</highlight></codeline>
<codeline lineno="755"><highlight class="comment"></highlight></codeline>
<codeline lineno="756"><highlight class="comment">void</highlight></codeline>
<codeline lineno="757"><highlight class="comment">bTree::PrintWholeTree(void)<sp/>{</highlight></codeline>
<codeline lineno="758"><highlight class="comment"><sp/><sp/>Print(root);</highlight></codeline>
<codeline lineno="759"><highlight class="comment">}<sp/>//<sp/>bTree::PrintWholeTree;</highlight></codeline>
<codeline lineno="760"><highlight class="comment"></highlight></codeline>
<codeline lineno="761"><highlight class="comment">bTree::~bTree(void)<sp/>{</highlight></codeline>
<codeline lineno="762"><highlight class="comment"><sp/><sp/>cout<sp/>&lt;&lt;<sp/>&quot;tree<sp/>depth:<sp/>&quot;<sp/>&lt;&lt;<sp/>header-&gt;treeDepth<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="763"><highlight class="comment"><sp/><sp/>cout<sp/>&lt;&lt;<sp/>&quot;tree<sp/>width:<sp/>&quot;<sp/>&lt;&lt;<sp/>header-&gt;treeWidth<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="764"><highlight class="comment"><sp/><sp/>cout<sp/>&lt;&lt;<sp/>&quot;tree<sp/>leaf<sp/>count:<sp/>&quot;<sp/>&lt;&lt;<sp/>header-&gt;treeLeafCount<sp/>&lt;&lt;<sp/>endl;</highlight></codeline>
<codeline lineno="765"><highlight class="comment">}<sp/>//<sp/>bTree::~bTree</highlight></codeline>
<codeline lineno="766"><highlight class="comment"></highlight></codeline>
<codeline lineno="767"><highlight class="comment">*/</highlight><highlight class="normal"></highlight></codeline>
    </programlisting>
    <location file="C:/Dev/git/UbixOS/sys/fs/ubixfsv2/btree.cpp"/>
  </compounddef>
</doxygen>
