├── .travis.yml ├── src └── clope │ ├── impl.clj │ ├── core.cljc │ └── impl.cljs ├── deps.edn ├── test └── clope │ └── core_test.cljc ├── pom.xml ├── README.md ├── java └── clope │ └── impl │ └── Rope.java └── LICENSE /.travis.yml: -------------------------------------------------------------------------------- 1 | dist: xenial 2 | sudo: true 3 | language: clojure 4 | script: 5 | - mvn compile 6 | - clojure -Aclj-test 7 | - clojure -Acljs-test 8 | - clojure -Acljs-test -x planck 9 | install: 10 | - curl -O https://download.clojure.org/install/linux-install-1.10.1.447.sh 11 | - chmod +x linux-install-1.10.1.447.sh 12 | - sudo ./linux-install-1.10.1.447.sh 13 | - sudo add-apt-repository -y ppa:mfikes/planck 14 | - sudo apt-get update -y 15 | - sudo apt-get install -y planck 16 | -------------------------------------------------------------------------------- /src/clope/impl.clj: -------------------------------------------------------------------------------- 1 | (ns ^:no-doc clope.impl 2 | (:import (clope.impl Rope) (java.io Writer))) 3 | 4 | (defmethod print-method Rope [^Rope r ^Writer w] 5 | (.write w "#rope") 6 | (print-method {:hash (.hashCode r) :size (.size r)} w)) 7 | 8 | (defn wrap [^bytes bytes] 9 | (when (pos? (alength bytes)) (Rope/wrap bytes))) 10 | 11 | (defn join [^Rope l ^Rope r] 12 | (Rope/join l r)) 13 | 14 | (defn size [^Rope r] 15 | (.size r)) 16 | 17 | (defn subr [^Rope r ^long s ^long e] 18 | (.subr r s e)) -------------------------------------------------------------------------------- /deps.edn: -------------------------------------------------------------------------------- 1 | {:deps {org.clojure/clojure {:mvn/version "1.10.1"} 2 | org.clojure/clojurescript {:mvn/version "1.10.520"}} 3 | :paths ["src" "target/classes"] 4 | :aliases 5 | {:clj-test 6 | {:extra-deps {com.cognitect/test-runner 7 | {:git/url "https://github.com/cognitect-labs/test-runner.git" 8 | :sha "028a6d41ac9ac5d5c405dfc38e4da6b4cc1255d5"} 9 | org.clojure/test.check {:mvn/version "0.9.0"}} 10 | :extra-paths ["test"] 11 | :main-opts ["-m" "cognitect.test-runner"]} 12 | :cljs-test 13 | {:extra-deps {olical/cljs-test-runner {:mvn/version "3.6.0"} 14 | org.clojure/test.check {:mvn/version "0.9.0"}} 15 | :extra-paths ["test" "cljs-test-runner-out/gen"] 16 | :main-opts ["-m" "cljs-test-runner.main"]}}} -------------------------------------------------------------------------------- /src/clope/core.cljc: -------------------------------------------------------------------------------- 1 | (ns clope.core 2 | (:require [clope.impl :as i])) 3 | 4 | (defn wrap 5 | "Wraps given byte array into a rope." 6 | [bytes] (when (some? bytes) (i/wrap bytes))) 7 | 8 | (defn join 9 | "Returns a concatenation of given ropes." 10 | ([]) 11 | ([r] r) 12 | ([l r] (if (nil? l) r (if (nil? r) l (i/join l r)))) 13 | ([l r & s] (reduce join (join l r) s))) 14 | 15 | (defn size 16 | "Returns the size of given `rope`, in bytes." 17 | ^long [rope] (if (nil? rope) 0 (i/size rope))) 18 | 19 | (defn subr 20 | "Returns a subrope of given `rope` with bytes from `start` (inclusive, defaults to 0) to `end` (exclusive, defaults to `(size rope)`)." 21 | ([]) 22 | ([rope] rope) 23 | ([rope ^long start] (subr rope start (size rope))) 24 | ([rope ^long start ^long end] 25 | (assert (<= 0 start end (size rope)) "subrope out of bounds") 26 | (when-not (== start end) (i/subr rope start end)))) -------------------------------------------------------------------------------- /test/clope/core_test.cljc: -------------------------------------------------------------------------------- 1 | (ns clope.core-test 2 | (:require [clojure.test :refer [deftest is]] 3 | [clojure.test.check :as tc] 4 | [clojure.test.check.generators :as g #?@(:cljs [:include-macros true])] 5 | [clojure.test.check.properties :as p #?@(:cljs [:include-macros true])] 6 | [clope.core :as c])) 7 | 8 | (defn bytes->array [bytes] 9 | #?(:clj (reduce-kv (fn [a i b] (doto ^bytes a (aset i (byte b)))) (byte-array (count bytes)) bytes) 10 | :cljs (.-buffer (reduce-kv (fn [a i b] (doto a (.setInt8 i b))) (-> (count bytes) (js/ArrayBuffer.) (js/DataView.)) bytes)))) 11 | 12 | (def ropes 13 | (->> (g/choose -128 127) 14 | (g/vector) 15 | (g/fmap (comp c/wrap bytes->array)) 16 | (g/vector) 17 | (g/fmap (partial apply c/join)))) 18 | 19 | (def subr-join-equality 20 | (p/for-all [[r s] (g/let [r ropes 21 | i (g/choose 0 (c/size r))] 22 | [r (c/join (c/subr r 0 i) (c/subr r i))])] 23 | (and (= (c/size r) (c/size s)) 24 | (= (hash r) (hash s)) 25 | (= r s)))) 26 | 27 | (deftest main 28 | (is (:result (tc/quick-check 1000 subr-join-equality)))) -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | clope 5 | clope 6 | 1 7 | clope 8 | Byte ropes for clojure and clojurescript. 9 | https://github.com/leonoel/clope 10 | 11 | 12 | Eclipse Public License 13 | https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html 14 | 15 | 16 | 17 | scm:git:git://github.com/leonoel/clope.git 18 | scm:git:ssh://git@github.com/leonoel/clope.git 19 | f7eb302ebce63b2664de5e65edbcaf198ae09da4 20 | https://github.com/leonoel/clope 21 | 22 | 23 | 24 | clojars 25 | Clojars repository 26 | https://clojars.org/repo 27 | 28 | 29 | 30 | java 31 | 32 | 33 | src 34 | 35 | 36 | target 37 | target/classes 38 | 39 | 40 | org.apache.maven.plugins 41 | maven-compiler-plugin 42 | 43 | 8 44 | 8 45 | 46 | 47 | 48 | 49 | 50 | 51 | clojars 52 | https://repo.clojars.org/ 53 | 54 | 55 | 56 | 57 | org.clojure 58 | clojure 59 | 1.10.1 60 | 61 | 62 | org.clojure 63 | clojurescript 64 | 1.10.520 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # clope 2 | 3 | Byte ropes for clojure and clojurescript. 4 | 5 | [![clojars](https://img.shields.io/clojars/v/clope.svg)](https://clojars.org/clope) 6 | [![cljdoc](https://cljdoc.org/badge/clope/clope)](https://cljdoc.org/d/clope/clope/CURRENT) 7 | [![build](https://travis-ci.org/leonoel/clope.svg?branch=master)](https://travis-ci.org/leonoel/clope) 8 | [![license](https://img.shields.io/github/license/leonoel/clope.svg)](LICENSE) 9 | 10 | 11 | ## Maturity 12 | 13 | Stable. 14 | 15 | 16 | ## Rationale 17 | 18 | Ropes are immutable data structures holding sequences of bytes, represented as binary trees instead of contiguous memory arrays. This provides sub-linear algorithmic complexity for concatenation and slicing, and relaxes allocation-related constraints. 19 | 20 | 21 | ## Documentation 22 | 23 | [`clope.core`](https://cljdoc.org/d/clope/clope/CURRENT/api/clope.core) 24 | 25 | 26 | ### Overview 27 | 28 | ```clojure 29 | (require '[clope.core :as c]) 30 | ``` 31 | 32 | `wrap` turns a byte array into a rope. 33 | ```clojure 34 | (c/wrap (.getBytes "clojure")) 35 | #_=> #rope{:hash 866284260, :size 7} 36 | ``` 37 | 38 | `size` returns the number of bytes in a rope. 39 | ```clojure 40 | (def rope (c/wrap (.getBytes "clojure"))) 41 | (c/size rope) 42 | #_=> 7 43 | ``` 44 | 45 | `join` returns the concatenation of an arbitrary number of ropes. 46 | ```clojure 47 | (c/join (c/wrap (.getBytes "Hello ")) 48 | (c/wrap (.getBytes "World !"))) 49 | #_=> #rope{:hash 22678917, :size 13} 50 | ``` 51 | 52 | `subr` returns a subrope of an arbitrary rope, with bytes in the given range. 53 | ```clojure 54 | (c/subr (c/wrap (.getBytes "clojure")) 1 4) 55 | #_=> #rope{:hash 107335, :size 3} 56 | ``` 57 | 58 | Ropes are collections of their underlying byte arrays, they are counted, iterable, seqable and reducible. 59 | ```clojure 60 | (def rope (c/join (c/wrap (.getBytes "Hello ")) 61 | (c/wrap (.getBytes "World !")))) 62 | 63 | (count rope) 64 | #_=> 2 65 | 66 | (map alength rope) 67 | #_=> (6 7) 68 | 69 | (import java.nio.ByteBuffer) 70 | (import java.nio.charset.Charset) 71 | (defn bb-put [^ByteBuffer buffer ^bytes array] (.put buffer array)) 72 | (->> rope 73 | (reduce bb-put (ByteBuffer/allocate (c/size rope))) 74 | (.flip) 75 | (.decode (Charset/defaultCharset)) 76 | (.toString)) 77 | #_=> "Hello World !" 78 | ``` 79 | 80 | `nil` is the empty rope, it's safe to pass it where a rope is expected. non-`nil` implies non-empty. 81 | ```clojure 82 | (c/size nil) 83 | #_=> 0 84 | ``` 85 | 86 | Ropes implement proper hashing and equality semantics, based on actual byte content. 87 | ```clojure 88 | (= (c/wrap (.getBytes "clojure")) 89 | (c/join (c/wrap (.getBytes "clo")) 90 | (c/wrap (.getBytes "jure")))) 91 | #_=> true 92 | ``` 93 | 94 | 95 | ### Caveats 96 | 97 | For performance reasons, the rope implementation assumes to take full ownership of the arrays it wraps and doesn't perform any defensive copies. The immutability contract of ropes holds by the following conditions : 98 | * don't write to an array after it's been `wrap`ped in a rope. 99 | * treat arrays exposed by rope traversal as read-only. -------------------------------------------------------------------------------- /src/clope/impl.cljs: -------------------------------------------------------------------------------- 1 | (ns ^:no-doc clope.impl) 2 | 3 | (declare join) 4 | 5 | (defn hash-dv ^number [^number hash dv] 6 | (loop [h hash 7 | i (.-byteOffset dv)] 8 | (if (< i (.-byteLength dv)) 9 | (recur (-> h (imul 31) (+ (.getInt8 dv i))) (inc i)) h))) 10 | 11 | (defprotocol Rope 12 | (-size [_]) 13 | (-subr [_ ^number start ^number end]) 14 | (-append [_ ^Rope rope]) 15 | (-prepend [_ ^Rope rope]) 16 | (-populate [_ ^array arrays ^number index])) 17 | 18 | (defn print-rope [rope writer opts] 19 | (-write writer "#rope") 20 | (pr-writer {:hash (-hash rope) :size (-size rope)} writer opts)) 21 | 22 | (deftype Join [^number size ^Rope left ^Rope right ^:mutable hash] 23 | Rope 24 | (-size [_] size) 25 | (-subr [_ ^number start ^number end] 26 | (if (== (- end start) size) 27 | _ (let [startk (- start (-size left)) 28 | endk (- end (-size left))] 29 | (if (neg? startk) 30 | (if (pos? endk) 31 | (join (-subr left start (-size left)) 32 | (-subr right 0 endk)) 33 | (-subr left start end)) 34 | (-subr right startk endk))))) 35 | (-append [_ ^Rope rope] 36 | (if (< (-size rope) (-size left)) 37 | (join left (join right rope)) 38 | (Join. (+ size (-size rope)) _ rope nil))) 39 | (-prepend [_ ^Rope rope] 40 | (if (< (-size rope) (-size right)) 41 | (join (join rope left) right) 42 | (Join. (+ (-size rope) size) rope _ nil))) 43 | (-populate [_ ^array arrays ^number index] 44 | (->> index 45 | (-populate left arrays) 46 | (-populate right arrays))) 47 | IHash 48 | (-hash [_] 49 | (if-some [h hash] 50 | h (let [it (iter right)] 51 | (loop [h (-hash left)] 52 | (if (.hasNext it) 53 | (recur (hash-dv h (js/DataView. (.next it)))) 54 | (set! hash h)))))) 55 | IEquiv 56 | (-equiv [_ o] 57 | (and (some? o) 58 | (satisfies? Rope o) 59 | (== size (-size o)) 60 | (= left (-subr o 0 (-size left))) 61 | (= right (-subr o (-size left) size)))) 62 | ICounted 63 | (-count [_] (+ (-count left) (-count right))) 64 | ISeqable 65 | (-seq [_] 66 | (let [arrays (object-array (-count _))] 67 | (-populate _ arrays 0) 68 | (->IndexedSeq arrays 0 nil))) 69 | IIterable 70 | (-iterator [_] 71 | (let [arrays (object-array (-count _))] 72 | (-populate _ arrays 0) 73 | (->IndexedSeqIterator arrays 0))) 74 | IReduce 75 | (-reduce [_ f] 76 | (let [arrays (object-array (-count _))] 77 | (-populate _ arrays 0) 78 | (array-reduce arrays f))) 79 | (-reduce [_ f i] 80 | (let [arrays (object-array (-count _))] 81 | (-populate _ arrays 0) 82 | (array-reduce arrays f i))) 83 | IPrintWithWriter 84 | (-pr-writer [_ writer opts] 85 | (print-rope _ writer opts))) 86 | 87 | (deftype Wrap [ab ^:mutable hash] 88 | Rope 89 | (-size [_] (.-byteLength ab)) 90 | (-subr [_ ^number start ^number end] 91 | (if (== (- end start) (.-byteLength ab)) 92 | _ (Wrap. (.slice ab start end) nil))) 93 | (-append [_ ^Rope rope] 94 | (->Join (+ (-size _) (-size rope)) _ rope nil)) 95 | (-prepend [_ ^Rope rope] 96 | (->Join (+ (-size rope) (-size _)) rope _ nil)) 97 | (-populate [_ ^array arrays ^number index] 98 | (aset arrays index ab) 99 | (inc index)) 100 | IHash 101 | (-hash [_] 102 | (if-some [h hash] 103 | h (set! hash (hash-dv 0 (js/DataView. ab))))) 104 | IEquiv 105 | (-equiv [_ o] 106 | (and (some? o) 107 | (satisfies? Rope o) 108 | (== (.-byteLength ab) (-size o)) 109 | (let [it (iter o) 110 | dv (js/DataView. ab)] 111 | (loop [i 0] 112 | (if (< i (.-byteLength ab)) 113 | (let [oab (.next it) 114 | odv (js/DataView. oab)] 115 | (if (loop [j 0] 116 | (if (< j (.-byteLength oab)) 117 | (if (== (.getInt8 odv j) (.getInt8 dv (+ i j))) 118 | (recur (inc j)) false) true)) 119 | (recur (+ i (.-byteLength oab))) false)) true))))) 120 | ICounted 121 | (-count [_] 1) 122 | ISeqable 123 | (-seq [_] (list ab)) 124 | IIterable 125 | (-iterator [_] (iter (list ab))) 126 | IReduce 127 | (-reduce [_ _] ab) 128 | (-reduce [_ f i] 129 | (let [r (f i ab)] 130 | (if (reduced? r) @r r))) 131 | IPrintWithWriter 132 | (-pr-writer [_ writer opts] 133 | (print-rope _ writer opts))) 134 | 135 | (defn wrap [ab] 136 | (when (pos? (.-byteLength ab)) (->Wrap ab nil))) 137 | 138 | (defn join [^Rope l ^Rope r] 139 | (if (> (-size l) (-size r)) 140 | (-append l r) (-prepend r l))) 141 | 142 | (def size -size) 143 | 144 | (def subr -subr) -------------------------------------------------------------------------------- /java/clope/impl/Rope.java: -------------------------------------------------------------------------------- 1 | package clope.impl; 2 | 3 | import clojure.lang.*; 4 | 5 | import java.util.Iterator; 6 | 7 | public interface Rope extends Seqable, Counted, Iterable, IReduce { 8 | 9 | long size(); 10 | Rope subr(long start, long end); 11 | Rope append(Rope rope); 12 | Rope prepend(Rope rope); 13 | int populate(Object[] arrays, int index); 14 | 15 | static Rope wrap(byte[] b) { 16 | return new Wrap(b); 17 | } 18 | static Rope join(Rope l, Rope r) { 19 | return l.size() > r.size() ? l.append(r) : r.prepend(l); 20 | } 21 | 22 | final class Wrap implements Rope { 23 | final byte[] bytes; 24 | int hash; 25 | 26 | Wrap(byte[] a) { 27 | bytes = a; 28 | } 29 | 30 | @Override 31 | public int count() { 32 | return 1; 33 | } 34 | 35 | @Override 36 | public ISeq seq() { 37 | return new PersistentList(bytes); 38 | } 39 | 40 | @Override 41 | public Iterator iterator() { 42 | return new Iterator() { 43 | boolean done; 44 | 45 | @Override 46 | public boolean hasNext() { 47 | return !done; 48 | } 49 | 50 | @Override 51 | public Object next() { 52 | done = true; 53 | return bytes; 54 | } 55 | }; 56 | } 57 | 58 | @Override 59 | public Object reduce(IFn f) { 60 | return bytes; 61 | } 62 | 63 | @Override 64 | public Object reduce(IFn f, Object init) { 65 | Object r = f.invoke(init, bytes); 66 | return r instanceof Reduced ? ((Reduced) r).deref() : r; 67 | } 68 | 69 | @Override 70 | public long size() { 71 | return bytes.length; 72 | } 73 | 74 | @Override 75 | public Rope subr(long start, long end) { 76 | int f = (int) start; 77 | int s = (int) end - f; 78 | if (s == bytes.length) return this; 79 | byte[] b = new byte[s]; 80 | System.arraycopy(bytes, f, b, 0, s); 81 | return new Wrap(b); 82 | } 83 | 84 | @Override 85 | public Rope append(Rope r) { 86 | return new Join(this, r); 87 | } 88 | 89 | @Override 90 | public Rope prepend(Rope r) { 91 | return new Join(r, this); 92 | } 93 | 94 | @Override 95 | public int populate(Object[] arrays, int index) { 96 | arrays[index] = bytes; 97 | return index + 1; 98 | } 99 | 100 | @Override 101 | public int hashCode() { 102 | int h = hash; 103 | if (h == 0) { 104 | for(byte b: bytes) h = h * 31 + b; 105 | hash = h; 106 | } 107 | return h; 108 | } 109 | 110 | @Override 111 | public boolean equals(Object o) { 112 | if (o == null) return false; 113 | if (!(o instanceof Rope)) return false; 114 | Rope r = (Rope) o; 115 | if (size() != r.size()) return false; 116 | int i = 0; 117 | for(Object bs: r) 118 | for(byte b: (byte []) bs) 119 | if (bytes[i++] != b) return false; 120 | return true; 121 | } 122 | } 123 | 124 | final class Join implements Rope { 125 | final long size; 126 | final Rope left; 127 | final Rope right; 128 | 129 | int hash; 130 | 131 | Join(Rope l, Rope r) { 132 | size = l.size() + r.size(); 133 | left = l; 134 | right = r; 135 | } 136 | 137 | @Override 138 | public int count() { 139 | return left.count() + right.count(); 140 | } 141 | 142 | @Override 143 | public ISeq seq() { 144 | Object[] arrays = new Object[count()]; 145 | populate(arrays, 0); 146 | return ArraySeq.create(arrays); 147 | } 148 | 149 | @Override 150 | public Iterator iterator() { 151 | Object[] arrays = new Object[count()]; 152 | populate(arrays, 0); 153 | return new Iterator() { 154 | int i; 155 | 156 | @Override 157 | public boolean hasNext() { 158 | return i < arrays.length; 159 | } 160 | 161 | @Override 162 | public Object next() { 163 | return arrays[i++]; 164 | } 165 | }; 166 | } 167 | 168 | @Override 169 | public Object reduce(IFn f) { 170 | int n = count(); 171 | Object[] arrays = new Object[n]; 172 | populate(arrays, 0); 173 | Object r = arrays[0]; 174 | for(int i = 1; i < n; i++) { 175 | r = f.invoke(r, arrays[i]); 176 | if (r instanceof Reduced) return ((Reduced) r).deref(); 177 | } 178 | return r; 179 | } 180 | 181 | @Override 182 | public Object reduce(IFn f, Object r) { 183 | int n = count(); 184 | Object[] arrays = new Object[n]; 185 | populate(arrays, 0); 186 | for (int i = 0; i < n; i++) { 187 | r = f.invoke(r, arrays[i]); 188 | if (r instanceof Reduced) return ((Reduced) r).deref(); 189 | } 190 | return r; 191 | } 192 | 193 | @Override 194 | public int hashCode() { 195 | int h = hash; 196 | if (h == 0) { 197 | h = left.hashCode(); 198 | for(Object bs: right) 199 | for(byte b: (byte[]) bs) 200 | h = h * 31 + b; 201 | hash = h; 202 | } 203 | return h; 204 | } 205 | 206 | @Override 207 | public boolean equals(Object o) { 208 | if (o == null) return false; 209 | if (!(o instanceof Rope)) return false; 210 | Rope r = (Rope) o; 211 | long s = left.size(); 212 | return (size == r.size()) && 213 | left.equals(r.subr(0, s)) && 214 | right.equals(r.subr(s, size)); 215 | } 216 | 217 | @Override 218 | public int populate(Object[] arrays, int index) { 219 | return right.populate(arrays, left.populate(arrays, index)); 220 | } 221 | 222 | @Override 223 | public long size() { 224 | return size; 225 | } 226 | 227 | @Override 228 | public Rope subr(long start, long end) { 229 | if (end - start == size) return this; 230 | long startk = start - left.size(); 231 | long endk = end - left.size(); 232 | return (startk < 0) ? (endk > 0) ? 233 | join(left.subr(start, left.size()), right.subr(0, endk)) : 234 | left.subr(start, end) : right.subr(startk, endk); 235 | } 236 | 237 | @Override 238 | public Rope append(Rope r) { 239 | return r.size() < left.size() ? join(left, join(right, r)) : new Join(this, r); 240 | } 241 | 242 | @Override 243 | public Rope prepend(Rope r) { 244 | return r.size() < right.size() ? join(join(r, left), right) : new Join(r, this); 245 | } 246 | } 247 | } 248 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Eclipse Public License - v 2.0 2 | 3 | THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE 4 | PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION 5 | OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT. 6 | 7 | 1. DEFINITIONS 8 | 9 | "Contribution" means: 10 | 11 | a) in the case of the initial Contributor, the initial content 12 | Distributed under this Agreement, and 13 | 14 | b) in the case of each subsequent Contributor: 15 | i) changes to the Program, and 16 | ii) additions to the Program; 17 | where such changes and/or additions to the Program originate from 18 | and are Distributed by that particular Contributor. A Contribution 19 | "originates" from a Contributor if it was added to the Program by 20 | such Contributor itself or anyone acting on such Contributor's behalf. 21 | Contributions do not include changes or additions to the Program that 22 | are not Modified Works. 23 | 24 | "Contributor" means any person or entity that Distributes the Program. 25 | 26 | "Licensed Patents" mean patent claims licensable by a Contributor which 27 | are necessarily infringed by the use or sale of its Contribution alone 28 | or when combined with the Program. 29 | 30 | "Program" means the Contributions Distributed in accordance with this 31 | Agreement. 32 | 33 | "Recipient" means anyone who receives the Program under this Agreement 34 | or any Secondary License (as applicable), including Contributors. 35 | 36 | "Derivative Works" shall mean any work, whether in Source Code or other 37 | form, that is based on (or derived from) the Program and for which the 38 | editorial revisions, annotations, elaborations, or other modifications 39 | represent, as a whole, an original work of authorship. 40 | 41 | "Modified Works" shall mean any work in Source Code or other form that 42 | results from an addition to, deletion from, or modification of the 43 | contents of the Program, including, for purposes of clarity any new file 44 | in Source Code form that contains any contents of the Program. Modified 45 | Works shall not include works that contain only declarations, 46 | interfaces, types, classes, structures, or files of the Program solely 47 | in each case in order to link to, bind by name, or subclass the Program 48 | or Modified Works thereof. 49 | 50 | "Distribute" means the acts of a) distributing or b) making available 51 | in any manner that enables the transfer of a copy. 52 | 53 | "Source Code" means the form of a Program preferred for making 54 | modifications, including but not limited to software source code, 55 | documentation source, and configuration files. 56 | 57 | "Secondary License" means either the GNU General Public License, 58 | Version 2.0, or any later versions of that license, including any 59 | exceptions or additional permissions as identified by the initial 60 | Contributor. 61 | 62 | 2. GRANT OF RIGHTS 63 | 64 | a) Subject to the terms of this Agreement, each Contributor hereby 65 | grants Recipient a non-exclusive, worldwide, royalty-free copyright 66 | license to reproduce, prepare Derivative Works of, publicly display, 67 | publicly perform, Distribute and sublicense the Contribution of such 68 | Contributor, if any, and such Derivative Works. 69 | 70 | b) Subject to the terms of this Agreement, each Contributor hereby 71 | grants Recipient a non-exclusive, worldwide, royalty-free patent 72 | license under Licensed Patents to make, use, sell, offer to sell, 73 | import and otherwise transfer the Contribution of such Contributor, 74 | if any, in Source Code or other form. This patent license shall 75 | apply to the combination of the Contribution and the Program if, at 76 | the time the Contribution is added by the Contributor, such addition 77 | of the Contribution causes such combination to be covered by the 78 | Licensed Patents. The patent license shall not apply to any other 79 | combinations which include the Contribution. No hardware per se is 80 | licensed hereunder. 81 | 82 | c) Recipient understands that although each Contributor grants the 83 | licenses to its Contributions set forth herein, no assurances are 84 | provided by any Contributor that the Program does not infringe the 85 | patent or other intellectual property rights of any other entity. 86 | Each Contributor disclaims any liability to Recipient for claims 87 | brought by any other entity based on infringement of intellectual 88 | property rights or otherwise. As a condition to exercising the 89 | rights and licenses granted hereunder, each Recipient hereby 90 | assumes sole responsibility to secure any other intellectual 91 | property rights needed, if any. For example, if a third party 92 | patent license is required to allow Recipient to Distribute the 93 | Program, it is Recipient's responsibility to acquire that license 94 | before distributing the Program. 95 | 96 | d) Each Contributor represents that to its knowledge it has 97 | sufficient copyright rights in its Contribution, if any, to grant 98 | the copyright license set forth in this Agreement. 99 | 100 | e) Notwithstanding the terms of any Secondary License, no 101 | Contributor makes additional grants to any Recipient (other than 102 | those set forth in this Agreement) as a result of such Recipient's 103 | receipt of the Program under the terms of a Secondary License 104 | (if permitted under the terms of Section 3). 105 | 106 | 3. REQUIREMENTS 107 | 108 | 3.1 If a Contributor Distributes the Program in any form, then: 109 | 110 | a) the Program must also be made available as Source Code, in 111 | accordance with section 3.2, and the Contributor must accompany 112 | the Program with a statement that the Source Code for the Program 113 | is available under this Agreement, and informs Recipients how to 114 | obtain it in a reasonable manner on or through a medium customarily 115 | used for software exchange; and 116 | 117 | b) the Contributor may Distribute the Program under a license 118 | different than this Agreement, provided that such license: 119 | i) effectively disclaims on behalf of all other Contributors all 120 | warranties and conditions, express and implied, including 121 | warranties or conditions of title and non-infringement, and 122 | implied warranties or conditions of merchantability and fitness 123 | for a particular purpose; 124 | 125 | ii) effectively excludes on behalf of all other Contributors all 126 | liability for damages, including direct, indirect, special, 127 | incidental and consequential damages, such as lost profits; 128 | 129 | iii) does not attempt to limit or alter the recipients' rights 130 | in the Source Code under section 3.2; and 131 | 132 | iv) requires any subsequent distribution of the Program by any 133 | party to be under a license that satisfies the requirements 134 | of this section 3. 135 | 136 | 3.2 When the Program is Distributed as Source Code: 137 | 138 | a) it must be made available under this Agreement, or if the 139 | Program (i) is combined with other material in a separate file or 140 | files made available under a Secondary License, and (ii) the initial 141 | Contributor attached to the Source Code the notice described in 142 | Exhibit A of this Agreement, then the Program may be made available 143 | under the terms of such Secondary Licenses, and 144 | 145 | b) a copy of this Agreement must be included with each copy of 146 | the Program. 147 | 148 | 3.3 Contributors may not remove or alter any copyright, patent, 149 | trademark, attribution notices, disclaimers of warranty, or limitations 150 | of liability ("notices") contained within the Program from any copy of 151 | the Program which they Distribute, provided that Contributors may add 152 | their own appropriate notices. 153 | 154 | 4. COMMERCIAL DISTRIBUTION 155 | 156 | Commercial distributors of software may accept certain responsibilities 157 | with respect to end users, business partners and the like. While this 158 | license is intended to facilitate the commercial use of the Program, 159 | the Contributor who includes the Program in a commercial product 160 | offering should do so in a manner which does not create potential 161 | liability for other Contributors. Therefore, if a Contributor includes 162 | the Program in a commercial product offering, such Contributor 163 | ("Commercial Contributor") hereby agrees to defend and indemnify every 164 | other Contributor ("Indemnified Contributor") against any losses, 165 | damages and costs (collectively "Losses") arising from claims, lawsuits 166 | and other legal actions brought by a third party against the Indemnified 167 | Contributor to the extent caused by the acts or omissions of such 168 | Commercial Contributor in connection with its distribution of the Program 169 | in a commercial product offering. The obligations in this section do not 170 | apply to any claims or Losses relating to any actual or alleged 171 | intellectual property infringement. In order to qualify, an Indemnified 172 | Contributor must: a) promptly notify the Commercial Contributor in 173 | writing of such claim, and b) allow the Commercial Contributor to control, 174 | and cooperate with the Commercial Contributor in, the defense and any 175 | related settlement negotiations. The Indemnified Contributor may 176 | participate in any such claim at its own expense. 177 | 178 | For example, a Contributor might include the Program in a commercial 179 | product offering, Product X. That Contributor is then a Commercial 180 | Contributor. If that Commercial Contributor then makes performance 181 | claims, or offers warranties related to Product X, those performance 182 | claims and warranties are such Commercial Contributor's responsibility 183 | alone. Under this section, the Commercial Contributor would have to 184 | defend claims against the other Contributors related to those performance 185 | claims and warranties, and if a court requires any other Contributor to 186 | pay any damages as a result, the Commercial Contributor must pay 187 | those damages. 188 | 189 | 5. NO WARRANTY 190 | 191 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, AND TO THE EXTENT 192 | PERMITTED BY APPLICABLE LAW, THE PROGRAM IS PROVIDED ON AN "AS IS" 193 | BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR 194 | IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF 195 | TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR 196 | PURPOSE. Each Recipient is solely responsible for determining the 197 | appropriateness of using and distributing the Program and assumes all 198 | risks associated with its exercise of rights under this Agreement, 199 | including but not limited to the risks and costs of program errors, 200 | compliance with applicable laws, damage to or loss of data, programs 201 | or equipment, and unavailability or interruption of operations. 202 | 203 | 6. DISCLAIMER OF LIABILITY 204 | 205 | EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, AND TO THE EXTENT 206 | PERMITTED BY APPLICABLE LAW, NEITHER RECIPIENT NOR ANY CONTRIBUTORS 207 | SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 208 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST 209 | PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 210 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 211 | ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE 212 | EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE 213 | POSSIBILITY OF SUCH DAMAGES. 214 | 215 | 7. GENERAL 216 | 217 | If any provision of this Agreement is invalid or unenforceable under 218 | applicable law, it shall not affect the validity or enforceability of 219 | the remainder of the terms of this Agreement, and without further 220 | action by the parties hereto, such provision shall be reformed to the 221 | minimum extent necessary to make such provision valid and enforceable. 222 | 223 | If Recipient institutes patent litigation against any entity 224 | (including a cross-claim or counterclaim in a lawsuit) alleging that the 225 | Program itself (excluding combinations of the Program with other software 226 | or hardware) infringes such Recipient's patent(s), then such Recipient's 227 | rights granted under Section 2(b) shall terminate as of the date such 228 | litigation is filed. 229 | 230 | All Recipient's rights under this Agreement shall terminate if it 231 | fails to comply with any of the material terms or conditions of this 232 | Agreement and does not cure such failure in a reasonable period of 233 | time after becoming aware of such noncompliance. If all Recipient's 234 | rights under this Agreement terminate, Recipient agrees to cease use 235 | and distribution of the Program as soon as reasonably practicable. 236 | However, Recipient's obligations under this Agreement and any licenses 237 | granted by Recipient relating to the Program shall continue and survive. 238 | 239 | Everyone is permitted to copy and distribute copies of this Agreement, 240 | but in order to avoid inconsistency the Agreement is copyrighted and 241 | may only be modified in the following manner. The Agreement Steward 242 | reserves the right to publish new versions (including revisions) of 243 | this Agreement from time to time. No one other than the Agreement 244 | Steward has the right to modify this Agreement. The Eclipse Foundation 245 | is the initial Agreement Steward. The Eclipse Foundation may assign the 246 | responsibility to serve as the Agreement Steward to a suitable separate 247 | entity. Each new version of the Agreement will be given a distinguishing 248 | version number. The Program (including Contributions) may always be 249 | Distributed subject to the version of the Agreement under which it was 250 | received. In addition, after a new version of the Agreement is published, 251 | Contributor may elect to Distribute the Program (including its 252 | Contributions) under the new version. 253 | 254 | Except as expressly stated in Sections 2(a) and 2(b) above, Recipient 255 | receives no rights or licenses to the intellectual property of any 256 | Contributor under this Agreement, whether expressly, by implication, 257 | estoppel or otherwise. All rights in the Program not expressly granted 258 | under this Agreement are reserved. Nothing in this Agreement is intended 259 | to be enforceable by any entity that is not a Contributor or Recipient. 260 | No third-party beneficiary rights are created under this Agreement. 261 | 262 | Exhibit A - Form of Secondary Licenses Notice 263 | 264 | "This Source Code may also be made available under the following 265 | Secondary Licenses when the conditions for such availability set forth 266 | in the Eclipse Public License, v. 2.0 are satisfied: {name license(s), 267 | version(s), and exceptions or additional permissions here}." 268 | 269 | Simply including a copy of this Agreement, including this Exhibit A 270 | is not sufficient to license the Source Code under Secondary Licenses. 271 | 272 | If it is not possible or desirable to put the notice in a particular 273 | file, then You may include the notice in a location (such as a LICENSE 274 | file in a relevant directory) where a recipient would be likely to 275 | look for such a notice. 276 | 277 | You may add additional accurate notices of copyright ownership. 278 | --------------------------------------------------------------------------------