| Anonymous | Login | Signup for a new account | 2013-05-19 04:30 CEST | ![]() |
| Main | My View | View Issues | Change Log | Roadmap |
| View Issue Details [ Jump to Notes ] | [ Issue History ] [ Print ] | ||||||||||
| ID | Project | Category | View Status | Date Submitted | Last Update | ||||||
| 0005220 | OCaml | OCaml general | public | 2011-02-04 11:45 | 2011-05-17 16:17 | ||||||
| Reporter | Christoph Bauer | ||||||||||
| Assigned To | |||||||||||
| Priority | normal | Severity | feature | Reproducibility | have not tried | ||||||
| Status | acknowledged | Resolution | open | ||||||||
| Platform | OS | OS Version | |||||||||
| Product Version | 3.11.2 | ||||||||||
| Target Version | Fixed in Version | ||||||||||
| Summary | 0005220: Feature request: Hashtbl.adjust | ||||||||||
| Description | If you have a Hashtable of counters and you want to increment one, you have to do it that way: Hashtbl.replace t key (1+Hashtbl.find t key) There could be a more efficient way to do this with a helper function Hashtbl.adjust t key f with the type Hashtbl.adjust : ('a, 'b) Hashtbl.t -> 'a -> ('b -> 'b) Hashtbl.adjust looks up the key in t and replaces it associated value b with (f b). It might raise Not_found. I guess it's not possible to implement this function in BatHashtbl. | ||||||||||
| Tags | No tags attached. | ||||||||||
| Attached Files | |||||||||||
Notes |
|
|
(0005794) Christoph Bauer (reporter) 2011-02-04 11:56 |
The type is Hashtbl.adjust : ('a, 'b) Hashtbl.t -> 'a -> ('b -> 'b) -> unit |
|
(0005795) Christoph Bauer (reporter) 2011-02-04 11:57 |
Here an implementation: let adjust h key f = let rec replace_bucket = function Empty -> raise Not_found | Cons(k, i, next) -> if compare k key = 0 then Cons(k, f i, next) else Cons(k, i, replace_bucket next) in let i = (hash key) mod (Array.length h.data) in let l = h.data.(i) in h.data.(i) <- replace_bucket l |
Issue History |
|||
| Date Modified | Username | Field | Change |
| 2011-02-04 11:45 | Christoph Bauer | New Issue | |
| 2011-02-04 11:56 | Christoph Bauer | Note Added: 0005794 | |
| 2011-02-04 11:57 | Christoph Bauer | Note Added: 0005795 | |
| 2011-05-17 16:17 | doligez | Status | new => acknowledged |
| Copyright © 2000 - 2011 MantisBT Group |