Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated to Java SVN rev 1377: first cut of chunked seq
- Loading branch information
David Miller
committed
Jun 26, 2009
1 parent
ec26584
commit f35ce2f
Showing
9 changed files
with
372 additions
and
21 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,55 @@ | ||
/** | ||
* Copyright (c) David Miller. 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. | ||
**/ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace clojure.lang | ||
{ | ||
public class ArrayChunk : Indexed | ||
{ | ||
#region Data | ||
|
||
readonly object[] _array; | ||
readonly int _off; | ||
|
||
#endregion | ||
|
||
#region C-tors | ||
|
||
public ArrayChunk(object[] array, int off) | ||
{ | ||
_array = array; | ||
_off = off; | ||
} | ||
|
||
#endregion | ||
|
||
#region Indexed Members | ||
|
||
public object nth(int i) | ||
{ | ||
return _array[_off + i]; | ||
} | ||
|
||
#endregion | ||
|
||
#region Counted Members | ||
|
||
public int count() | ||
{ | ||
return _array.Length - _off; | ||
} | ||
|
||
#endregion | ||
} | ||
} |
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,110 @@ | ||
/** | ||
* Copyright (c) David Miller. 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. | ||
**/ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace clojure.lang | ||
{ | ||
public class ChunkedCons : ASeq, IChunkedSeq | ||
{ | ||
#region Data | ||
|
||
readonly Indexed _chunk; | ||
readonly ISeq _more; | ||
readonly int _offset; | ||
|
||
#endregion | ||
|
||
#region C-tors | ||
|
||
ChunkedCons(IPersistentMap meta, Indexed chunk, int offset, ISeq more) | ||
: base(meta) | ||
{ | ||
_chunk = chunk; | ||
_offset = offset; | ||
_more = more; | ||
} | ||
|
||
public ChunkedCons(Indexed chunk, ISeq more) | ||
: this(chunk, 0, more) | ||
{ | ||
} | ||
|
||
public ChunkedCons(Indexed chunk, int offset, ISeq more) | ||
{ | ||
_chunk = chunk; | ||
_offset = offset; | ||
_more = more; | ||
} | ||
|
||
#endregion | ||
|
||
#region IObj methods | ||
|
||
public override IObj withMeta(IPersistentMap meta) | ||
{ | ||
return (meta == _meta) | ||
? this | ||
:new ChunkedCons(meta, _chunk, _offset, _more); | ||
} | ||
|
||
#endregion | ||
|
||
#region ISeq methods | ||
|
||
public override object first() | ||
{ | ||
return _chunk.nth(_offset); | ||
} | ||
|
||
public override ISeq next() | ||
{ | ||
if (_offset + 1 < _chunk.count()) | ||
return new ChunkedCons(_chunk, _offset + 1, _more); | ||
return chunkedNext(); | ||
} | ||
|
||
#endregion | ||
|
||
#region IChunkedSeq Members | ||
|
||
public Indexed chunkedFirst() | ||
{ | ||
return _chunk; | ||
} | ||
|
||
public ISeq chunkedNext() | ||
{ | ||
return chunkedMore().seq(); | ||
} | ||
|
||
public ISeq chunkedMore() | ||
{ | ||
if (_more == null) | ||
return PersistentList.EMPTY; | ||
return _more; | ||
} | ||
|
||
#endregion | ||
|
||
#region IPersistentCollection Members | ||
|
||
|
||
//public new IPersistentCollection cons(object o) | ||
//{ | ||
// throw new NotImplementedException(); | ||
//} | ||
|
||
#endregion | ||
} | ||
} |
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,24 @@ | ||
/** | ||
* Copyright (c) David Miller. 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. | ||
**/ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace clojure.lang | ||
{ | ||
public interface IChunkedSeq : ISeq | ||
{ | ||
Indexed chunkedFirst(); | ||
ISeq chunkedNext(); | ||
ISeq chunkedMore(); | ||
} | ||
} |
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,27 @@ | ||
/** | ||
* Copyright (c) David Miller. 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. | ||
**/ | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace clojure.lang | ||
{ | ||
public interface Indexed : Counted | ||
{ | ||
/// <summary> | ||
/// Returns the n-th item. | ||
/// </summary> | ||
/// <param name="i">Index of the item to access</param> | ||
/// <returns>The item at the given index</returns> | ||
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
Oops, something went wrong.