Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ada 2.51 KB | None | 0 0
  1. --
  2. --  Copyright (c) 2010, Edward O'Callaghan
  3. --
  4. --  Permission to use, copy, modify, and/or distribute this software for any
  5. --  purpose with or without fee is hereby granted, provided that the above
  6. --  copyright notice and this permission notice appear in all copies.
  7. --
  8. --  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. --  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. --  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. --  ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. --  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. --  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. --  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. --
  16.  
  17. --
  18. --  SPARK Verified Ada2005 Red-Back Tree in-memory implementation.
  19.  
  20. generic
  21.    type Element_Type is private;
  22.  
  23. package RB_Tree is
  24.    type Node_Type is tagged limited private;
  25.  
  26.    type disk_Node_Type   is new Node_Type with private;
  27.    type memory_Node_Type is new Node_Type with private;
  28.  
  29.    --
  30.    --  Red-Black Tree Insertion
  31.    -- Time Complexity:
  32.    -- Average Case: O( Log[N] )
  33.    -- Worst Case: O( Log[N] )
  34.    procedure Insert (Tree : in out Node_Type; Element : in Element_Type);
  35.    --# derives Tree from *, Element;
  36.  
  37.    --
  38.    --  Red-Black Tree Deletion
  39.    -- Time Complexity:
  40.    -- Average Case: O( Log[N] )
  41.    -- Worst Case: O( Log[N] )
  42.    procedure Delete (Tree : in out Node_Type; Node : in Node_Type);
  43.    --# derives Tree from *, Node;
  44.  
  45.    --
  46.    --  Red-Black Tree Search
  47.    -- Time Complexity:
  48.    -- Average Case: O( Log[N] )
  49.    -- Worst Case: O( Log[N] )
  50.    procedure Search
  51.      (Tree    : in Node_Type;
  52.       Element : in Element_Type;
  53.       Found   : out Boolean;
  54.       Node    : out Node_Type);
  55.    --# derives Found, Node from
  56.    --#  Tree, Element;
  57.    --# post Found -> Tree (Node) = Element;
  58.    --  If Found is False then Node is undefined.
  59.  
  60. private
  61.    type Node_Colour is (Red, Black);
  62.  
  63.    type Node_Type is record
  64.       Colour : Node_Colour := Black;
  65.    end record;
  66.  
  67.  
  68.    type disk_Node_Type   is new Node_Type with
  69.       record
  70.          Parent      : access disk_Node_Type := null;
  71.          Right, Left : access disk_Node_Type := null;
  72.       end record;        
  73.  
  74.    type memory_Node_Type   is new Node_Type with
  75.       record
  76.          Parent      : access memory_Node_Type := null;
  77.          Right, Left : access memory_Node_Type := null;
  78.       end record;        
  79.  
  80. end RB_Tree;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement