src/Pure/General/linear_set.ML
changeset 44483 383a5b9efbd0
parent 44479 9a04e7502e22
child 47403 296b478df14e
equal deleted inserted replaced
44482:c7225307acf2 44483:383a5b9efbd0
    14   val empty: 'a T
    14   val empty: 'a T
    15   val is_empty: 'a T -> bool
    15   val is_empty: 'a T -> bool
    16   val defined: 'a T -> key -> bool
    16   val defined: 'a T -> key -> bool
    17   val lookup: 'a T -> key -> ('a * key option) option
    17   val lookup: 'a T -> key -> ('a * key option) option
    18   val update: key * 'a -> 'a T -> 'a T
    18   val update: key * 'a -> 'a T -> 'a T
    19   val fold: key option ->
    19   val iterate: key option ->
    20     ((key option * key) * 'a -> 'b -> 'b option) -> 'a T -> 'b -> 'b
    20     ((key option * key) * 'a -> 'b -> 'b option) -> 'a T -> 'b -> 'b
    21   val get_first: key option ->
       
    22     ((key option * key) * 'a -> bool) -> 'a T -> ((key option * key) * 'a) option
       
    23   val get_after: 'a T -> key option -> key option
    21   val get_after: 'a T -> key option -> key option
    24   val insert_after: key option -> key * 'a -> 'a T -> 'a T
    22   val insert_after: key option -> key * 'a -> 'a T -> 'a T
    25   val delete_after: key option -> 'a T -> 'a T
    23   val delete_after: key option -> 'a T -> 'a T
    26 end;
    24 end;
    27 
    25 
    79 (* iterate entries *)
    77 (* iterate entries *)
    80 
    78 
    81 fun optional_start set NONE = start_of set
    79 fun optional_start set NONE = start_of set
    82   | optional_start _ some = some;
    80   | optional_start _ some = some;
    83 
    81 
    84 fun fold opt_start f set =
    82 fun iterate opt_start f set =
    85   let
    83   let
    86     val entries = entries_of set;
    84     val entries = entries_of set;
    87     fun apply _ NONE y = y
    85     fun apply _ NONE y = y
    88       | apply prev (SOME key) y =
    86       | apply prev (SOME key) y =
    89           let
    87           let
    93             (case f item y of
    91             (case f item y of
    94               NONE => y
    92               NONE => y
    95             | SOME y' => apply (SOME key) next y')
    93             | SOME y' => apply (SOME key) next y')
    96           end;
    94           end;
    97   in apply NONE (optional_start set opt_start) end;
    95   in apply NONE (optional_start set opt_start) end;
    98 
       
    99 fun get_first opt_start P set =
       
   100   let
       
   101     val entries = entries_of set;
       
   102     fun first _ NONE = NONE
       
   103       | first prev (SOME key) =
       
   104           let
       
   105             val (x, next) = the_entry entries key;
       
   106             val item = ((prev, key), x);
       
   107           in if P item then SOME item else first (SOME key) next end;
       
   108   in first NONE (optional_start set opt_start) end;
       
   109 
    96 
   110 
    97 
   111 (* relative addressing *)
    98 (* relative addressing *)
   112 
    99 
   113 fun get_after set hook =
   100 fun get_after set hook =