Index: trunk/extensions/SemanticMediaWiki/includes/SMW_SemanticData.php |
— | — | @@ -39,9 +39,10 @@ |
40 | 40 | static protected $m_propertyprefix = false; |
41 | 41 | |
42 | 42 | /// SMWWikiPageValue object that is the subject of this container. |
| 43 | + /// Subjects that are NULL are used to represent "internal objects" only. |
43 | 44 | protected $subject; |
44 | 45 | |
45 | | - public function __construct(SMWWikiPageValue $subject, $noduplicates = true) { |
| 46 | + public function __construct($subject, $noduplicates = true) { |
46 | 47 | $this->subject = $subject; |
47 | 48 | $this->m_noduplicates = $noduplicates; |
48 | 49 | $this->stubobject = false; |
— | — | @@ -102,6 +103,25 @@ |
103 | 104 | } |
104 | 105 | |
105 | 106 | /** |
| 107 | + * Generate a hash value to simplify the comparison of this data container with other |
| 108 | + * containers. The hash uses PHP's md5 implementation, which is among the fastest hash |
| 109 | + * algorithms that PHP offers. |
| 110 | + */ |
| 111 | + public function getHash() { |
| 112 | + $ctx = hash_init('md5'); |
| 113 | + if ($this->subject !== NULL) { // here and below, use "_#_" to separate values; really not much care needed here |
| 114 | + hash_update($ctx, '_#_' . $this->subject->getHash()); |
| 115 | + } |
| 116 | + foreach ($this->getProperties() as $property) { |
| 117 | + hash_update($ctx, '_#_' . $property->getHash() . '##'); |
| 118 | + foreach ($this->getPropertyValues($property) as $dv) { |
| 119 | + hash_update($ctx, '_#_' . $dv->getHash()); |
| 120 | + } |
| 121 | + } |
| 122 | + return hash_final($ctx); |
| 123 | + } |
| 124 | + |
| 125 | + /** |
106 | 126 | * Return true if there are any visible properties. |
107 | 127 | * @note While called "visible" this check actually refers to the function |
108 | 128 | * SMWPropertyValue::isShown(). The name is kept for compatibility. |