10 examples of 'golang queue' in Go

Every line of 'golang queue' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Go code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
120func main() {
121 fmt.Println(coinChange([]int{5}, 5))
122 fmt.Println(coinChange([]int{1, 2, 5}, 11))
123 fmt.Println(coinChange([]int{2}, 3))
124 fmt.Println(coinChange([]int{1, 7, 11, 13, 17}, 152))
125 fmt.Println(coinChange([]int{70, 177, 394, 428, 427, 437, 176, 145, 83, 370}, 7582))
126 fmt.Println("-----")
127
128 fmt.Println(coinChange1([]int{5}, 5))
129 fmt.Println(coinChange1([]int{1, 2, 5}, 11))
130 fmt.Println(coinChange1([]int{2}, 3))
131 fmt.Println(coinChange1([]int{1, 7, 11, 13, 17}, 152))
132 fmt.Println(coinChange([]int{70, 177, 394, 428, 427, 437, 176, 145, 83, 370}, 7582))
133 fmt.Println("-----")
134
135 fmt.Println(coinChange2([]int{5}, 5))
136 fmt.Println(coinChange2([]int{1, 2, 5}, 11))
137 fmt.Println(coinChange2([]int{2}, 3))
138 fmt.Println(coinChange2([]int{1, 7, 11, 13, 17}, 152))
139 fmt.Println(coinChange([]int{70, 177, 394, 428, 427, 437, 176, 145, 83, 370}, 7582))
140}
45func (h *Syncer) Queue(url Url, out chan Url) {
46 out <- url
47}
25func (mq *RedisMessageQueue) Custome(queuename string, cb func(message string) error) error {
26 go func() {
27 for {
28 message, err := RedisClient.BRPop(0, queuename).Result()
29
30 if err != nil {
31 log.Fatal(err)
32 }
33
34 err = cb(message[1])
35
36 if err != nil {
37 log.Printf("Execute Callback func Error: %s", err)
38 }
39 }
40 }()
41
42 return nil
43}
87func (d DefaultProxyWAMSHost) ProxyDequeueSharedQueue(queueID uint32, returnValueData **byte, returnValueSize *int) types.Status {
88 return 0
89}
13func queue() cli.Command {
14
15 keyTypeFlag := cli.StringFlag{
16 Name: "key",
17 Usage: "type that will be held in the queue",
18 }
19
20 return cli.Command{
21 Name: "queue",
22 ShortName: "q",
23 Usage: "Create a queue (list) customized for your types.",
24 Description: `Create a queue customized for your types. The implementation
25is based on a ring buffer, which has good performance and is well tested.
26(the tests are not generated with the custom type)`,
27 Flags: []cli.Flag{keyTypeFlag},
28 Action: func(ctx *cli.Context) {
29 ktype := valOrDefault(ctx, keyTypeFlag)
30
31 kname := ktype
32 if len(kname) > 1 && []byte(kname)[0] == '*' {
33 kname = kname[1:]
34 }
35 if len(kname) > 2 && kname[:2] == "[]" {
36 kname = strings.Title(kname[2:]) + "s"
37 }
38
39 typeName := fmt.Sprintf("%sQueue", strings.Title(kname))
40
41 cwd, _ := os.Getwd()
42 pkgname := fmt.Sprintf("package %s", filepath.Base(cwd))
43
44 src := []byte(queueSrc)
45 src = bytes.Replace(src, []byte("package queue"), []byte(pkgname), 1)
46
47 src = bytes.Replace(src, []byte("// GENERATED CODE!!!"), []byte(generatedCodeComment()), 1)
48
49 src = bytes.Replace(src, []byte("nilKType"), []byte("nil"+kname), -1) // before KType's replace
50 src = bytes.Replace(src, []byte("KType"), []byte(ktype), -1)
51 src = bytes.Replace(src, []byte("Queue"), []byte(typeName), -1)
52
53 fmt.Println(string(src))
54 },
55 }
56}
13func queueTest() {
14 size := 2000
15 var q queue.IQueue = queue.NewQueue(size) //数组实现队列
16 //var q queue.IQueue = queue.NewQueueLink() //链表实现队列
17 for i := 0; i < size; i++ {
18 q.Enqueue(i)
19 }
20 if q.Len() != size {
21 fmt.Println("queue len error")
22 }
23 if q.Cap() != size {
24 fmt.Println("queue cap error,cap=", q.Cap())
25 }
26 value, isOK := q.Peek()
27 if isOK {
28 if value.(int) != 0 {
29 fmt.Println("queue peek error")
30 }
31 }
32
33 for i := 0; i < size; i++ {
34 q.Enqueue(i)
35 }
36 if q.Cap() != size*2 {
37 fmt.Println("queue cap error,cap=", q.Cap())
38 }
39 count := q.Len()
40 index := 0
41 for !q.Empty() {
42 q.Dequeue()
43 index++
44 }
45 if count != index {
46 fmt.Println(fmt.Sprintf("len = %v != count = %v", index, count))
47 }
48 for i := 0; i < size*8; i++ {
49 q.Enqueue(i)
50 }
51 if q.Cap() != size*8 {
52 fmt.Println(fmt.Sprintf("queue cap error,cap=%v,want cap=%v", q.Cap(), size*8))
53 }
54}
7func main() {
8 s := NewStack()
9 s.Enqueue("a")
10 s.Enqueue("b")
11 fmt.Println(s.Dequeue() == "b")
12 fmt.Println(s.IsEmpty() == false)
13 fmt.Println(s.Dequeue() == "a")
14 fmt.Println(s.IsEmpty() == true)
15}
54func (p *Proto) Queue() string {
55 return p.Value(QueueStr)
56}
354func (c *taskQueueClient) Dequeue(ctx context.Context, in *DequeueRequest, opts ...grpc.CallOption) (*TaskMessage, error) {
355 out := new(TaskMessage)
356 err := c.cc.Invoke(ctx, "/pb.TaskQueue/Dequeue", in, out, opts...)
357 if err != nil {
358 return nil, err
359 }
360 return out, nil
361}
57func (store *LeveldbStore) TaskEnqueue(url []byte) {
58 log.Info("task enqueue:", string(url))
59}

Related snippets