Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ada 1.83 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.    procedure Insert (Tree : in out Node_Type;
  27.                      Element : in Element_Type);
  28.    --# derives Tree from *, Element;
  29.    
  30.    procedure Delete (Tree : in out Node_Type;
  31.                      Node : in Node_Type);
  32.    --# derives Tree from *, Node;
  33.  
  34.    procedure Search (Tree : in Node_Type;
  35.                      Element : in Element_Type;
  36.                      Found    :     out Boolean;
  37.                      Node : out Node_Type);
  38.    --# derives Found,
  39.    --#          Node from
  40.    --#                  Tree,
  41.    --#                  Element;
  42.    --# post Found -> Tree (Node) = Element;
  43.    --  If Found is False then Position is undefined.
  44.  
  45. private
  46.    type Node_Colour is (Red, Black);
  47.  
  48.    type Node_Type is
  49.       record
  50.          Colour : Node_Colour;
  51.          Parent : access Node_Type;
  52.          Right, Left : access Node_Type;
  53.       end record;
  54. end RB_Tree;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement