Comparing items for sameness
May 27th, 2005 at 1:20 pm (3 years, 1 month ago) by Andi Vajda under chandlerdbWhile an item’s UUID is normally used to compare items for sameness, there are times when it is useful to compare item instances with different UUIDs as, for example, while importing items from another repository. The Item class does not implement any Python comparison hook functions, comparing items is left to the implementors since meaningful item comparison depends on the items’ schema and on the knowledge of the implementor. For instance, not all attributes are equally relevant, some may even be completely irrelevant for comparison purposes. To help with this, a new API, hashItem(), was added to the Item class. Two items can be defined to be the ’same’ when their hash values are the same.
Item.hashItem() computes a hash value, a semantic signature for an item. While this method is meant to be specialized, the Item class provides a default implementation that is very generic and treats all persistent attributes equally. The generic hash value of an item is a combination of the hashes of the item’s instance class name, the item’s kind, and the item’s persistent values and references.
The hashItem() method of schema items is specialized to include only their semantically meaningful characteristics. For example, the hash value of a Kind item is a combination of the hashes of kind’s path, the kind’s attribute names and attribute items, and the kind’s superKinds. The kind’s subKinds or the kind’s clouds are not included, for example. Similarly, the hash value of an Attribute item is a combination of the hashes of the attribute’s superAttributes and aspects. The hash value of a Type item is just the hash value of its path.








