A "hierarchical set" data structure for Clojure has elements in a defined hierarchical relationship. An element is a member if it is a primary member or a descendant of a primary member. Lookup returns set membership and all primary members that are ancestors of the lookup element.
The element sort-order and a separate containment predicate define the hierarchical relationship. These constraints apply:
Use this library for simple hierarchical systems. The hierarchy is implicit in the entities, such as the Java package system, hierarchical filesystems, or IP networks. Do not use this library for complex ad hoc hierarchies, such as relationships between classes with multiple inheritance.
Clojure CLI (deps.edn):
net.clojars.savya/hier-set {:mvn/version "1.2.3"}
Leiningen (project.clj):
[net.clojars.savya/hier-set "1.2.3"]
Run tests with clojure -M:test. Build the JAR with
clojure -T:build jar, or deploy with clojure -T:build deploy.
Use the hier-set and hier-set-by constructor functions in the
hier-set.core namespace. The hier-set.core/ancestors and
hier-set.core/descendants functions return lazy sequences of the ancestors
and descendants of a provided key.
The library requires Clojure 1.10 or later and JDK 8 or later. The library is continuously tested against Clojure 1.10.3, 1.11.4, and 1.12.5 on JDK 8, 11, 17, and 21.
A basic example:
(ns example.hier-set
(:require [hier-set.core :as hs :refer [hier-set]]))
(def starts-with? #(.startsWith %2 %1))
(def h (hier-set starts-with? "ack" "foo" "foo.bar" "quux"))
(get h "bar") ;;=> nil
(get h "foo") ;;=> ("foo")
(get h "foo.bar.baz") ;;=> ("foo.bar" "foo")
(hs/ancestors h "bar") ;;=> ()
(hs/ancestors h "foo.baz") ;;=> ("foo")
(hs/descendants h "foo") ;;=> ("foo" "foo.bar")
Copyright © 2012, 2014 Marshall Bockrath-Vandegrift.
Maintenance fork (2026) by Savyasachi, original: https://github.com/llasram/hier-set. Distributed under the Eclipse Public License 1.0, preserving the original license.
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.
Can you improve this documentation? These fine people already did:
Savyasachi, Marshall T. Vandegrift & Marshall Bockrath-VandegriftEdit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |