Skip to content

Commit

Permalink
Made stdLibs a folder instead of a zip file to reduce curse wait times
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredlll08 committed Nov 2, 2019
1 parent bc74746 commit f351b22
Show file tree
Hide file tree
Showing 65 changed files with 2,090 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ZenCode
Submodule ZenCode updated from cb2950 to 1f4b12
Binary file removed src/main/resources/StdLibs.zip
Binary file not shown.
4 changes: 4 additions & 0 deletions src/main/resources/StdLibs/collections/module.json
@@ -0,0 +1,4 @@
{
"package": "collections",
"host": "universal"
}
11 changes: 11 additions & 0 deletions src/main/resources/StdLibs/collections/src/HashSet.zs
@@ -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);
}
}
68 changes: 68 additions & 0 deletions src/main/resources/StdLibs/collections/src/LinkedList.zs
@@ -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;
}
}
}
@@ -0,0 +1,5 @@
public class NoSuchElementException : Exception {
public this(message as string) {
super(message);
}
}
7 changes: 7 additions & 0 deletions src/main/resources/StdLibs/collections/src/Queue.zs
@@ -0,0 +1,7 @@
public interface Queue<T> {
get empty as bool;

poll() as T;
peek() as T;
push(value as T) as void;
}
12 changes: 12 additions & 0 deletions src/main/resources/StdLibs/collections/src/Set.zs
@@ -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);
}
16 changes: 16 additions & 0 deletions src/main/resources/StdLibs/collections/src/Stack.zs
@@ -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;
}
6 changes: 6 additions & 0 deletions src/main/resources/StdLibs/compactio/module.json
@@ -0,0 +1,6 @@
{
"package": "compactio",
"javaPackage": "org.openzen.zencode.stdlib.compactio",
"host": "universal",
"dependencies": ["io"]
}

0 comments on commit f351b22

Please sign in to comment.