Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ada 2.93 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 generic implementation,
  19. --  provides both  in-memory and on-disk facilities.
  20.  
  21. --
  22. --  Red-Black Tree Properties:
  23. --
  24. --  1.) A node is either Red or Black, Root node is always Black.
  25. --  2.) All leave nodes are Black.
  26. --  3.) Both children of every Red node are black.
  27. --  4.) Every simple* path from a given node to any of its descendant
  28. --       leaves contains the same number of Black nodes.
  29. --  *A path with no repeated vertices is called a simple path.
  30.  
  31. generic
  32.    type Element_Type is private;
  33.  
  34. package ADT.RB_Tree is
  35.  
  36.    type Node_Type is abstract tagged limited private;
  37.  
  38.    --
  39.    --  Red-Black Tree Constructor
  40.    function Initialize_Memory_Tree return  Node_Type'Class;
  41.    function Initialize_On_Disk_Tree return  Node_Type'Class;
  42.  
  43.    --
  44.    --  Red-Black Tree Destructor
  45.    procedure Finalize (Tree : in out Node_Type) is abstract;
  46.    --# derives Tree from *;
  47.  
  48.    --
  49.    --  Red-Black Tree Insertion
  50.    --  Time Complexity:
  51.    --  Average Case: O( Log[N] )
  52.    --  Worst Case: O( Log[N] )
  53.    procedure Insert
  54.      (Tree    : access Node_Type;
  55.       Element : in Element_Type)
  56. is abstract;
  57.    --# derives Tree from *, Element;
  58.  
  59.    --
  60.    --  Red-Black Tree Deletion
  61.    --  Time Complexity:
  62.    --  Average Case: O( Log[N] )
  63.    --  Worst Case: O( Log[N] )
  64.    procedure Delete
  65.      (Tree : in out Node_Type;
  66.       Node : in Node_Type)
  67. is abstract;
  68.    --# derives Tree from *, Node;
  69.  
  70.    --
  71.    --  Red-Black Tree Search
  72.    --  Time Complexity:
  73.    --  Average Case: O( Log[N] )
  74.    --  Worst Case: O( Log[N] )
  75.    procedure Search
  76.      (Tree    : in Node_Type;
  77.       Element : in Element_Type;
  78.       Found   : out Boolean;
  79.       Node    : out Node_Type)
  80. is abstract;
  81.    --# derives Found, Node from Tree, Element;
  82.    --# post Found -> Tree (Node) = Element;
  83.    --  If Found is False then Node is undefined.
  84.  
  85. private
  86.    type Node_Colour is (Red, Black);
  87.  
  88.    type Node_Type is abstract tagged limited record
  89.       Colour : Node_Colour := Black;
  90.       --  Parent      : access Node_Type := null;
  91.       --  Right, Left : access Node_Type := null;
  92.    end record;
  93.  
  94. end ADT.RB_Tree;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement