Skip to content

Commit

Permalink
Merge branch 'main' into tri
Browse files Browse the repository at this point in the history
  • Loading branch information
Lampese authored Mar 26, 2024
2 parents f30ef88 + 6b95f92 commit de62205
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 22 deletions.
28 changes: 6 additions & 22 deletions queue/queue.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

struct Cont[T] {
content : T
mut next : Cell[T]
}

enum Cell[T] {
Nil
Cons(Cont[T])
}

struct Queue[T] {
mut length : Int
mut first : Cell[T]
mut last : Cell[T]
}

/// Creates a new empty queue.
///
/// # Example
Expand Down Expand Up @@ -64,15 +48,15 @@ pub fn Queue::from_array[T](arr : Array[T]) -> Queue[T] {
}

/// Tests if two queue cells are equal.
pub fn op_equal[T : Eq](self : Cell[T], other : Cell[T]) -> Bool {
fn op_equal[T : Eq](self : Cell[T], other : Cell[T]) -> Bool {
loop self, other {
Nil, Nil => true
Cons({ content: x, next: xs }), Cons({ content: y, next: ys }) => {
if x != y {
break false
Cons({ content: x, next: xs }), Cons({ content: y, next: ys }) =>
if x == y {
continue xs, ys
} else {
false
}
continue xs, ys
}
_, _ => false
}
}
Expand Down
29 changes: 29 additions & 0 deletions queue/types.mbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2024 International Digital Economy Academy
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

priv struct Cont[T] {
content : T
mut next : Cell[T]
}

priv enum Cell[T] {
Nil
Cons(Cont[T])
}

struct Queue[T] {
mut length : Int
mut first : Cell[T]
mut last : Cell[T]
}

0 comments on commit de62205

Please sign in to comment.