-- File: DBIndexOp.mesa
-- Contents: General operations on pages of B-trees.
-- Derived from: DBIndexLeaf created November 26, 1980
-- Last edited by:
--   Cattell:  July 19, 1983 3:34 pm

DIRECTORY
    DBStorageInternal USING[TID],
    DBIndex USING [Page, IndexKey, State];

DBIndexOp: DEFINITIONS = { 

  Page: TYPE = DBIndex.Page;
  State: TYPE = DBIndex.State;
  IndexKey: TYPE = DBIndex.IndexKey;

  OverFlow: PROC [p: Page, key: IndexKey] RETURNS [BOOLEAN];

  EntrySize: PROC [p: Page, i: CARDINAL] RETURNS [CARDINAL];
    -- Returns the size of the entry: key plus value

  SplitPage:  PROC [p: Page, loc: CARDINAL, insertSize: INTEGER]
    RETURNS [splitLoc: CARDINAL, splitKey: IndexKey, overflow: Page];

  SplitLeaf: PROC [p: Page, key: IndexKey, value: LONG CARDINAL]
    RETURNS [Page, IndexKey];
    -- The page overflows if we insert <key, value> pair.  We allocate 
    --a page to the right of p and moves contents, and insert 
    --<key, value> at the same time.

  SplitInternal: PROC [p: Page, insertLoc: CARDINAL, key: IndexKey, value: LONG CARDINAL]
    RETURNS [Page, IndexKey];

  InsertInInternalPage: PROC [
    p: Page, i: CARDINAL, newPage: LONG CARDINAL, newKey: IndexKey]
    RETURNS [State, Page, IndexKey];
  
  DeleteFromLeafPage: PROC [p: Page, key: IndexKey, tid: DBStorageInternal.TID]
    RETURNS [State, Page, IndexKey];

  MergeInLeafPage: PROC [p: Page, son: Page, index: CARDINAL]
    RETURNS [State, Page, IndexKey];

  ChangeKey: PROC[p: Page, newKey: IndexKey, index: CARDINAL]
    RETURNS[state: State, overflow: Page, key: IndexKey];
    -- Sets indexed key in leaf page p to be newKey.
  
  MoveScanIndexLeft: PUBLIC PROC [from, to: Page, nentries: CARDINAL];
    -- "from" is to the right of "to"
    -- moves the first "nentries" in "from" to "to"
  
  MoveScanIndexRight: PUBLIC PROC [from, to: Page, after: CARDINAL];
    -- moves the scan index on "from" to "to", if the index
    --is greater than "after"
    -- "to" is empty
  
  DecrementScanIndex: PROC [page: Page, atOrAfter: CARDINAL];
    -- Decrements any effected scan indices by one, if they are on "page" with index 
    -- greater or equal to "atOrAfter"
  
  IncrementScanIndex: PUBLIC PROC [
    page: Page, atOrAfter: CARDINAL, howMuch: CARDINAL← 1];
    -- Increments any effected scan indices by howMuch, if they are on "page" with index 
    -- greater or equal to "atOrAfter"
            
}.

Change log since Sept 82:

By Cattell September 22, 1982 9:20 am: Re-organized DBIndex interfaces for isolating page writes.  Moved some procs from here to DBIndexMod.