Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ada 2.09 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 limited private;
  25.  
  26.    --
  27.    --  Red-Black Tree Insertion
  28.    -- Time Complexity:
  29.    -- Average Case: O( Log[N] )
  30.    -- Worst Case: O( Log[N] )
  31.    procedure Insert (Tree : in out Node_Type; Element : in Element_Type);
  32.    --# derives Tree from *, Element;
  33.  
  34.    --
  35.    --  Red-Black Tree Deletion
  36.    -- Time Complexity:
  37.    -- Average Case: O( Log[N] )
  38.    -- Worst Case: O( Log[N] )
  39.    procedure Delete (Tree : in out Node_Type; Node : in Node_Type);
  40.    --# derives Tree from *, Node;
  41.  
  42.    --
  43.    --  Red-Black Tree Search
  44.    -- Time Complexity:
  45.    -- Average Case: O( Log[N] )
  46.    -- Worst Case: O( Log[N] )
  47.    procedure Search
  48.      (Tree    : in Node_Type;
  49.       Element : in Element_Type;
  50.       Found   : out Boolean;
  51.       Node    : out Node_Type);
  52.    --# derives Found, Node from
  53.    --#  Tree, Element;
  54.    --# post Found -> Tree (Node) = Element;
  55.    --  If Found is False then Node is undefined.
  56.  
  57. private
  58.    type Node_Colour is (Red, Black);
  59.  
  60.    type Node_Type is record
  61.       Colour      : Node_Colour      := Black;
  62.       Parent      : access Node_Type := null;
  63.       Right, Left : access Node_Type := null;
  64.    end record;
  65. end RB_Tree;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement