vlib: rename `adt` to `datatypes`
parent
2210f89ea3
commit
8a10dbcf27
|
@ -12,9 +12,9 @@ be more suitable for your specific application.
|
||||||
It is implemented using generics, that you have to specialise for the type of
|
It is implemented using generics, that you have to specialise for the type of
|
||||||
your actual elements. For example:
|
your actual elements. For example:
|
||||||
```v
|
```v
|
||||||
import adt
|
import datatypes
|
||||||
|
|
||||||
mut stack := adt.Stack<int>{}
|
mut stack := datatypes.Stack<int>{}
|
||||||
stack.push(1)
|
stack.push(1)
|
||||||
println(stack)
|
println(stack)
|
||||||
```
|
```
|
|
@ -1,4 +1,4 @@
|
||||||
module adt
|
module datatypes
|
||||||
|
|
||||||
struct DoublyListNode<T> {
|
struct DoublyListNode<T> {
|
||||||
mut:
|
mut:
|
|
@ -1,4 +1,4 @@
|
||||||
module adt
|
module datatypes
|
||||||
|
|
||||||
fn test_is_empty() {
|
fn test_is_empty() {
|
||||||
mut list := DoublyLinkedList<int>{}
|
mut list := DoublyLinkedList<int>{}
|
|
@ -1,4 +1,4 @@
|
||||||
module adt
|
module datatypes
|
||||||
|
|
||||||
// MinHeap is a binary minimum heap data structure.
|
// MinHeap is a binary minimum heap data structure.
|
||||||
pub struct MinHeap<T> {
|
pub struct MinHeap<T> {
|
|
@ -1,4 +1,4 @@
|
||||||
module adt
|
module datatypes
|
||||||
|
|
||||||
fn test_min_heap() ? {
|
fn test_min_heap() ? {
|
||||||
mut heap := MinHeap<int>{}
|
mut heap := MinHeap<int>{}
|
|
@ -1,4 +1,4 @@
|
||||||
module adt
|
module datatypes
|
||||||
|
|
||||||
pub struct ListNode<T> {
|
pub struct ListNode<T> {
|
||||||
mut:
|
mut:
|
|
@ -1,4 +1,4 @@
|
||||||
module adt
|
module datatypes
|
||||||
|
|
||||||
fn test_is_empty() {
|
fn test_is_empty() {
|
||||||
mut list := LinkedList<int>{}
|
mut list := LinkedList<int>{}
|
|
@ -1,4 +1,4 @@
|
||||||
module adt
|
module datatypes
|
||||||
|
|
||||||
pub struct Queue<T> {
|
pub struct Queue<T> {
|
||||||
mut:
|
mut:
|
|
@ -1,4 +1,4 @@
|
||||||
module adt
|
module datatypes
|
||||||
|
|
||||||
fn test_is_empty() {
|
fn test_is_empty() {
|
||||||
mut queue := Queue<int>{}
|
mut queue := Queue<int>{}
|
|
@ -1,4 +1,4 @@
|
||||||
module adt
|
module datatypes
|
||||||
|
|
||||||
pub struct Stack<T> {
|
pub struct Stack<T> {
|
||||||
mut:
|
mut:
|
|
@ -1,14 +1,14 @@
|
||||||
import adt
|
import datatypes as dt
|
||||||
|
|
||||||
fn test_is_empty() {
|
fn test_is_empty() {
|
||||||
mut stack := adt.Stack<int>{}
|
mut stack := dt.Stack<int>{}
|
||||||
assert stack.is_empty() == true
|
assert stack.is_empty() == true
|
||||||
stack.push(1)
|
stack.push(1)
|
||||||
assert stack.is_empty() == false
|
assert stack.is_empty() == false
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_len() ? {
|
fn test_len() ? {
|
||||||
mut stack := adt.Stack<int>{}
|
mut stack := dt.Stack<int>{}
|
||||||
assert stack.len() == 0
|
assert stack.len() == 0
|
||||||
stack.push(1)
|
stack.push(1)
|
||||||
assert stack.len() == 1
|
assert stack.len() == 1
|
||||||
|
@ -17,18 +17,18 @@ fn test_len() ? {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_peek() ? {
|
fn test_peek() ? {
|
||||||
mut stack := adt.Stack<int>{}
|
mut stack := dt.Stack<int>{}
|
||||||
stack.push(1)
|
stack.push(1)
|
||||||
assert stack.peek() ? == 1
|
assert stack.peek() ? == 1
|
||||||
stack.push(2)
|
stack.push(2)
|
||||||
assert stack.peek() ? == 2
|
assert stack.peek() ? == 2
|
||||||
stack = adt.Stack<int>{}
|
stack = dt.Stack<int>{}
|
||||||
stack.peek() or { return }
|
stack.peek() or { return }
|
||||||
assert false
|
assert false
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_push() ? {
|
fn test_push() ? {
|
||||||
mut stack := adt.Stack<int>{}
|
mut stack := dt.Stack<int>{}
|
||||||
stack.push(1)
|
stack.push(1)
|
||||||
assert stack.peek() ? == 1
|
assert stack.peek() ? == 1
|
||||||
stack.push(2)
|
stack.push(2)
|
||||||
|
@ -38,7 +38,7 @@ fn test_push() ? {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_pop() ? {
|
fn test_pop() ? {
|
||||||
mut stack := adt.Stack<int>{}
|
mut stack := dt.Stack<int>{}
|
||||||
stack.push(1)
|
stack.push(1)
|
||||||
stack.push(2)
|
stack.push(2)
|
||||||
stack.push(3)
|
stack.push(3)
|
||||||
|
@ -46,7 +46,7 @@ fn test_pop() ? {
|
||||||
stack.push(4)
|
stack.push(4)
|
||||||
assert stack.pop() ? == 4
|
assert stack.pop() ? == 4
|
||||||
assert stack.pop() ? == 2
|
assert stack.pop() ? == 2
|
||||||
stack = adt.Stack<int>{}
|
stack = dt.Stack<int>{}
|
||||||
stack.pop() or { return }
|
stack.pop() or { return }
|
||||||
assert false
|
assert false
|
||||||
}
|
}
|
Loading…
Reference in New Issue