Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0000576OCamlOCaml standard librarypublic2001-10-13 10:172016-12-08 11:57
Reporteradministrator 
Assigned Tofrisch 
PrioritynormalSeverityfeatureReproducibilityalways
StatusresolvedResolutionsuspended 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0000576: Suggestion: add_new to map
Descriptionsame definition as Map.add, except that it will throw an exception if the
key already exists. (I think that this should have been the default
behaviour of add, and the current add should have been called replace)

    let rec add x data = function
        Empty ->
          Node(Empty, x, data, Empty, 1)
      | Node(l, v, d, r, h) as t ->
          let c = Ord.compare x v in
          if c = 0 then
            raise XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
          else if c < 0 then
            bal (add x data l) v d r
          else
            bal l v d (add x data r)

/mattias

Tagsjunior_job, patch
Attached Filespatch file icon Map.add_new.2.patch [^] (3,189 bytes) 2014-06-19 21:40 [Show Content]

- Relationships
related to 0000340closedfrisch Implementer dans Map les memes operations que dans Set 

-  Notes
(0000116)
administrator (administrator)
2002-11-13 16:20

Reasonable suggestion. Find good name?
(0011761)
thizanne (reporter)
2014-06-19 21:40

Please ignore Map.add_new.patch (no test). Map.add_new.2.patch solves this (and there is a test).
(0016850)
frisch (developer)
2016-12-08 11:57

I agree this would be a reasonable addition. Since we are moving away from using exception, the function should return an option (None if the map already contained the element). A similar function should also be added to Set (and to Labeled versions). Marking as suspended, but a PR is welcome.

- Issue History
Date Modified Username Field Change
2005-11-18 10:13 administrator New Issue
2008-02-19 15:01 doligez Relationship added related to 0000340
2013-08-30 22:02 doligez Tag Attached: junior_job
2013-08-30 22:02 doligez Tag Attached: patch
2014-06-19 20:32 thizanne File Added: Map.add_new.patch
2014-06-19 21:40 thizanne Note Added: 0011761
2014-06-19 21:40 thizanne File Added: Map.add_new.2.patch
2014-06-19 23:52 gasche File Deleted: Map.add_new.patch
2016-12-07 14:11 shinwell Category OCaml general => OCaml standard library
2016-12-07 14:11 shinwell Description Updated View Revisions
2016-12-08 11:57 frisch Note Added: 0016850
2016-12-08 11:57 frisch Status acknowledged => resolved
2016-12-08 11:57 frisch Resolution open => suspended
2016-12-08 11:57 frisch Assigned To => frisch


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker