mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
vlib: rename adt
to datatypes
This commit is contained in:
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
|
||||
your actual elements. For example:
|
||||
```v
|
||||
import adt
|
||||
import datatypes
|
||||
|
||||
mut stack := adt.Stack<int>{}
|
||||
mut stack := datatypes.Stack<int>{}
|
||||
stack.push(1)
|
||||
println(stack)
|
||||
```
|
@ -1,4 +1,4 @@
|
||||
module adt
|
||||
module datatypes
|
||||
|
||||
struct DoublyListNode<T> {
|
||||
mut:
|
@ -1,4 +1,4 @@
|
||||
module adt
|
||||
module datatypes
|
||||
|
||||
fn test_is_empty() {
|
||||
mut list := DoublyLinkedList<int>{}
|
@ -1,4 +1,4 @@
|
||||
module adt
|
||||
module datatypes
|
||||
|
||||
// MinHeap is a binary minimum heap data structure.
|
||||
pub struct MinHeap<T> {
|
@ -1,4 +1,4 @@
|
||||
module adt
|
||||
module datatypes
|
||||
|
||||
fn test_min_heap() ? {
|
||||
mut heap := MinHeap<int>{}
|
@ -1,4 +1,4 @@
|
||||
module adt
|
||||
module datatypes
|
||||
|
||||
pub struct ListNode<T> {
|
||||
mut:
|
@ -1,4 +1,4 @@
|
||||
module adt
|
||||
module datatypes
|
||||
|
||||
fn test_is_empty() {
|
||||
mut list := LinkedList<int>{}
|
@ -1,4 +1,4 @@
|
||||
module adt
|
||||
module datatypes
|
||||
|
||||
pub struct Queue<T> {
|
||||
mut:
|
@ -1,4 +1,4 @@
|
||||
module adt
|
||||
module datatypes
|
||||
|
||||
fn test_is_empty() {
|
||||
mut queue := Queue<int>{}
|
@ -1,4 +1,4 @@
|
||||
module adt
|
||||
module datatypes
|
||||
|
||||
pub struct Stack<T> {
|
||||
mut:
|
@ -1,14 +1,14 @@
|
||||
import adt
|
||||
import datatypes as dt
|
||||
|
||||
fn test_is_empty() {
|
||||
mut stack := adt.Stack<int>{}
|
||||
mut stack := dt.Stack<int>{}
|
||||
assert stack.is_empty() == true
|
||||
stack.push(1)
|
||||
assert stack.is_empty() == false
|
||||
}
|
||||
|
||||
fn test_len() ? {
|
||||
mut stack := adt.Stack<int>{}
|
||||
mut stack := dt.Stack<int>{}
|
||||
assert stack.len() == 0
|
||||
stack.push(1)
|
||||
assert stack.len() == 1
|
||||
@ -17,18 +17,18 @@ fn test_len() ? {
|
||||
}
|
||||
|
||||
fn test_peek() ? {
|
||||
mut stack := adt.Stack<int>{}
|
||||
mut stack := dt.Stack<int>{}
|
||||
stack.push(1)
|
||||
assert stack.peek() ? == 1
|
||||
stack.push(2)
|
||||
assert stack.peek() ? == 2
|
||||
stack = adt.Stack<int>{}
|
||||
stack = dt.Stack<int>{}
|
||||
stack.peek() or { return }
|
||||
assert false
|
||||
}
|
||||
|
||||
fn test_push() ? {
|
||||
mut stack := adt.Stack<int>{}
|
||||
mut stack := dt.Stack<int>{}
|
||||
stack.push(1)
|
||||
assert stack.peek() ? == 1
|
||||
stack.push(2)
|
||||
@ -38,7 +38,7 @@ fn test_push() ? {
|
||||
}
|
||||
|
||||
fn test_pop() ? {
|
||||
mut stack := adt.Stack<int>{}
|
||||
mut stack := dt.Stack<int>{}
|
||||
stack.push(1)
|
||||
stack.push(2)
|
||||
stack.push(3)
|
||||
@ -46,7 +46,7 @@ fn test_pop() ? {
|
||||
stack.push(4)
|
||||
assert stack.pop() ? == 4
|
||||
assert stack.pop() ? == 2
|
||||
stack = adt.Stack<int>{}
|
||||
stack = dt.Stack<int>{}
|
||||
stack.pop() or { return }
|
||||
assert false
|
||||
}
|
Loading…
Reference in New Issue
Block a user