summaryrefslogtreecommitdiff
path: root/lib/maps/maputil.go
diff options
context:
space:
mode:
Diffstat (limited to 'lib/maps/maputil.go')
-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
+}