| 311 | } |
| 312 | |
| 313 | func (node Node) sameExtendedAttributes(other Node) bool { |
| 314 | ln := len(node.ExtendedAttributes) |
| 315 | lo := len(other.ExtendedAttributes) |
| 316 | if ln != lo { |
| 317 | return false |
| 318 | } else if ln == 0 { |
| 319 | // This means lo is also of length 0 |
| 320 | return true |
| 321 | } |
| 322 | |
| 323 | // build a set of all attributes that node has |
| 324 | type mapvalue struct { |
| 325 | value []byte |
| 326 | present bool |
| 327 | } |
| 328 | attributes := make(map[string]mapvalue) |
| 329 | for _, attr := range node.ExtendedAttributes { |
| 330 | attributes[attr.Name] = mapvalue{value: attr.Value} |
| 331 | } |
| 332 | |
| 333 | for _, attr := range other.ExtendedAttributes { |
| 334 | v, ok := attributes[attr.Name] |
| 335 | if !ok { |
| 336 | // extended attribute is not set for node |
| 337 | debug.Log("other node has attribute %v, which is not present in node", attr.Name) |
| 338 | return false |
| 339 | |
| 340 | } |
| 341 | |
| 342 | if !bytes.Equal(v.value, attr.Value) { |
| 343 | // attribute has different value |
| 344 | debug.Log("attribute %v has different value", attr.Name) |
| 345 | return false |
| 346 | } |
| 347 | |
| 348 | // remember that this attribute is present in other. |
| 349 | v.present = true |
| 350 | attributes[attr.Name] = v |
| 351 | } |
| 352 | |
| 353 | // check for attributes that are not present in other |
| 354 | for name, v := range attributes { |
| 355 | if !v.present { |
| 356 | debug.Log("attribute %v not present in other node", name) |
| 357 | return false |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | return true |
| 362 | } |
| 363 | |
| 364 | func (node Node) sameGenericAttributes(other Node) bool { |
| 365 | return deepEqual(node.GenericAttributes, other.GenericAttributes) |