concurrentsort

package module
v0.0.0-...-5a374e7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 10, 2017 License: MIT Imports: 2 Imported by: 0

README

ConcurrentSort

Sorting algorithms parallelized in Golang.

Simply doing them as exercise.

GoDoc

QuickSort

Initializing an empty slice with 100000 slots
Filling it up with random numbers
Init done
Start sorting with 1 workers
Sorted in 90.433691ms
Checking slice order...

Initializing an empty slice with 100000 slots
Filling it up with random numbers
Init done
Start sorting with 8 workers
Sorted in 23.142308ms
Checking slice order...

Initializing an empty slice with 1000000 slots
Filling it up with random numbers
Init done
Start sorting with 1 workers
Sorted in 779.117719ms
Checking slice order...

Initializing an empty slice with 1000000 slots
Filling it up with random numbers
Init done
Start sorting with 8 workers
Sorted in 143.434931ms
Checking slice order...

Initializing an empty slice with 10000000 slots
Filling it up with random numbers
Init done
Start sorting with 1 workers
Sorted in 7.277401429s
Checking slice order...

Initializing an empty slice with 10000000 slots
Filling it up with random numbers
Init done
Start sorting with 8 workers
Sorted in 1.407103771s
Checking slice order...

PASS
ok  	_/tmp/cs/env/src/concurrentsort	17.841s

Documentation

Index

Constants

View Source
const WorkersToSliceLimitRatio = 1.5

WorkersToSliceLimitRatio is the "ideal" ratio between the number of workers and the slice size limit for concurrency Check quicksort.bench package for more informations

Variables

This section is empty.

Functions

func GetIdealSliceSizeLimit

func GetIdealSliceSizeLimit(nbWorkers int) int

GetIdealSliceSizeLimit will return the best slice size limit for concurrency based on the number of workers and the number of availables cpu cores. Check quicksort.bench package for more informations

func QuickSort

func QuickSort(data QuickSortable)

QuickSort sorts data using the quicksort algo distributed on multiples workers. It is just a high level wrapper which set optimal parameters to QuickSortCustom(). The number of workers will be equal to runtime.NumCPU() and the concurrent limit adapted to the number of workers.

func QuickSortCustom

func QuickSortCustom(data QuickSortable, nbWorkers int, concurrentSliceSizeLimit int)

QuickSortCustom sorts data using the quicksort algo distributed on nbWorkers goroutines nbWorkers allows to specify the number of max goroutines which will be used for concurrency. concurrentSliceSizeLimit sets the minimum slice size limit for concurrency. Check quicksort.bench package readme for more informations.

Types

type IntSlice

type IntSlice []int

IntSlice attaches the methods of Interface to []int, sorting in increasing order.

func (IntSlice) GetSubSliceFrom

func (p IntSlice) GetSubSliceFrom(i int) QuickSortable

func (IntSlice) GetSubSliceTo

func (p IntSlice) GetSubSliceTo(i int) QuickSortable

func (IntSlice) Len

func (p IntSlice) Len() int

func (IntSlice) LessOrEqual

func (p IntSlice) LessOrEqual(i, j int) bool

func (IntSlice) Swap

func (p IntSlice) Swap(i, j int)

type QuickSortable

type QuickSortable interface {
	Len() int
	LessOrEqual(i, j int) bool
	Swap(i, j int)
	GetSubSliceTo(i int) QuickSortable
	GetSubSliceFrom(j int) QuickSortable
}

QuickSortable is an interface which must be satisfied in order to call QuickSort()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL