Home > ngl

ngl

Ngl is a project mainly written in Scala, it's free.

Scala Port of STL Algorithms

ngl 0.1.0

ngl(Nonstandard Generics Library) ports C++ STL algorithms to Scala. The implementation is mainly based upon STLport:

val numbers = Array(5, 2, 4, 3, 1, 6)
ngl.partial_sort(numbers, 0, 3, 6)
assert(java.util.Arrays.equals(numbers, Array(1, 2, 3, 5, 4, 6)))

Concepts

Following JVM memory management, ngl doesn't port STL iterators. Instead ngl algorithms traverse the Range which corresponds to a pair of random-access-iterators.

Range

Range is a triple represented by (ngl.Seq[A], Int, Int).

OutputRange

OutputRange is a pair represented by (ngl.Seq[A], Int).

These concepts don't appear as Scala types; for maximum efficiency.

Seq Synopsis

ngl.Seq is a trivial array interface:

trait Seq[A] {
    def begin: Int
    def end: Int
    def apply(i: Int): A
    def update(i: Int, x: A): Unit
}

Seq doesn't always guarantee indices in [0, length-of-Seq). You must call begin and end in polymorphic methods.

Signature

For example, STL contains the copy function:

template<class Iterator, class OutputIterator>
Iterator copy(Iterator first, Iterator last, OutputIterator result);

In ngl it is declared as:

def copy[A](in: Seq[A], first: Int, last: Int)(out: Seq[_ >: A], result: Int): Int

Setup Dependencies for sbt

Append this in your project definition:

val ngl = "com.github.okomok" %% "ngl" % "0.1.0"
val okomok = "okomok" at "http://okomok.github.com/maven-repo/releases"

Links

  • STLport
  • Browse Source
  • Browse Test Source
  • The Scala Programming Language

Shunsuke Sogame <[email protected]>

Previous:magit-tutorial