Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/llasram/hier-set
A Clojure hierarchical set.
https://github.com/llasram/hier-set
Last synced: about 2 months ago
JSON representation
A Clojure hierarchical set.
- Host: GitHub
- URL: https://github.com/llasram/hier-set
- Owner: llasram
- License: epl-1.0
- Created: 2012-03-30T12:17:48.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2020-09-24T12:03:36.000Z (about 4 years ago)
- Last Synced: 2024-10-05T08:18:17.501Z (3 months ago)
- Language: Clojure
- Homepage:
- Size: 137 KB
- Stars: 7
- Watchers: 2
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-clojure - Hierarchical set
README
# hier-set
Library providing a "hierarchical set" data structure. The provided data
structure is set of elements with a defined hierarchical relationship. An
element is considered to be in the set either if it is provided as a primary
set member or if it is a descendant of any such element. Lookup in the set not
only determines set membership, but also finds all primary set members which
are ancestors of the lookup element.The hierarchical relationship is defined by the element sort-order and a
separate containment predicate, with the following constraints:* elements must sort prior to any descendants; and
* elements must contain all elements which sort between themselves and any
descendant.This is sufficient to represent simple hierarchical systems where the hierarchy
is implicit in the entities involved, such as the Java package system,
hierarchical filesystems, or IP networks. It is inappropriate for modeling
complex, ad hoc hierarchies, such as the relationships between classes with
multiple inheritance.## Usage
Add `hier-set` to the `:dependencies` list in your
[Leiningen](https://github.com/technomancy/leiningen) `project.clj`:```clj
[hier-set "1.1.2"]
```Primary usage is then through the `hier-set` and `hier-set-by` constructor
functions in the `hier-set.core` namespace. In addition to set lookup as
described above, the `hier-set.core/ancestors` and `hier-set.core/descendants`
functions also provide access to lazy sequences of the ancestors and
descendants respectively of a provided key.## Example
A trivial example:
```clj
(ns example.hier-set
(:require [hier-set.core :as hs])
(:use [hier-set.core :only [hier-set]])(def with-starts? #(.startsWith %2 %1))
(def hs (hier-set with-starts? "ack" "foo" "foo.bar" "quux")
(get hs "bar") ;;=> nil
(get hs "foo") ;;=> ("foo")
(get hs "foo.bar.baz") ;;=> ("foo.bar" "foo")
(hs/ancestors hs "bar") ;;=> ()
(hs/ancestors hs "foo.baz") ;;=> ("foo")
(hs/descendants hs "foo") ;;=> ("foo" "foo.bar")
```## License
Copyright © 2012, 2014 Marshall Bockrath-Vandegrift.
Distributed under the Eclipse Public License either version 1.0 or (at
your option) any later version.