Skip to content

Commit

Permalink
"Inlining" nth in PersistentVector and TransientVector
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Jun 1, 2012
1 parent d9b6f45 commit 286ec23
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/FSharpx.Core/DataStructures/Vector.fs
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,6 @@ type TransientVector<'a> (count,shift:int,root:Node,tail:obj[]) =
node.Array
else raise Exceptions.OutOfBounds

member this.nth i =
this.EnsureEditable()
let node = this.ArrayFor i
node.[i &&& blockIndexMask] :?> 'a

member this.conj<'a> (x:'a) =
this.EnsureEditable()

Expand Down Expand Up @@ -226,10 +221,15 @@ type TransientVector<'a> (count,shift:int,root:Node,tail:obj[]) =
:> System.Collections.IEnumerator

interface IVector<'a> with
member this.Item with get i = this.nth i
member this.Item
with get i =
this.EnsureEditable()
let node = this.ArrayFor i
node.[i &&& blockIndexMask] :?> 'a

member this.Conj x = this.conj x :> IVector<'a>
member this.Pop() = this.pop() :> IVector<'a>
member this.Peek() = if count > 0 then this.nth(count - 1) else failwith "Can't peek empty vector"
member this.Peek() = if count > 0 then (this :> IVector<'a>).[count - 1] else failwith "Can't peek empty vector"
member this.Count() = this.EnsureEditable(); count
member this.AssocN(i,x) = this.assocN(i,x) :> IVector<'a>

Expand Down Expand Up @@ -308,10 +308,6 @@ and PersistentVector<[<EqualityConditionalOn>]'a> (count,shift:int,root:Node,tai
node.Array
else raise Exceptions.OutOfBounds

member this.nth<'a> i : 'a =
let node = this.ArrayFor i
node.[i &&& blockIndexMask] :?> 'a

member this.cons<'a> (x:'a) =
if count - tailOff < blockSize then
let newTail = Array.append tail [|x:>obj|]
Expand Down Expand Up @@ -412,11 +408,15 @@ and PersistentVector<[<EqualityConditionalOn>]'a> (count,shift:int,root:Node,tai
:> System.Collections.IEnumerator

interface IVector<'a> with
member this.Item with get i = this.nth i
member this.Item
with get i =
let node = this.ArrayFor i
node.[i &&& blockIndexMask] :?> 'a

member this.Conj x = this.cons x :> IVector<'a>
member this.Pop() = this.pop() :> IVector<'a>
member this.Count() = count
member this.Peek() = if count > 0 then this.nth(count - 1) else failwith "Can't peek empty vector"
member this.Peek() = if count > 0 then (this :> IVector<'a>).[count - 1] else failwith "Can't peek empty vector"

member this.AssocN(i,x) = this.assocN(i,x) :> IVector<'a>

Expand Down

0 comments on commit 286ec23

Please sign in to comment.