Index: service/datastore/key.go |
diff --git a/service/datastore/key.go b/service/datastore/key.go |
index 3bf02e861e3f99118fab2258070106b04ca45091..47bbad297ee8567f0e491bbce61ff08d2e19ee50 100644 |
--- a/service/datastore/key.go |
+++ b/service/datastore/key.go |
@@ -359,6 +359,22 @@ func (k *Key) Less(other *Key) bool { |
return len(k.toks) < len(other.toks) |
} |
+// HasAncestor returns true iff other is an ancestor of k. |
Vadim Sh.
2015/09/28 18:52:56
... or k is other.
iannucci
2015/09/29 03:21:37
Yes. Done.
|
+func (k *Key) HasAncestor(other *Key) bool { |
+ if k.appID != other.appID || k.namespace != other.namespace { |
+ return false |
+ } |
+ if len(k.toks) < len(other.toks) { |
+ return false |
+ } |
+ for i, tok := range other.toks { |
+ if tok != k.toks[i] { |
+ return false |
+ } |
+ } |
+ return true |
+} |
+ |
// GQL returns a correctly formatted Cloud Datastore GQL key literal. |
// |
// The flavor of GQL that this emits is defined here: |