Przeglądaj źródła

Small edits, added comparison to other queues.

Peter H. Froehlich 8 lat temu
rodzic
commit
05d844b62b
2 zmienionych plików z 24 dodań i 2 usunięć
  1. 22 0
      README.md
  2. 2 2
      queue/queue.go

+ 22 - 0
README.md

@@ -8,6 +8,7 @@ All operations are (amortized) constant time.
 Benchmarks compare favorably to
 [container/list](https://golang.org/pkg/container/list/) as
 well as to Go's channels.
+Not safe for concurrent use.
 
 I tried to stick to the conventions established by
 [container/list](https://golang.org/pkg/container/list/)
@@ -297,3 +298,24 @@ an evening. Kudos to...
 
 If you find something in my code that helps you improve yours, feel
 free to run with it!
+
+## Why use this queue over...
+
+- Your own? Well, I spent a reasonable amount of time on this one, making
+  sure that it works well as a general-purpose queue data structure. But
+  go ahead, you can probably do better.
+- https://github.com/eapache/queue is not double-ended, panics unlike the
+  standard library, has a "strange" `get` that's not really a queue
+  operation
+- https://gist.github.com/moraes/2141121 is not double-ended, doesn't
+  shrink to free up memory, uses an "extra" `Node` type
+- https://github.com/ErikDubbelboer/ringqueue/ is not double-ended
+  seems to shrink too early if I am reading the code correctly, uses
+  `%` instead of `&` which (sadly) still seems to make a difference
+- https://github.com/Workiva/go-datastructures/tree/master/queue is full
+  of semi-arcane concurrency stuff that a simple data structure doesn't
+  need
+- https://github.com/oleiade/lane uses
+  [container/list](https://golang.org/pkg/container/list/) and thus has
+  the same performance problems, has a bunch of concurrency stuff that
+  a simple data structure doesn't need

+ 2 - 2
queue/queue.go

@@ -6,6 +6,7 @@
 // of a slice. All operations are (amortized) constant time.
 // Benchmarks compare favorably to container/list as well as to Go's
 // channels.
+// Not safe for concurrent use.
 package queue
 
 import (
@@ -18,8 +19,7 @@ import (
 type Queue struct {
 	// PushBack writes to rep[back] and then increments
 	// back; PushFront decrements front and then writes
-	// to rep[front]; len(rep) must be a power of two;
-	// gotta love those invariants.
+	// to rep[front]; len(rep) must be a power of two.
 	rep    []interface{}
 	front  int
 	back   int