After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 589801 - Adding Pair, Tripple and some implementations
Adding Pair, Tripple and some implementations
Status: RESOLVED DUPLICATE of bug 531918
Product: libgee
Classification: Platform
Component: general
git master
Other All
: Normal enhancement
: 0.5
Assigned To: libgee-maint
libgee-maint
Depends on: 554781 591718
Blocks:
 
 
Reported: 2009-07-26 20:57 UTC by Maciej (Matthew) Piechotka
Modified: 2010-07-14 09:37 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
0001-Added-basic-Map.Entry.patch (17.75 KB, patch)
2009-08-13 17:28 UTC, Maciej (Matthew) Piechotka
none Details | Review
0001-Added-Map.Entry.patch (43.87 KB, patch)
2009-08-13 18:24 UTC, Maciej (Matthew) Piechotka
none Details | Review

Description Maciej (Matthew) Piechotka 2009-07-26 20:57:21 UTC
Adding pair to libgee would have following advantages:

- It would make Gee.Map iterable in full sense (both values and keys at the same time). On top of such iteration key and set iterations can be easily abstracted. it would also allowed to have mutating interfaces for Gee.Map as in bug 589800
- It would allow to base Gee.Map on Gee.Set i.e. having underlying Gee.Set<Gee.Pair<K,V>> shortening the code
Comment 1 Didier "Ptitjes" 2009-07-30 09:27:18 UTC
I would prefer to have a specific Map.Entry interface for the entries of maps. This Entry interface would have key and value properties.

In constrast to that, it is still interesting for some people to have a Pair class. Here are some things Pair could provide (comments by Michael Lauer copy/pasted from Vala's ML):

- Equality tests (pairs and tuples),
- Swapping elements (pairs),
- Adding from/to other (pairs, tuples),
- Slicing into other,
- Converting to/from string.
Comment 2 Maciej (Matthew) Piechotka 2009-07-30 11:31:14 UTC
(In reply to comment #1)
> I would prefer to have a specific Map.Entry interface for the entries of maps.
> This Entry interface would have key and value properties.
> 

I'll try to experiment with it.
Comment 3 Maciej (Matthew) Piechotka 2009-08-13 09:49:28 UTC
I add dependency to bug 557719. I considered several scenarios:
Adding Map.Entry as an interface:
- Cannot be simply used to modifing underlying map
- Rather slow (most current Map.Entries are based on compact classes)
Adding Map.Entry as an class:
- Needs to be virtual/GObject anyway to not break ReadOnlyMap readonlyness.
Adding Map.MutableEntry as subclass of Map.Entry:
- Needs split between map and mutable map
Comment 4 Maciej (Matthew) Piechotka 2009-08-13 17:28:03 UTC
Created attachment 140682 [details] [review]
0001-Added-basic-Map.Entry.patch

Share of work. Patch *not* finished. Depends on bug 591718 (for contains).
Comment 5 Maciej (Matthew) Piechotka 2009-08-13 18:24:22 UTC
Created attachment 140686 [details] [review]
0001-Added-Map.Entry.patch

A nearly working patch. The only remaining problems:
- How to map equalities and hashes
- How to prevent modification
Comment 6 Maciej (Matthew) Piechotka 2009-08-25 08:33:05 UTC
Personally from the current point I see two ways:
- Full closures support within vala without additional parameter (unlikely but I know too little about vala  and gcc C extention to state this for sure).
- Other implementation of closures (possibly using llvm). Cons: lots of code having nothing to do with collections
- Change API to handle equality etc. on values. Cons: Breaks API. Very unhandy
- Implementing Set based on Map rather then other way round (Set<T> as Map<T,void>). Cons: vala don't have void. Also it takes more space (additional pointer)
- Resign. Cons: Lots of duplicate code betwean Map and Set.
Comment 7 Maciej (Matthew) Piechotka 2009-08-25 08:37:51 UTC
PS. I'm personally for full closures support or implementing set based on map.
Comment 8 Maciej (Matthew) Piechotka 2009-08-25 08:41:03 UTC
Ups.
- Change API to handle additional parameter in which user data is passed. Cons: breaks API
Comment 9 Didier "Ptitjes" 2009-09-26 15:51:44 UTC
commit 93ab6ba6e32056ef9f15ff8ce844143c207c99b6
Author: Didier 'Ptitjes <ptitjes@free.fr>
Date:   Sun Sep 20 16:25:17 2009 +0200

    Introduce the Map.Entry<K,V> class and the Map.entries property
    
    We also use Map.entries to optimize the implementations of
    set_all, has_all and HashMultiMap by avoiding the common pattern:
    iterate on keys and for each key get the associated value.

This fixes part of this bug, so let me change the summary of this ticket.
Comment 10 Maciej (Matthew) Piechotka 2010-07-14 09:37:16 UTC

*** This bug has been marked as a duplicate of bug 531918 ***