summaryrefslogtreecommitdiff
path: root/lib/maps
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2022-07-13 21:22:14 -0600
committerLuke Shumaker <lukeshu@lukeshu.com>2022-07-13 21:39:42 -0600
commit72a458520fccafe4df8c02c811cb6f64a310616e (patch)
tree1c424b5376c31524b01f8461b02950eb04d48345 /lib/maps
parent952b677bf7f10da93673e3671f764c54c454bbfe (diff)
Move the remaining former-generic.go parts out of lib/util/
Diffstat (limited to 'lib/maps')
-rw-r--r--lib/maps/maputil.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/maps/maputil.go b/lib/maps/maputil.go
new file mode 100644
index 0000000..aeebe12
--- /dev/null
+++ b/lib/maps/maputil.go
@@ -0,0 +1,25 @@
+// Copyright (C) 2022 Luke Shumaker <lukeshu@lukeshu.com>
+//
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+package maps
+
+import (
+ "golang.org/x/exp/constraints"
+
+ "git.lukeshu.com/btrfs-progs-ng/lib/slices"
+)
+
+func Keys[K comparable, V any](m map[K]V) []K {
+ ret := make([]K, 0, len(m))
+ for k := range m {
+ ret = append(ret, k)
+ }
+ return ret
+}
+
+func SortedKeys[K constraints.Ordered, V any](m map[K]V) []K {
+ ret := Keys(m)
+ slices.Sort(ret)
+ return ret
+}