Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » creating a registry for objects with certain identifying features
creating a registry for objects with certain identifying features [message #895823] Mon, 16 July 2012 08:24 Go to next message
Joel Greenyer is currently offline Joel GreenyerFriend
Messages: 170
Registered: July 2009
Senior Member
Hi,
in our application, we want to prevent creating many "structurally equal" objects.
Let's say we have a class X with features a:A, b:B, c:C (A,B,C being classes or data types), then we don't want to have two X objects with the same values for a, b, and c. The reason here is to save memory and allow for a fast comparison of objects, using "==" instead of having to iterate over all the feature values.

How do we do that?
Our idea is to build a registry that basically consists of a (hash) map that maps lists of the identifying attributes to these objects, e.g. (A,B,C)->X.
The lists are basically a way to create a unique key.
Then, before creating a new X object, with a=a1, b=b1, c=c1 we would create a new list (a1, b1, c1) and see if an object of X with an equal list as key is already contained in the map.


Do you think that this is a good idea? Any other suggestions?
Does it make sense to use BasicEList.FastCompare lists for this purpose?

Thanks for your input

Joel
Re: creating a registry for objects with certain identifying features [message #895914 is a reply to message #895823] Mon, 16 July 2012 13:38 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Joel,

Comments below.

On 16/07/2012 10:24 AM, Joel Greenyer wrote:
> Hi,
> in our application, we want to prevent creating many "structurally
> equal" objects.
> Let's say we have a class X with features a:A, b:B, c:C (A,B,C being
> classes or data types), then we don't want to have two X objects with
> the same values for a, b, and c. The reason here is to save memory and
> allow for a fast comparison of objects, using "==" instead of having
> to iterate over all the feature values.
I think it makes sense for data types that are immutable, but not so
much for classes.
>
> How do we do that?
> Our idea is to build a registry that basically consists of a (hash)
> map that maps lists of the identifying attributes to these objects,
> e.g. (A,B,C)->X.
> The lists are basically a way to create a unique key.
If you do this for a data type, you can ensure that there is a static
utility method for creating instances and it can hide all this under the
covers.
> Then, before creating a new X object, with a=a1, b=b1, c=c1 we would
> create a new list (a1, b1, c1) and see if an object of X with an equal
> list as key is already contained in the map.
For a class, the values can always be changed, and when deserializing,
the object is created first, and then the features are populated, so I
don't see how this approach can work for that.
>
>
> Do you think that this is a good idea? Any other suggestions?
> Does it make sense to use BasicEList.FastCompare lists for this purpose?
Certainly for a data type if you can ensure that there is at most one
instance for any combination of values, you can rely on == instead of
equals.
>
> Thanks for your input
>
> Joel


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: creating a registry for objects with certain identifying features [message #895979 is a reply to message #895914] Mon, 16 July 2012 17:59 Go to previous messageGo to next message
Joel Greenyer is currently offline Joel GreenyerFriend
Messages: 170
Registered: July 2009
Senior Member
Hi Ed,
thanks for your comments.
Yes, of course it only makes sense if what you are registering is not meant to be changed. Within our application we would ensure that.
Also, we would serialize and deserialize the objects in a plain list and after the deserialization we would re-initialize this registry map.
But would youhave any other suggestion than this key-list idea?
What we would really need is only a convenient way to calculate some unique hash-value for the registered objects.

Thanks

Joel


On 16.07.2012 15:38, Ed Merks wrote:
> Joel,
>
> Comments below.
>
> On 16/07/2012 10:24 AM, Joel Greenyer wrote:
>> Hi,
>> in our application, we want to prevent creating many "structurally equal" objects.
>> Let's say we have a class X with features a:A, b:B, c:C (A,B,C being classes or data types), then we don't want to have two X objects with the same values for a, b, and c. The reason here is to save memory and allow for a fast comparison of objects, using "==" instead of having to iterate over all the feature values.
> I think it makes sense for data types that are immutable, but not so much for classes.
>>
>> How do we do that?
>> Our idea is to build a registry that basically consists of a (hash) map that maps lists of the identifying attributes to these objects, e.g. (A,B,C)->X.
>> The lists are basically a way to create a unique key.
> If you do this for a data type, you can ensure that there is a static utility method for creating instances and it can hide all this under the covers.
>> Then, before creating a new X object, with a=a1, b=b1, c=c1 we would create a new list (a1, b1, c1) and see if an object of X with an equal list as key is already contained in the map.
> For a class, the values can always be changed, and when deserializing, the object is created first, and then the features are populated, so I don't see how this approach can work for that.
>>
>>
>> Do you think that this is a good idea? Any other suggestions?
>> Does it make sense to use BasicEList.FastCompare lists for this purpose?
> Certainly for a data type if you can ensure that there is at most one instance for any combination of values, you can rely on == instead of equals.
>>
>> Thanks for your input
>>
>> Joel
>
>
Re: creating a registry for objects with certain identifying features [message #895986 is a reply to message #895979] Mon, 16 July 2012 18:16 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

This sounds rather like what OCL has to do for Tuple types (and
Collection types) for which structurally equal types are the same type.

Computing the hash of the alphabetically sorted element names is
relatively cheap, so this is used as a hash to a list of types that may
have distinct element types for the same element names.

See
GIT\org.eclipse.ocl\examples\org.eclipse.ocl.examples.pivot\src\org\eclipse\ocl\examples\pivot\manager\TupleTypeManager.java.

Regards

Ed Willink

On 16/07/2012 18:59, Joel Greenyer wrote:
> Hi Ed,
> thanks for your comments.
> Yes, of course it only makes sense if what you are registering is not
> meant to be changed. Within our application we would ensure that.
> Also, we would serialize and deserialize the objects in a plain list
> and after the deserialization we would re-initialize this registry map.
> But would youhave any other suggestion than this key-list idea?
> What we would really need is only a convenient way to calculate some
> unique hash-value for the registered objects.
>
> Thanks
>
> Joel
>
>
> On 16.07.2012 15:38, Ed Merks wrote:
>> Joel,
>>
>> Comments below.
>>
>> On 16/07/2012 10:24 AM, Joel Greenyer wrote:
>>> Hi,
>>> in our application, we want to prevent creating many "structurally
>>> equal" objects.
>>> Let's say we have a class X with features a:A, b:B, c:C (A,B,C being
>>> classes or data types), then we don't want to have two X objects
>>> with the same values for a, b, and c. The reason here is to save
>>> memory and allow for a fast comparison of objects, using "=="
>>> instead of having to iterate over all the feature values.
>> I think it makes sense for data types that are immutable, but not so
>> much for classes.
>>>
>>> How do we do that?
>>> Our idea is to build a registry that basically consists of a (hash)
>>> map that maps lists of the identifying attributes to these objects,
>>> e.g. (A,B,C)->X.
>>> The lists are basically a way to create a unique key.
>> If you do this for a data type, you can ensure that there is a static
>> utility method for creating instances and it can hide all this under
>> the covers.
>>> Then, before creating a new X object, with a=a1, b=b1, c=c1 we would
>>> create a new list (a1, b1, c1) and see if an object of X with an
>>> equal list as key is already contained in the map.
>> For a class, the values can always be changed, and when
>> deserializing, the object is created first, and then the features are
>> populated, so I don't see how this approach can work for that.
>>>
>>>
>>> Do you think that this is a good idea? Any other suggestions?
>>> Does it make sense to use BasicEList.FastCompare lists for this
>>> purpose?
>> Certainly for a data type if you can ensure that there is at most one
>> instance for any combination of values, you can rely on == instead of
>> equals.
>>>
>>> Thanks for your input
>>>
>>> Joel
>>
>>
>
>
Previous Topic:[EMF Validation] how can i control multiple context?
Next Topic:[CDO 4.1] : Reattachment issue with EOpposite
Goto Forum:
  


Current Time: Fri Mar 29 10:29:09 GMT 2024

Powered by FUDForum. Page generated in 0.04127 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top