-- File DBStorageTID.mesa
-- Last edited by
  -- MBrown on  1-Mar-81 11:21:34
  -- Cattell on January 14, 1983 2:09 pm


DIRECTORY
  DBCommon,
  DBEnvironment USING[InternalError],
  Inline;


DBStorageTID: DEFINITIONS
  IMPORTS DBEnvironment, Inline = BEGIN
  -- This interface contains definitions that relate to tuple IDs (TIDs).


  TID: TYPE = LONG CARDINAL;
    -- "Pointer" to a tuple in the database.  Structure is given by the procedures
    --below:

  DecomposeTID: PROCEDURE[tid: TID]
   RETURNS[--p-- DBCommon.DBPage, --slotIndex-- CARDINAL] = INLINE BEGIN
    -- Breaks a TID into the DBPage where the tuple's slot is, and the number of
    --the slot on that page.
    slotIndex: CARDINAL ←
       Inline.BITAND[LOOPHOLE[tid, num   Inline.LongNumber].lowbits, TIDSlotMask];
    LOOPHOLE[tid, num   Inline.LongNumber].lowbits ←
       Inline.BITAND[LOOPHOLE[tid, num   Inline.LongNumber].lowbits, TIDLowPageMask];
    RETURN[tid, slotIndex];
  END;--DecomposeTID

  ConsTID: PROCEDURE[p: DBCommon.DBPage, slotIndex: CARDINAL]
   RETURNS[--tid-- TID] = INLINE BEGIN
    -- Makes a TID from the DBPage where the tuple's slot is, and the number of
    --the slot on that page.
    IF slotIndex > TIDSlotMask THEN ERROR DBEnvironment.InternalError; -- BadSlotIndex
    RETURN[p + slotIndex];
  END;--ConsTID

  NullTID: TID = 0;

  -- Masks that define the maximum number of slots allowed per page.
  --Must agree with DBSegmentPrivate.BitsUnused.

  DBPageIncrement: CARDINAL = 100B;
  TIDSlotMask:    CARDINAL = DBPageIncrement - 1; --000077B
  TIDLowPageMask: CARDINAL = LAST[CARDINAL] - TIDSlotMask; --177700B


END.--DBStorageTID


--  Module History

Created by MBrown on June 10, 1980  3:56 PM
-- Moved TID-related stuff here from DBStoragePrivateA.

Changed by MBrown on September 26, 1980  11:13 AM
-- Defined error code BadSlotIndex.

Changed by MBrown on December 8, 1980  1:48 PM
-- Defined DBPageIncrement, for use in Segment block allocator.

Changed by MBrown on  1-Mar-81 11:22:17
-- InlineDefs -> Inline.