SlideShare a Scribd company logo
Go Containers
January 23, 2014 

John Graham-Cumming

www.cloudflare.com!
Six interesting containers
•  From pkg/container!
•  container/list!
•  container/ring!
•  container/heap

!
•  Built in
•  map!
•  slice
•  Channels as queues

www.cloudflare.com!
container/list!
•  Doubly-linked list implementation
•  Uses interface{} for values
l := list.New()!
e0 := l.PushBack(42)!
e1 := l.PushFront(13)!
Pity	
  there’s	
  no	
  ‘map’	
  
e2 := l.PushBack(7)!
func4on	
  
l.InsertBefore(3, e0)!
l.InsertAfter(196, e1)!
l.InsertAfter(1729, e2)!
!
for e := l.Front(); e != nil; e = e.Next() {!
fmt.Printf("%d ", e.Value.(int))!
}!
e.Value	
  to	
  get	
  the	
  
fmt.Printf("n")!
stored	
  value	
  
!
!
13 196 3 42 7 1729!
www.cloudflare.com!
container/list!

All	
  work	
  on	
  
elements	
  not	
  values	
  	
  

l.MoveToFront(e2)!
l.MoveToBack(e1)!
Returns	
  the	
  value	
  
l.Remove(e0)!
removed	
  
!
for e := l.Front(); e != nil; e = e.Next() {!
fmt.Printf("%d ", e.Value.(int))!
}!
fmt.Printf("n")!
!
!
7 196 3 1729 13!

www.cloudflare.com!
container/ring!
•  A circular ‘list’
parus := []string{”major", “holsti”, “carpi”}!
!
r := ring.New(len(parus))!
for i := 0; i < r.Len(); i++ {!
r.Value = parus[i]!
r = r.Next()!
}!
!
r.Do(func(x interface{}) {!
fmt.Printf(“Parus %sn”, x.(string))!
})!

•  Move n elements through ring
r.Move(n)!

www.cloudflare.com!
container/heap!
•  Implements a “min-heap” (i.e. tree where each node is

the “minimum” element in its subtree)

•  Needs a notion of “Less” and a way to “Swap”
www.cloudflare.com!
container/heap!
•  The single most confusing definition in all of Go
type Interface interface {!
sort.Interface!
Push(x interface{}) // add x as element Len()!
Pop() interface{}
// remove/return element Len()-1!
}!
!
// Note that Push and Pop in this interface are for !
// package heap's implementation to call. To add and !
// remove things from the heap, use heap.Push and!
// heap.Pop.!

www.cloudflare.com!
container/heap!
•  Simple example
type OrderedInts []int!
!
func (h OrderedInts) Len() int { return len(h) }!
func (h OrderedInts) Less(i, j int) bool {!
return h[i] < h[j]!
}!
func (h OrderedInts) Swap(i,j int) {h[i],h[j]=h[j],h[i]}!
func (h *OrderedInts) Push(x interface{}) {!
!*h = append(*h, x.(int))!
}!
func (h *OrderedInts) Pop() interface{} {!
!old := *h!
!n := len(old)-1!
!x := old[n]!
!*h = old[:n]!
!return x!
}!
www.cloudflare.com!
container/heap!
•  Using a heap
h := &OrderedInts{33,76,55,24,48,63,86,83,83,12}!
!
heap.Init(h)!
!
fmt.Printf("min: %dn", (*h)[0])!
!
for h.Len() > 0 {!
fmt.Printf("%d ", heap.Pop(h))!
}!
!
fmt.Printf(“n”)!

www.cloudflare.com!
container/heap!
•  Heaps are useful for...
•  Make a priority queue
•  Sorting
•  Graph algorithms

www.cloudflare.com!
MAP

www.cloudflare.com!
map!
•  Maps are typed



dictionary := make(map[string]string)!
dictionary := map[string]string{}!
!

•  They are not concurrency safe
•  Use a lock or channel for concurrent read/write access
counts := struct{!
sync.RWMutex!
m map[string]int!
}{m: make(map[string]int)}!
!
counts.RLock()!
fmt.Printf(“foo count”, counts.m[“foo”]!
counts.RUnlock()!
!
counts.Lock()!
counts.m[“foo”] += num_foos!
counts.Unlock()!
!
www.cloudflare.com!

Mul4ple	
  readers,	
  
one	
  writer	
  
map iteration
m := map[string]int{!
"bar”: 54,!
"foo”: 42,!
"baz”: -1,!
}!
!
for k := range m {!
// k is foo, bar, baz!
}!
!
for _, v := range m {!
// v is 54, 42, -1 in some order!
}!
!
for k, v := range m {!
// k and v are as above!
}!

www.cloudflare.com!

Order	
  of	
  itera4on	
  is	
  
undefined	
  	
  
Common map operations
•  Remove an element
delete(dictionary, “twerking”)!

•  Test presence of an element
definition, present := dictionary[“hoopy”]!
!
_, present := dictionary[“sigil”]!

•  Missing element gives a “zero” value




fmt.Printf(“[%s]n”, dictionary[“ewyfgwyegfweygf”])!
!
[]!

www.cloudflare.com!
SLICE

www.cloudflare.com!
Slices
•  A slice is part of an array
var arrayOfInts [256]int!
!
var part []int = arrayOfInts[2:6]!

•  arrayOfInts is 256 ints contiguously in memory
0	
  

1	
  

2	
  

3	
  

4	
  

5	
  

6	
  

7	
  

8	
  

9	
  

10	
  

11	
  

12	
  

!
!
•  part consists of a pointer (to arrayOfInts[2]) and a
length (4)

www.cloudflare.com!
Slice passing
•  A slice is passed (like everything else) by copy
var arrayOfInts [256]int!
!
var part []int = arrayOfInts[2:6]!
!
func fill(s []int) {!
for i, _ := range s {!
s[i] = i*2!
}!
!
s = s[1:]!
}!
Does	
  nothing	
  to	
  
!
part!
fill(part)!
fmt.Printf(“%#v”, part)!
!
% ./slice!
[]int{0, 2, 4, 6}!
www.cloudflare.com!

Contents	
  of	
  s	
  can	
  be	
  
modified	
  

Changes	
  contents	
  of	
  
underlying	
  array	
  
Slice passing, part 2
•  Can pass a pointer to a slice to modify the slice
var arrayOfInts [256]int!
!
var part intSlice = arrayOfInts[2:6] !
!
Contents	
  of	
  s	
  can	
  be	
  
type intSlice []int!
modified	
  and	
  s	
  can	
  
func (s *intSlice) fill() {!
be	
  changed	
  
for i, _ := range *s {!
(*s)[i] = i*2!
}!
*s = (*s)[1:]!
Changes	
  part!
}!
!
part.fill()!
fmt.Printf("%#vn", part)!
!
% ./slice!
[]int{2, 4, 6}!
www.cloudflare.com!
Slice iteration
prime := []int{2, 3, 5, 7, 11}!
!
for i := range prime {!
// i is 0, 1, 2, 3, 4!
}!
!
for _, e := range prime{!
// e is 2, 3, 5, 7, 11!
}!
!
for i, e := range prime {!
// i and e as above!
}!

www.cloudflare.com!
Copying slices
•  copy builtin
morePrimes := make([]int, len(primes), 2*cap(primes))!
!
copy(morePrimes, primes)!

•  copy allows source and destination to overlap
primes := [10]int{2, 3, 5, 7, 11, 13, 17, 19, 23, 29}!
odds := primes[1:7]!
!
odds = odds[0:len(odds)+1]!
copy(odds[4:], odds[3:])!
odds[3] = 9!
fmt.Printf("%#vn", odds)!
!
[]int{3, 5, 7, 9, 11, 13, 17}!

www.cloudflare.com!
Appending slices
s := []int{1, 3, 6, 10}!
t := []int{36, 45, 55, 66, 78}!
!
s = append(s, 15)!
Adding	
  individual	
  
elements	
  
s = append(s, 21, 28)!
!
s = append(s, t...)!
!
Adding	
  an	
  en4re	
  
nu := append([]int(nil), s...)!
slice	
  
!
s = append(s, s...)!
Copying	
  a	
  slice	
  (use	
  
!
copy	
  instead)	
  
fmt.Printf(“%#vn”, s)!
!
[]int{1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 1, 3,
6, 10, 15, 21, 28, 36, 45, 55, 66, 78}!

www.cloudflare.com!
CHANNELS AS QUEUES

www.cloudflare.com!
A buffered channel is a FIFO queue 
•  A typed queue of up to 10 Things



queue := make(chan Thing, 10)

!

•  Get the next element from the queue if there is one



select {!
case t := <-queue: // got one!
default:
// queue is empty!
}
!

•  Add to queue if there’s room
select {!
case queue <- t: // added to queue!
default:
// queue is full!
}!

www.cloudflare.com!
GENERICS

www.cloudflare.com!
Perhaps heretical
•  But... I wish Go had some generics
•  interface{} is like void *; Type assertions similar to casts
l := list.New()!
l.PushFront("Hello, World!")!
v := l.Front()!
i := v.Value.(int)!
% go build l.go!
% ./l!
panic: interface conversion: interface is
string, not int!
!
goroutine 1 [running]:!
runtime.panic(0x49bdc0, 0xc210041000)!
!/extra/go/src/pkg/runtime/panic.c:266
+0xb6!
main.main()!
!/extra/src/mc/generic.go:12 +0xaa!
www.cloudflare.com!
Sources etc.
•  Slides and code samples for this talk:

https://github.com/cloudflare/jgc-talks/tree/master/
Go_London_User_Group/Go_Containers

•  All my talks (with data/code) on the CloudFlare Github

https://github.com/cloudflare/jgc-talks
•  All my talks on the CloudFlare SlideShare

http://www.slideshare.net/cloudflare

www.cloudflare.com!

More Related Content

What's hot

Introduction to programming - class 11
Introduction to programming - class 11Introduction to programming - class 11
Introduction to programming - class 11
Paul Brebner
 
Program to sort array using insertion sort
Program to sort array using insertion sortProgram to sort array using insertion sort
Program to sort array using insertion sort
Swarup Boro
 
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPythonByterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
akaptur
 
Diving into byte code optimization in python
Diving into byte code optimization in python Diving into byte code optimization in python
Diving into byte code optimization in python
Chetan Giridhar
 
TypeLevel Summit
TypeLevel SummitTypeLevel Summit
TypeLevel Summit
Luca Belli
 
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
akaptur
 
Elixir @ Paris.rb
Elixir @ Paris.rbElixir @ Paris.rb
Elixir @ Paris.rb
Gregoire Lejeune
 
Basics
BasicsBasics
Parallel binary search
Parallel binary searchParallel binary search
Parallel binary search
승혁 조
 
Python programing
Python programingPython programing
Python programing
BHAVYA DOSHI
 
FFT
FFTFFT
P4 2018 io_functions
P4 2018 io_functionsP4 2018 io_functions
P4 2018 io_functions
Prof. Wim Van Criekinge
 
Metarhia KievJS 22-Feb-2018
Metarhia KievJS 22-Feb-2018Metarhia KievJS 22-Feb-2018
Metarhia KievJS 22-Feb-2018
Timur Shemsedinov
 
กลุ่ม6
กลุ่ม6กลุ่ม6
กลุ่ม6
Witita Khamsook
 
Ceaser's cipher
Ceaser's cipherCeaser's cipher
Ceaser's cipher
Nimit Kansagra
 
All I Needed for Functional Programming I Learned in High School Algebra
All I Needed for Functional Programming I Learned in High School AlgebraAll I Needed for Functional Programming I Learned in High School Algebra
All I Needed for Functional Programming I Learned in High School Algebra
Eric Normand
 
Prgišče Lispa
Prgišče LispaPrgišče Lispa
Prgišče Lispa
Simon Belak
 
Python Developer's Daily Routine
Python Developer's Daily RoutinePython Developer's Daily Routine
Python Developer's Daily Routine
Maxim Avanov
 
Git
GitGit
Simulador carrera de caballos desarrollado en C++
Simulador carrera de caballos desarrollado en C++Simulador carrera de caballos desarrollado en C++
Simulador carrera de caballos desarrollado en C++
Santiago Sarmiento
 

What's hot (20)

Introduction to programming - class 11
Introduction to programming - class 11Introduction to programming - class 11
Introduction to programming - class 11
 
Program to sort array using insertion sort
Program to sort array using insertion sortProgram to sort array using insertion sort
Program to sort array using insertion sort
 
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPythonByterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
 
Diving into byte code optimization in python
Diving into byte code optimization in python Diving into byte code optimization in python
Diving into byte code optimization in python
 
TypeLevel Summit
TypeLevel SummitTypeLevel Summit
TypeLevel Summit
 
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
 
Elixir @ Paris.rb
Elixir @ Paris.rbElixir @ Paris.rb
Elixir @ Paris.rb
 
Basics
BasicsBasics
Basics
 
Parallel binary search
Parallel binary searchParallel binary search
Parallel binary search
 
Python programing
Python programingPython programing
Python programing
 
FFT
FFTFFT
FFT
 
P4 2018 io_functions
P4 2018 io_functionsP4 2018 io_functions
P4 2018 io_functions
 
Metarhia KievJS 22-Feb-2018
Metarhia KievJS 22-Feb-2018Metarhia KievJS 22-Feb-2018
Metarhia KievJS 22-Feb-2018
 
กลุ่ม6
กลุ่ม6กลุ่ม6
กลุ่ม6
 
Ceaser's cipher
Ceaser's cipherCeaser's cipher
Ceaser's cipher
 
All I Needed for Functional Programming I Learned in High School Algebra
All I Needed for Functional Programming I Learned in High School AlgebraAll I Needed for Functional Programming I Learned in High School Algebra
All I Needed for Functional Programming I Learned in High School Algebra
 
Prgišče Lispa
Prgišče LispaPrgišče Lispa
Prgišče Lispa
 
Python Developer's Daily Routine
Python Developer's Daily RoutinePython Developer's Daily Routine
Python Developer's Daily Routine
 
Git
GitGit
Git
 
Simulador carrera de caballos desarrollado en C++
Simulador carrera de caballos desarrollado en C++Simulador carrera de caballos desarrollado en C++
Simulador carrera de caballos desarrollado en C++
 

Viewers also liked

Running Secure Server Software on Insecure Hardware Without Parachute
Running Secure Server Software on Insecure Hardware Without ParachuteRunning Secure Server Software on Insecure Hardware Without Parachute
Running Secure Server Software on Insecure Hardware Without Parachute
Cloudflare
 
Secure 2013 Poland
Secure 2013 PolandSecure 2013 Poland
Secure 2013 Poland
Cloudflare
 
CloudFlare - The Heartbleed Bug - Webinar
CloudFlare - The Heartbleed Bug - WebinarCloudFlare - The Heartbleed Bug - Webinar
CloudFlare - The Heartbleed Bug - Webinar
Cloudflare
 
Sullivan red october-oscon-2014
Sullivan red october-oscon-2014Sullivan red october-oscon-2014
Sullivan red october-oscon-2014
Cloudflare
 
Sullivan heartbleed-defcon22 2014
Sullivan heartbleed-defcon22 2014Sullivan heartbleed-defcon22 2014
Sullivan heartbleed-defcon22 2014
Cloudflare
 
Overview of SSL: choose the option that's right for you
Overview of SSL: choose the option that's right for youOverview of SSL: choose the option that's right for you
Overview of SSL: choose the option that's right for you
Cloudflare
 
SortaSQL
SortaSQLSortaSQL
SortaSQL
Cloudflare
 
WordPress London Meetup January 2012
WordPress London Meetup January 2012WordPress London Meetup January 2012
WordPress London Meetup January 2012
Cloudflare
 
Managing Traffic Spikes This Holiday Season
Managing Traffic Spikes This Holiday Season Managing Traffic Spikes This Holiday Season
Managing Traffic Spikes This Holiday Season
Cloudflare
 
How to Meet FFIEC Regulations and Protect Your Bank from Cyber Attacks
How to Meet FFIEC Regulations and Protect Your Bank from Cyber AttacksHow to Meet FFIEC Regulations and Protect Your Bank from Cyber Attacks
How to Meet FFIEC Regulations and Protect Your Bank from Cyber Attacks
Cloudflare
 
Running a Robust DNS Infrastructure with CloudFlare Virtual DNS
Running a Robust DNS Infrastructure with CloudFlare Virtual DNSRunning a Robust DNS Infrastructure with CloudFlare Virtual DNS
Running a Robust DNS Infrastructure with CloudFlare Virtual DNS
Cloudflare
 
Botconf ppt
Botconf   pptBotconf   ppt
Botconf ppt
Cloudflare
 
A Channel Compendium
A Channel CompendiumA Channel Compendium
A Channel Compendium
Cloudflare
 
Go Profiling - John Graham-Cumming
Go Profiling - John Graham-Cumming Go Profiling - John Graham-Cumming
Go Profiling - John Graham-Cumming
Cloudflare
 
Sullivan randomness-infiltrate 2014
Sullivan randomness-infiltrate 2014Sullivan randomness-infiltrate 2014
Sullivan randomness-infiltrate 2014
Cloudflare
 
Hardening Microservices Security: Building a Layered Defense Strategy
Hardening Microservices Security: Building a Layered Defense StrategyHardening Microservices Security: Building a Layered Defense Strategy
Hardening Microservices Security: Building a Layered Defense Strategy
Cloudflare
 
Latest Trends in Web Application Security
Latest Trends in Web Application SecurityLatest Trends in Web Application Security
Latest Trends in Web Application Security
Cloudflare
 
Surviving A DDoS Attack: Securing CDN Traffic at CloudFlare
Surviving A DDoS Attack: Securing CDN Traffic at CloudFlareSurviving A DDoS Attack: Securing CDN Traffic at CloudFlare
Surviving A DDoS Attack: Securing CDN Traffic at CloudFlare
Cloudflare
 
Virus Bulletin 2012
Virus Bulletin 2012Virus Bulletin 2012
Virus Bulletin 2012
Cloudflare
 
F5 Networks - - OpenStack Summit 2016/Red Hat NFV Mini Summit
F5 Networks -  - OpenStack Summit 2016/Red Hat NFV Mini SummitF5 Networks -  - OpenStack Summit 2016/Red Hat NFV Mini Summit
F5 Networks - - OpenStack Summit 2016/Red Hat NFV Mini Summit
kimw001
 

Viewers also liked (20)

Running Secure Server Software on Insecure Hardware Without Parachute
Running Secure Server Software on Insecure Hardware Without ParachuteRunning Secure Server Software on Insecure Hardware Without Parachute
Running Secure Server Software on Insecure Hardware Without Parachute
 
Secure 2013 Poland
Secure 2013 PolandSecure 2013 Poland
Secure 2013 Poland
 
CloudFlare - The Heartbleed Bug - Webinar
CloudFlare - The Heartbleed Bug - WebinarCloudFlare - The Heartbleed Bug - Webinar
CloudFlare - The Heartbleed Bug - Webinar
 
Sullivan red october-oscon-2014
Sullivan red october-oscon-2014Sullivan red october-oscon-2014
Sullivan red october-oscon-2014
 
Sullivan heartbleed-defcon22 2014
Sullivan heartbleed-defcon22 2014Sullivan heartbleed-defcon22 2014
Sullivan heartbleed-defcon22 2014
 
Overview of SSL: choose the option that's right for you
Overview of SSL: choose the option that's right for youOverview of SSL: choose the option that's right for you
Overview of SSL: choose the option that's right for you
 
SortaSQL
SortaSQLSortaSQL
SortaSQL
 
WordPress London Meetup January 2012
WordPress London Meetup January 2012WordPress London Meetup January 2012
WordPress London Meetup January 2012
 
Managing Traffic Spikes This Holiday Season
Managing Traffic Spikes This Holiday Season Managing Traffic Spikes This Holiday Season
Managing Traffic Spikes This Holiday Season
 
How to Meet FFIEC Regulations and Protect Your Bank from Cyber Attacks
How to Meet FFIEC Regulations and Protect Your Bank from Cyber AttacksHow to Meet FFIEC Regulations and Protect Your Bank from Cyber Attacks
How to Meet FFIEC Regulations and Protect Your Bank from Cyber Attacks
 
Running a Robust DNS Infrastructure with CloudFlare Virtual DNS
Running a Robust DNS Infrastructure with CloudFlare Virtual DNSRunning a Robust DNS Infrastructure with CloudFlare Virtual DNS
Running a Robust DNS Infrastructure with CloudFlare Virtual DNS
 
Botconf ppt
Botconf   pptBotconf   ppt
Botconf ppt
 
A Channel Compendium
A Channel CompendiumA Channel Compendium
A Channel Compendium
 
Go Profiling - John Graham-Cumming
Go Profiling - John Graham-Cumming Go Profiling - John Graham-Cumming
Go Profiling - John Graham-Cumming
 
Sullivan randomness-infiltrate 2014
Sullivan randomness-infiltrate 2014Sullivan randomness-infiltrate 2014
Sullivan randomness-infiltrate 2014
 
Hardening Microservices Security: Building a Layered Defense Strategy
Hardening Microservices Security: Building a Layered Defense StrategyHardening Microservices Security: Building a Layered Defense Strategy
Hardening Microservices Security: Building a Layered Defense Strategy
 
Latest Trends in Web Application Security
Latest Trends in Web Application SecurityLatest Trends in Web Application Security
Latest Trends in Web Application Security
 
Surviving A DDoS Attack: Securing CDN Traffic at CloudFlare
Surviving A DDoS Attack: Securing CDN Traffic at CloudFlareSurviving A DDoS Attack: Securing CDN Traffic at CloudFlare
Surviving A DDoS Attack: Securing CDN Traffic at CloudFlare
 
Virus Bulletin 2012
Virus Bulletin 2012Virus Bulletin 2012
Virus Bulletin 2012
 
F5 Networks - - OpenStack Summit 2016/Red Hat NFV Mini Summit
F5 Networks -  - OpenStack Summit 2016/Red Hat NFV Mini SummitF5 Networks -  - OpenStack Summit 2016/Red Hat NFV Mini Summit
F5 Networks - - OpenStack Summit 2016/Red Hat NFV Mini Summit
 

Similar to Go Containers

JVMLS 2016. Coroutines in Kotlin
JVMLS 2016. Coroutines in KotlinJVMLS 2016. Coroutines in Kotlin
JVMLS 2016. Coroutines in Kotlin
Andrey Breslav
 
Combinator parsing
Combinator parsingCombinator parsing
Combinator parsing
Swanand Pagnis
 
Are we ready to Go?
Are we ready to Go?Are we ready to Go?
Are we ready to Go?
Adam Dudczak
 
JDD2014: GO! The one language you have to try in 2014 - Andrzej Grzesik
JDD2014: GO! The one language you have to try in 2014 - Andrzej GrzesikJDD2014: GO! The one language you have to try in 2014 - Andrzej Grzesik
JDD2014: GO! The one language you have to try in 2014 - Andrzej Grzesik
PROIDEA
 
Go, the one language to learn in 2014
Go, the one language to learn in 2014Go, the one language to learn in 2014
Go, the one language to learn in 2014
Andrzej Grzesik
 
Python language data types
Python language data typesPython language data types
Python language data types
James Wong
 
Python language data types
Python language data typesPython language data types
Python language data types
Harry Potter
 
Python language data types
Python language data typesPython language data types
Python language data types
Hoang Nguyen
 
Python language data types
Python language data typesPython language data types
Python language data types
Young Alista
 
Python language data types
Python language data typesPython language data types
Python language data types
Luis Goldster
 
Python language data types
Python language data typesPython language data types
Python language data types
Tony Nguyen
 
Python language data types
Python language data typesPython language data types
Python language data types
Fraboni Ec
 
An Introduction to Go
An Introduction to GoAn Introduction to Go
An Introduction to Go
Cloudflare
 
go.ppt
go.pptgo.ppt
go.ppt
ssuser4ca1eb
 
Happy Go Programming
Happy Go ProgrammingHappy Go Programming
Happy Go Programming
Lin Yo-An
 
Abstracting Vector Architectures in Library Generators: Case Study Convolutio...
Abstracting Vector Architectures in Library Generators: Case Study Convolutio...Abstracting Vector Architectures in Library Generators: Case Study Convolutio...
Abstracting Vector Architectures in Library Generators: Case Study Convolutio...
ETH Zurich
 
Ruslan.shevchenko: most functional-day-kiev 2014
Ruslan.shevchenko: most functional-day-kiev 2014Ruslan.shevchenko: most functional-day-kiev 2014
Ruslan.shevchenko: most functional-day-kiev 2014
Ruslan Shevchenko
 
Go Concurrency
Go ConcurrencyGo Concurrency
Go Concurrency
jgrahamc
 
Learn You a Functional JavaScript for Great Good
Learn You a Functional JavaScript for Great GoodLearn You a Functional JavaScript for Great Good
Learn You a Functional JavaScript for Great Good
Mike Harris
 
Music as data
Music as dataMusic as data
Music as data
John Vlachoyiannis
 

Similar to Go Containers (20)

JVMLS 2016. Coroutines in Kotlin
JVMLS 2016. Coroutines in KotlinJVMLS 2016. Coroutines in Kotlin
JVMLS 2016. Coroutines in Kotlin
 
Combinator parsing
Combinator parsingCombinator parsing
Combinator parsing
 
Are we ready to Go?
Are we ready to Go?Are we ready to Go?
Are we ready to Go?
 
JDD2014: GO! The one language you have to try in 2014 - Andrzej Grzesik
JDD2014: GO! The one language you have to try in 2014 - Andrzej GrzesikJDD2014: GO! The one language you have to try in 2014 - Andrzej Grzesik
JDD2014: GO! The one language you have to try in 2014 - Andrzej Grzesik
 
Go, the one language to learn in 2014
Go, the one language to learn in 2014Go, the one language to learn in 2014
Go, the one language to learn in 2014
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
An Introduction to Go
An Introduction to GoAn Introduction to Go
An Introduction to Go
 
go.ppt
go.pptgo.ppt
go.ppt
 
Happy Go Programming
Happy Go ProgrammingHappy Go Programming
Happy Go Programming
 
Abstracting Vector Architectures in Library Generators: Case Study Convolutio...
Abstracting Vector Architectures in Library Generators: Case Study Convolutio...Abstracting Vector Architectures in Library Generators: Case Study Convolutio...
Abstracting Vector Architectures in Library Generators: Case Study Convolutio...
 
Ruslan.shevchenko: most functional-day-kiev 2014
Ruslan.shevchenko: most functional-day-kiev 2014Ruslan.shevchenko: most functional-day-kiev 2014
Ruslan.shevchenko: most functional-day-kiev 2014
 
Go Concurrency
Go ConcurrencyGo Concurrency
Go Concurrency
 
Learn You a Functional JavaScript for Great Good
Learn You a Functional JavaScript for Great GoodLearn You a Functional JavaScript for Great Good
Learn You a Functional JavaScript for Great Good
 
Music as data
Music as dataMusic as data
Music as data
 

More from Cloudflare

Succeeding with Secure Access Service Edge (SASE)
Succeeding with Secure Access Service Edge (SASE)Succeeding with Secure Access Service Edge (SASE)
Succeeding with Secure Access Service Edge (SASE)
Cloudflare
 
Close your security gaps and get 100% of your traffic protected with Cloudflare
Close your security gaps and get 100% of your traffic protected with CloudflareClose your security gaps and get 100% of your traffic protected with Cloudflare
Close your security gaps and get 100% of your traffic protected with Cloudflare
Cloudflare
 
Why you should replace your d do s hardware appliance
Why you should replace your d do s hardware applianceWhy you should replace your d do s hardware appliance
Why you should replace your d do s hardware appliance
Cloudflare
 
Don't Let Bots Ruin Your Holiday Business - Snackable Webinar
Don't Let Bots Ruin Your Holiday Business - Snackable WebinarDon't Let Bots Ruin Your Holiday Business - Snackable Webinar
Don't Let Bots Ruin Your Holiday Business - Snackable Webinar
Cloudflare
 
Why Zero Trust Architecture Will Become the New Normal in 2021
Why Zero Trust Architecture Will Become the New Normal in 2021Why Zero Trust Architecture Will Become the New Normal in 2021
Why Zero Trust Architecture Will Become the New Normal in 2021
Cloudflare
 
HARTMANN and Cloudflare Learn how healthcare providers can build resilient in...
HARTMANN and Cloudflare Learn how healthcare providers can build resilient in...HARTMANN and Cloudflare Learn how healthcare providers can build resilient in...
HARTMANN and Cloudflare Learn how healthcare providers can build resilient in...
Cloudflare
 
Zero trust for everybody: 3 ways to get there fast
Zero trust for everybody: 3 ways to get there fastZero trust for everybody: 3 ways to get there fast
Zero trust for everybody: 3 ways to get there fast
Cloudflare
 
LendingTree and Cloudflare: Ensuring zero trade-off between security and cust...
LendingTree and Cloudflare: Ensuring zero trade-off between security and cust...LendingTree and Cloudflare: Ensuring zero trade-off between security and cust...
LendingTree and Cloudflare: Ensuring zero trade-off between security and cust...
Cloudflare
 
Network Transformation: What it is, and how it’s helping companies stay secur...
Network Transformation: What it is, and how it’s helping companies stay secur...Network Transformation: What it is, and how it’s helping companies stay secur...
Network Transformation: What it is, and how it’s helping companies stay secur...
Cloudflare
 
Scaling service provider business with DDoS-mitigation-as-a-service
Scaling service provider business with DDoS-mitigation-as-a-serviceScaling service provider business with DDoS-mitigation-as-a-service
Scaling service provider business with DDoS-mitigation-as-a-service
Cloudflare
 
Application layer attack trends through the lens of Cloudflare data
Application layer attack trends through the lens of Cloudflare dataApplication layer attack trends through the lens of Cloudflare data
Application layer attack trends through the lens of Cloudflare data
Cloudflare
 
Recent DDoS attack trends, and how you should respond
Recent DDoS attack trends, and how you should respondRecent DDoS attack trends, and how you should respond
Recent DDoS attack trends, and how you should respond
Cloudflare
 
Cybersecurity 2020 threat landscape and its implications (AMER)
Cybersecurity 2020 threat landscape and its implications (AMER)Cybersecurity 2020 threat landscape and its implications (AMER)
Cybersecurity 2020 threat landscape and its implications (AMER)
Cloudflare
 
Strengthening security posture for modern-age SaaS providers
Strengthening security posture for modern-age SaaS providersStrengthening security posture for modern-age SaaS providers
Strengthening security posture for modern-age SaaS providers
Cloudflare
 
Kentik and Cloudflare Partner to Mitigate Advanced DDoS Attacks
Kentik and Cloudflare Partner to Mitigate Advanced DDoS AttacksKentik and Cloudflare Partner to Mitigate Advanced DDoS Attacks
Kentik and Cloudflare Partner to Mitigate Advanced DDoS Attacks
Cloudflare
 
Stopping DDoS Attacks in North America
Stopping DDoS Attacks in North AmericaStopping DDoS Attacks in North America
Stopping DDoS Attacks in North America
Cloudflare
 
It’s 9AM... Do you know what’s happening on your network?
It’s 9AM... Do you know what’s happening on your network?It’s 9AM... Do you know what’s happening on your network?
It’s 9AM... Do you know what’s happening on your network?
Cloudflare
 
Cyber security fundamentals (simplified chinese)
Cyber security fundamentals (simplified chinese)Cyber security fundamentals (simplified chinese)
Cyber security fundamentals (simplified chinese)
Cloudflare
 
Bring speed and security to the intranet with cloudflare for teams
Bring speed and security to the intranet with cloudflare for teamsBring speed and security to the intranet with cloudflare for teams
Bring speed and security to the intranet with cloudflare for teams
Cloudflare
 
Accelerate your digital transformation
Accelerate your digital transformationAccelerate your digital transformation
Accelerate your digital transformation
Cloudflare
 

More from Cloudflare (20)

Succeeding with Secure Access Service Edge (SASE)
Succeeding with Secure Access Service Edge (SASE)Succeeding with Secure Access Service Edge (SASE)
Succeeding with Secure Access Service Edge (SASE)
 
Close your security gaps and get 100% of your traffic protected with Cloudflare
Close your security gaps and get 100% of your traffic protected with CloudflareClose your security gaps and get 100% of your traffic protected with Cloudflare
Close your security gaps and get 100% of your traffic protected with Cloudflare
 
Why you should replace your d do s hardware appliance
Why you should replace your d do s hardware applianceWhy you should replace your d do s hardware appliance
Why you should replace your d do s hardware appliance
 
Don't Let Bots Ruin Your Holiday Business - Snackable Webinar
Don't Let Bots Ruin Your Holiday Business - Snackable WebinarDon't Let Bots Ruin Your Holiday Business - Snackable Webinar
Don't Let Bots Ruin Your Holiday Business - Snackable Webinar
 
Why Zero Trust Architecture Will Become the New Normal in 2021
Why Zero Trust Architecture Will Become the New Normal in 2021Why Zero Trust Architecture Will Become the New Normal in 2021
Why Zero Trust Architecture Will Become the New Normal in 2021
 
HARTMANN and Cloudflare Learn how healthcare providers can build resilient in...
HARTMANN and Cloudflare Learn how healthcare providers can build resilient in...HARTMANN and Cloudflare Learn how healthcare providers can build resilient in...
HARTMANN and Cloudflare Learn how healthcare providers can build resilient in...
 
Zero trust for everybody: 3 ways to get there fast
Zero trust for everybody: 3 ways to get there fastZero trust for everybody: 3 ways to get there fast
Zero trust for everybody: 3 ways to get there fast
 
LendingTree and Cloudflare: Ensuring zero trade-off between security and cust...
LendingTree and Cloudflare: Ensuring zero trade-off between security and cust...LendingTree and Cloudflare: Ensuring zero trade-off between security and cust...
LendingTree and Cloudflare: Ensuring zero trade-off between security and cust...
 
Network Transformation: What it is, and how it’s helping companies stay secur...
Network Transformation: What it is, and how it’s helping companies stay secur...Network Transformation: What it is, and how it’s helping companies stay secur...
Network Transformation: What it is, and how it’s helping companies stay secur...
 
Scaling service provider business with DDoS-mitigation-as-a-service
Scaling service provider business with DDoS-mitigation-as-a-serviceScaling service provider business with DDoS-mitigation-as-a-service
Scaling service provider business with DDoS-mitigation-as-a-service
 
Application layer attack trends through the lens of Cloudflare data
Application layer attack trends through the lens of Cloudflare dataApplication layer attack trends through the lens of Cloudflare data
Application layer attack trends through the lens of Cloudflare data
 
Recent DDoS attack trends, and how you should respond
Recent DDoS attack trends, and how you should respondRecent DDoS attack trends, and how you should respond
Recent DDoS attack trends, and how you should respond
 
Cybersecurity 2020 threat landscape and its implications (AMER)
Cybersecurity 2020 threat landscape and its implications (AMER)Cybersecurity 2020 threat landscape and its implications (AMER)
Cybersecurity 2020 threat landscape and its implications (AMER)
 
Strengthening security posture for modern-age SaaS providers
Strengthening security posture for modern-age SaaS providersStrengthening security posture for modern-age SaaS providers
Strengthening security posture for modern-age SaaS providers
 
Kentik and Cloudflare Partner to Mitigate Advanced DDoS Attacks
Kentik and Cloudflare Partner to Mitigate Advanced DDoS AttacksKentik and Cloudflare Partner to Mitigate Advanced DDoS Attacks
Kentik and Cloudflare Partner to Mitigate Advanced DDoS Attacks
 
Stopping DDoS Attacks in North America
Stopping DDoS Attacks in North AmericaStopping DDoS Attacks in North America
Stopping DDoS Attacks in North America
 
It’s 9AM... Do you know what’s happening on your network?
It’s 9AM... Do you know what’s happening on your network?It’s 9AM... Do you know what’s happening on your network?
It’s 9AM... Do you know what’s happening on your network?
 
Cyber security fundamentals (simplified chinese)
Cyber security fundamentals (simplified chinese)Cyber security fundamentals (simplified chinese)
Cyber security fundamentals (simplified chinese)
 
Bring speed and security to the intranet with cloudflare for teams
Bring speed and security to the intranet with cloudflare for teamsBring speed and security to the intranet with cloudflare for teams
Bring speed and security to the intranet with cloudflare for teams
 
Accelerate your digital transformation
Accelerate your digital transformationAccelerate your digital transformation
Accelerate your digital transformation
 

Recently uploaded

GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!
GDSC PJATK
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
Wouter Lemaire
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
Shinana2
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdfNunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
flufftailshop
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
saastr
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
LucaBarbaro3
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Jeffrey Haguewood
 
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
alexjohnson7307
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
fredae14
 
AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
HarisZaheer8
 

Recently uploaded (20)

GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdfNunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
Overcoming the PLG Trap: Lessons from Canva's Head of Sales & Head of EMEA Da...
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
 
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
 
AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
 

Go Containers

  • 1. Go Containers January 23, 2014 John Graham-Cumming www.cloudflare.com!
  • 2. Six interesting containers •  From pkg/container! •  container/list! •  container/ring! •  container/heap
 ! •  Built in •  map! •  slice •  Channels as queues www.cloudflare.com!
  • 3. container/list! •  Doubly-linked list implementation •  Uses interface{} for values l := list.New()! e0 := l.PushBack(42)! e1 := l.PushFront(13)! Pity  there’s  no  ‘map’   e2 := l.PushBack(7)! func4on   l.InsertBefore(3, e0)! l.InsertAfter(196, e1)! l.InsertAfter(1729, e2)! ! for e := l.Front(); e != nil; e = e.Next() {! fmt.Printf("%d ", e.Value.(int))! }! e.Value  to  get  the   fmt.Printf("n")! stored  value   ! ! 13 196 3 42 7 1729! www.cloudflare.com!
  • 4. container/list! All  work  on   elements  not  values     l.MoveToFront(e2)! l.MoveToBack(e1)! Returns  the  value   l.Remove(e0)! removed   ! for e := l.Front(); e != nil; e = e.Next() {! fmt.Printf("%d ", e.Value.(int))! }! fmt.Printf("n")! ! ! 7 196 3 1729 13! www.cloudflare.com!
  • 5. container/ring! •  A circular ‘list’ parus := []string{”major", “holsti”, “carpi”}! ! r := ring.New(len(parus))! for i := 0; i < r.Len(); i++ {! r.Value = parus[i]! r = r.Next()! }! ! r.Do(func(x interface{}) {! fmt.Printf(“Parus %sn”, x.(string))! })! •  Move n elements through ring r.Move(n)! www.cloudflare.com!
  • 6. container/heap! •  Implements a “min-heap” (i.e. tree where each node is the “minimum” element in its subtree) •  Needs a notion of “Less” and a way to “Swap” www.cloudflare.com!
  • 7. container/heap! •  The single most confusing definition in all of Go type Interface interface {! sort.Interface! Push(x interface{}) // add x as element Len()! Pop() interface{} // remove/return element Len()-1! }! ! // Note that Push and Pop in this interface are for ! // package heap's implementation to call. To add and ! // remove things from the heap, use heap.Push and! // heap.Pop.! www.cloudflare.com!
  • 8. container/heap! •  Simple example type OrderedInts []int! ! func (h OrderedInts) Len() int { return len(h) }! func (h OrderedInts) Less(i, j int) bool {! return h[i] < h[j]! }! func (h OrderedInts) Swap(i,j int) {h[i],h[j]=h[j],h[i]}! func (h *OrderedInts) Push(x interface{}) {! !*h = append(*h, x.(int))! }! func (h *OrderedInts) Pop() interface{} {! !old := *h! !n := len(old)-1! !x := old[n]! !*h = old[:n]! !return x! }! www.cloudflare.com!
  • 9. container/heap! •  Using a heap h := &OrderedInts{33,76,55,24,48,63,86,83,83,12}! ! heap.Init(h)! ! fmt.Printf("min: %dn", (*h)[0])! ! for h.Len() > 0 {! fmt.Printf("%d ", heap.Pop(h))! }! ! fmt.Printf(“n”)! www.cloudflare.com!
  • 10. container/heap! •  Heaps are useful for... •  Make a priority queue •  Sorting •  Graph algorithms www.cloudflare.com!
  • 12. map! •  Maps are typed dictionary := make(map[string]string)! dictionary := map[string]string{}! ! •  They are not concurrency safe •  Use a lock or channel for concurrent read/write access counts := struct{! sync.RWMutex! m map[string]int! }{m: make(map[string]int)}! ! counts.RLock()! fmt.Printf(“foo count”, counts.m[“foo”]! counts.RUnlock()! ! counts.Lock()! counts.m[“foo”] += num_foos! counts.Unlock()! ! www.cloudflare.com! Mul4ple  readers,   one  writer  
  • 13. map iteration m := map[string]int{! "bar”: 54,! "foo”: 42,! "baz”: -1,! }! ! for k := range m {! // k is foo, bar, baz! }! ! for _, v := range m {! // v is 54, 42, -1 in some order! }! ! for k, v := range m {! // k and v are as above! }! www.cloudflare.com! Order  of  itera4on  is   undefined    
  • 14. Common map operations •  Remove an element delete(dictionary, “twerking”)! •  Test presence of an element definition, present := dictionary[“hoopy”]! ! _, present := dictionary[“sigil”]! •  Missing element gives a “zero” value fmt.Printf(“[%s]n”, dictionary[“ewyfgwyegfweygf”])! ! []! www.cloudflare.com!
  • 16. Slices •  A slice is part of an array var arrayOfInts [256]int! ! var part []int = arrayOfInts[2:6]! •  arrayOfInts is 256 ints contiguously in memory 0   1   2   3   4   5   6   7   8   9   10   11   12   ! ! •  part consists of a pointer (to arrayOfInts[2]) and a length (4) www.cloudflare.com!
  • 17. Slice passing •  A slice is passed (like everything else) by copy var arrayOfInts [256]int! ! var part []int = arrayOfInts[2:6]! ! func fill(s []int) {! for i, _ := range s {! s[i] = i*2! }! ! s = s[1:]! }! Does  nothing  to   ! part! fill(part)! fmt.Printf(“%#v”, part)! ! % ./slice! []int{0, 2, 4, 6}! www.cloudflare.com! Contents  of  s  can  be   modified   Changes  contents  of   underlying  array  
  • 18. Slice passing, part 2 •  Can pass a pointer to a slice to modify the slice var arrayOfInts [256]int! ! var part intSlice = arrayOfInts[2:6] ! ! Contents  of  s  can  be   type intSlice []int! modified  and  s  can   func (s *intSlice) fill() {! be  changed   for i, _ := range *s {! (*s)[i] = i*2! }! *s = (*s)[1:]! Changes  part! }! ! part.fill()! fmt.Printf("%#vn", part)! ! % ./slice! []int{2, 4, 6}! www.cloudflare.com!
  • 19. Slice iteration prime := []int{2, 3, 5, 7, 11}! ! for i := range prime {! // i is 0, 1, 2, 3, 4! }! ! for _, e := range prime{! // e is 2, 3, 5, 7, 11! }! ! for i, e := range prime {! // i and e as above! }! www.cloudflare.com!
  • 20. Copying slices •  copy builtin morePrimes := make([]int, len(primes), 2*cap(primes))! ! copy(morePrimes, primes)! •  copy allows source and destination to overlap primes := [10]int{2, 3, 5, 7, 11, 13, 17, 19, 23, 29}! odds := primes[1:7]! ! odds = odds[0:len(odds)+1]! copy(odds[4:], odds[3:])! odds[3] = 9! fmt.Printf("%#vn", odds)! ! []int{3, 5, 7, 9, 11, 13, 17}! www.cloudflare.com!
  • 21. Appending slices s := []int{1, 3, 6, 10}! t := []int{36, 45, 55, 66, 78}! ! s = append(s, 15)! Adding  individual   elements   s = append(s, 21, 28)! ! s = append(s, t...)! ! Adding  an  en4re   nu := append([]int(nil), s...)! slice   ! s = append(s, s...)! Copying  a  slice  (use   ! copy  instead)   fmt.Printf(“%#vn”, s)! ! []int{1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78}! www.cloudflare.com!
  • 23. A buffered channel is a FIFO queue •  A typed queue of up to 10 Things queue := make(chan Thing, 10) ! •  Get the next element from the queue if there is one select {! case t := <-queue: // got one! default: // queue is empty! } ! •  Add to queue if there’s room select {! case queue <- t: // added to queue! default: // queue is full! }! www.cloudflare.com!
  • 25. Perhaps heretical •  But... I wish Go had some generics •  interface{} is like void *; Type assertions similar to casts l := list.New()! l.PushFront("Hello, World!")! v := l.Front()! i := v.Value.(int)! % go build l.go! % ./l! panic: interface conversion: interface is string, not int! ! goroutine 1 [running]:! runtime.panic(0x49bdc0, 0xc210041000)! !/extra/go/src/pkg/runtime/panic.c:266 +0xb6! main.main()! !/extra/src/mc/generic.go:12 +0xaa! www.cloudflare.com!
  • 26. Sources etc. •  Slides and code samples for this talk: https://github.com/cloudflare/jgc-talks/tree/master/ Go_London_User_Group/Go_Containers •  All my talks (with data/code) on the CloudFlare Github https://github.com/cloudflare/jgc-talks •  All my talks on the CloudFlare SlideShare http://www.slideshare.net/cloudflare www.cloudflare.com!