| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package datastore | 5 package datastore |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "bytes" | 8 "bytes" |
| 9 "encoding/base64" | 9 "encoding/base64" |
| 10 "encoding/json" | 10 "encoding/json" |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 fmt.Fprintf(ret, ", %s, %s", gqlQuoteString(t.Kind), gql
QuoteString(t.StringID)) | 407 fmt.Fprintf(ret, ", %s, %s", gqlQuoteString(t.Kind), gql
QuoteString(t.StringID)) |
| 408 } | 408 } |
| 409 } | 409 } |
| 410 if _, err := ret.WriteString(")"); err != nil { | 410 if _, err := ret.WriteString(")"); err != nil { |
| 411 panic(err) | 411 panic(err) |
| 412 } | 412 } |
| 413 return ret.String() | 413 return ret.String() |
| 414 } | 414 } |
| 415 | 415 |
| 416 // Equal returns true iff the two keys represent identical key values. | 416 // Equal returns true iff the two keys represent identical key values. |
| 417 func (k *Key) Equal(other *Key) (ret bool) { | 417 func (k *Key) Equal(other *Key) bool { |
| 418 » return k.SameKind(other) && (k.LastTok() == other.LastTok()) |
| 419 } |
| 420 |
| 421 // SameKind asserts that other refers to the same entity as k. This checks the |
| 422 // full lineage of the key. |
| 423 func (k *Key) SameKind(other *Key) (ret bool) { |
| 418 ret = (k.appID == other.appID && | 424 ret = (k.appID == other.appID && |
| 419 k.namespace == other.namespace && | 425 k.namespace == other.namespace && |
| 420 len(k.toks) == len(other.toks)) | 426 len(k.toks) == len(other.toks)) |
| 421 if ret { | 427 if ret { |
| 422 for i, t := range k.toks { | 428 for i, t := range k.toks { |
| 423 » » » if ret = t == other.toks[i]; !ret { | 429 » » » if i == len(k.toks)-1 { |
| 424 » » » » return | 430 » » » » // Last token: check only Kind. |
| 431 » » » » if ret = (t.Kind == other.toks[i].Kind); !ret { |
| 432 » » » » » return |
| 433 » » » » } |
| 434 » » » } else { |
| 435 » » » » if ret = t == other.toks[i]; !ret { |
| 436 » » » » » return |
| 437 » » » » } |
| 425 } | 438 } |
| 426 } | 439 } |
| 427 } | 440 } |
| 428 return | 441 return |
| 429 } | 442 } |
| 430 | 443 |
| 431 // Split componentizes the key into pieces (AppID, Namespace and tokens) | 444 // Split componentizes the key into pieces (AppID, Namespace and tokens) |
| 432 // | 445 // |
| 433 // Each token represents one piece of they key's 'path'. | 446 // Each token represents one piece of they key's 'path'. |
| 434 // | 447 // |
| (...skipping 17 matching lines...) Expand all Loading... |
| 452 for _, t := range k.toks { | 465 for _, t := range k.toks { |
| 453 ret += int64(len(t.Kind)) | 466 ret += int64(len(t.Kind)) |
| 454 if t.StringID != "" { | 467 if t.StringID != "" { |
| 455 ret += int64(len(t.StringID)) | 468 ret += int64(len(t.StringID)) |
| 456 } else { | 469 } else { |
| 457 ret += 8 | 470 ret += 8 |
| 458 } | 471 } |
| 459 } | 472 } |
| 460 return ret | 473 return ret |
| 461 } | 474 } |
| OLD | NEW |