Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Unified Diff: impl/memory/stringset.go

Issue 1302813003: impl/memory: Implement Queries (Closed) Base URL: https://github.com/luci/gae.git@add_multi_iterator
Patch Set: stringSet everywhere Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « impl/memory/gkvlite_utils_test.go ('k') | impl/memory/taskqueue_data.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: impl/memory/stringset.go
diff --git a/impl/memory/stringset.go b/impl/memory/stringset.go
new file mode 100644
index 0000000000000000000000000000000000000000..d803cb1bd065eb85c26f5050653c073b6e2d3505
--- /dev/null
+++ b/impl/memory/stringset.go
@@ -0,0 +1,39 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package memory
+
+type stringSet map[string]struct{}
+
+func (s stringSet) has(value string) bool {
+ _, ret := s[value]
+ return ret
+}
+
+// add adds to the set and returns true iff the value was not there before (i.e.
+// it returns true if add actually modifies the stringSet).
+func (s stringSet) add(value string) bool {
+ ret := !s.has(value)
+ s[value] = struct{}{}
+ return ret
+}
+
+func (s stringSet) rm(value string) {
+ delete(s, value)
+}
+
+func (s stringSet) dup() stringSet {
+ ret := make(stringSet, len(s))
+ for v := range s {
+ ret.add(v)
+ }
+ return ret
+}
+
+func (s stringSet) getOne() string {
+ for k := range s {
+ return k
+ }
+ return ""
+}
« no previous file with comments | « impl/memory/gkvlite_utils_test.go ('k') | impl/memory/taskqueue_data.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698