forked from clojure/clojure
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
254 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Copyright (c) Rich Hickey. All rights reserved. | ||
* The use and distribution terms for this software are covered by the | ||
* Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) | ||
* which can be found in the file epl-v10.html at the root of this distribution. | ||
* By using this software in any fashion, you are agreeing to be bound by | ||
* the terms of this license. | ||
* You must not remove this notice, or any other, from this software. | ||
**/ | ||
|
||
/* rich May 24, 2009 */ | ||
|
||
package clojure.lang; | ||
|
||
public class ArrayChunk implements Indexed{ | ||
|
||
final Object[] array; | ||
final int off; | ||
|
||
public ArrayChunk(Object[] array, int off){ | ||
this.array = array; | ||
this.off = off; | ||
} | ||
|
||
public Object nth(int i){ | ||
return array[off + i]; | ||
} | ||
|
||
public int count(){ | ||
return array.length - off; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* Copyright (c) Rich Hickey. All rights reserved. | ||
* The use and distribution terms for this software are covered by the | ||
* Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) | ||
* which can be found in the file epl-v10.html at the root of this distribution. | ||
* By using this software in any fashion, you are agreeing to be bound by | ||
* the terms of this license. | ||
* You must not remove this notice, or any other, from this software. | ||
**/ | ||
|
||
/* rich May 25, 2009 */ | ||
|
||
package clojure.lang; | ||
|
||
final public class ChunkedCons extends ASeq implements IChunkedSeq{ | ||
|
||
final Indexed chunk; | ||
final ISeq _more; | ||
final int offset; | ||
|
||
ChunkedCons(IPersistentMap meta, Indexed chunk, int offset, ISeq more){ | ||
super(meta); | ||
this.chunk = chunk; | ||
this.offset = offset; | ||
this._more = more; | ||
} | ||
public ChunkedCons(Indexed chunk, ISeq more){ | ||
this(chunk, 0, more); | ||
} | ||
|
||
public ChunkedCons(Indexed chunk, int offset, ISeq more){ | ||
this.chunk = chunk; | ||
this.offset = offset; | ||
this._more = more; | ||
} | ||
|
||
public Obj withMeta(IPersistentMap meta){ | ||
if(meta != _meta) | ||
return new ChunkedCons(meta, chunk, offset, _more); | ||
return this; | ||
} | ||
|
||
public Object first(){ | ||
return chunk.nth(offset); | ||
} | ||
|
||
public ISeq next(){ | ||
if(offset + 1 < chunk.count()) | ||
return new ChunkedCons(chunk, offset + 1, _more); | ||
return chunkedNext(); | ||
} | ||
|
||
public ISeq more(){ | ||
if(offset + 1 < chunk.count()) | ||
return new ChunkedCons(chunk, offset + 1, _more); | ||
if(_more == null) | ||
return PersistentList.EMPTY; | ||
return _more; | ||
} | ||
|
||
public Indexed chunkedFirst(){ | ||
return chunk; | ||
} | ||
|
||
public ISeq chunkedNext(){ | ||
return chunkedMore().seq(); | ||
} | ||
|
||
public ISeq chunkedMore(){ | ||
if(_more == null) | ||
return PersistentList.EMPTY; | ||
return _more; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Copyright (c) Rich Hickey. All rights reserved. | ||
* The use and distribution terms for this software are covered by the | ||
* Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) | ||
* which can be found in the file epl-v10.html at the root of this distribution. | ||
* By using this software in any fashion, you are agreeing to be bound by | ||
* the terms of this license. | ||
* You must not remove this notice, or any other, from this software. | ||
**/ | ||
|
||
/* rich May 24, 2009 */ | ||
|
||
package clojure.lang; | ||
|
||
public interface IChunkedSeq extends ISeq{ | ||
|
||
Indexed chunkedFirst() throws Exception; | ||
|
||
ISeq chunkedNext() throws Exception; | ||
|
||
ISeq chunkedMore() throws Exception; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Copyright (c) Rich Hickey. All rights reserved. | ||
* The use and distribution terms for this software are covered by the | ||
* Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) | ||
* which can be found in the file epl-v10.html at the root of this distribution. | ||
* By using this software in any fashion, you are agreeing to be bound by | ||
* the terms of this license. | ||
* You must not remove this notice, or any other, from this software. | ||
**/ | ||
|
||
/* rich May 24, 2009 */ | ||
|
||
package clojure.lang; | ||
|
||
public interface Indexed extends Counted{ | ||
Object nth(int i); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters