Browse Source

Merge pull request #1828 from JungerBoyo/patch-2

front() and back()
gingerBill 3 years ago
parent
commit
79eb7b52d9
1 changed files with 10 additions and 0 deletions
  1. 10 0
      core/container/queue/queue.odin

+ 10 - 0
core/container/queue/queue.odin

@@ -69,6 +69,16 @@ get :: proc(q: ^$Q/Queue($T), #any_int i: int, loc := #caller_location) -> T {
 	idx := (uint(i)+q.offset)%builtin.len(q.data)
 	return q.data[idx]
 }
+
+front :: proc(q: ^$Q/Queue($T)) -> T {
+	return q.data[q.offset]
+}
+
+back :: proc(q: ^$Q/Queue($T)) -> T {
+	idx := (q.offset+uint(q.len))%builtin.len(q.data)
+	return q.data[idx]
+}
+
 set :: proc(q: ^$Q/Queue($T), #any_int i: int, val: T, loc := #caller_location) {
 	runtime.bounds_check_error_loc(loc, i, builtin.len(q.data))