Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Made stdLibs a folder instead of a zip file to reduce curse wait times
- Loading branch information
1 parent
bc74746
commit f351b22
Showing
65 changed files
with
2,090 additions
and
1 deletion.
There are no files selected for viewing
Binary file not shown.
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,4 @@ | ||
{ | ||
"package": "collections", | ||
"host": "universal" | ||
} |
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,11 @@ | ||
public class HashSet<T> { | ||
public implements Set<T> { | ||
add(value as T) as bool; | ||
remove(value as T) as bool; | ||
|
||
get size as usize; | ||
|
||
in(value as T) as bool; | ||
for(x as T); | ||
} | ||
} |
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,68 @@ | ||
public class LinkedList<T> { | ||
var first as Node?; | ||
var last as Node?; | ||
var size as usize : get; | ||
|
||
public get isEmpty as bool | ||
=> first == null; | ||
|
||
public add(value as T) as void { | ||
if first == null { | ||
first = last = new Node(value); | ||
} else { | ||
val node = new Node(value); | ||
last.next = node; | ||
node.prev = last; | ||
last = node; | ||
} | ||
size++; | ||
} | ||
|
||
public clear() as void { | ||
first = last = null; | ||
size = 0; | ||
} | ||
|
||
[Precondition(ENFORCE, index < size, "Index out of bounds")] | ||
public [](index as usize) as T { | ||
var node = first; | ||
while index > 0 && node != null | ||
node = node.next; | ||
|
||
if node == null | ||
panic "index out of bounds"; | ||
|
||
return node.value; | ||
} | ||
|
||
public implements Queue<T> { | ||
[Precondition(ENFORCE, first != null, "Cannot poll an empty queue")] | ||
poll() as T { | ||
val result = first.value; | ||
first = first.next; | ||
if first == null | ||
last = null; | ||
else | ||
first.prev = null; | ||
|
||
size--; | ||
} | ||
|
||
peek() as T? { | ||
return first == null ? null : first.value; | ||
} | ||
|
||
offer(value as T) as void | ||
=> add(value); | ||
} | ||
|
||
private struct Node { | ||
var next as Node?; | ||
var prev as Node?; | ||
val value as T; | ||
|
||
this(value as T) { | ||
this.value = value; | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/resources/StdLibs/collections/src/NoSuchElementException.zs
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,5 @@ | ||
public class NoSuchElementException : Exception { | ||
public this(message as string) { | ||
super(message); | ||
} | ||
} |
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,7 @@ | ||
public interface Queue<T> { | ||
get empty as bool; | ||
|
||
poll() as T; | ||
peek() as T; | ||
push(value as T) as void; | ||
} |
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,12 @@ | ||
public interface Set<T> { | ||
add(value as T) as bool; | ||
remove(value as T) as bool; | ||
|
||
get size as usize; | ||
|
||
toArray(); | ||
toArray(comparator as function(a as T, b as T) as int); | ||
|
||
in(value as T) as bool; | ||
for(x as T); | ||
} |
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,16 @@ | ||
public class Stack<T> { | ||
var values as List<T> = new List<T>(); | ||
|
||
public push(value as T) as void | ||
=> values.add(value); | ||
|
||
public get size as usize | ||
=> values.length; | ||
|
||
[Precondition(ENFORCE, size > 0, "Cannot pop an empty stack")] | ||
public pop() as T | ||
=> values.remove(values.length - 1); | ||
|
||
public get isEmpty as bool | ||
=> values.isEmpty; | ||
} |
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,6 @@ | ||
{ | ||
"package": "compactio", | ||
"javaPackage": "org.openzen.zencode.stdlib.compactio", | ||
"host": "universal", | ||
"dependencies": ["io"] | ||
} |
Oops, something went wrong.