GO 使用開源的資料結構

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。

1.  平台 Windows, 安裝 git

2. 安裝 go 1.3+

3. 查看 GOPATH 資訊

C:\>go envset GOARCH=amd64set GOBIN=set GOEXE=.exeset GOHOSTARCH=amd64set GOHOSTOS=windowsset GOOS=windowsset GOPATH=C:\Users\Administrator\goset GORACE=set GOROOT=C:\Goset GOTOOLDIR=C:\Go\pkg\tool\windows_amd64set GCCGO=gccgoset CC=gccset GOGCCFLAGS=-m64 -mthreads -fmessage-length=0set CXX=g++set CGO_ENABLED=1set PKG_CONFIG=pkg-configset CGO_CFLAGS=-g -O2set CGO_CPPFLAGS=set CGO_CXXFLAGS=-g -O2set CGO_FFLAGS=-g -O2set CGO_LDFLAGS=-g -O2

4. 下載代碼,測試代碼

Microsoft Windows [版本 6.1.7601]著作權 (c) 2009 Microsoft Corporation。著作權所有,並保留一切權利。C:\Users\Administrator>cd C:\Users\Administrator\goC:\Users\Administrator\go>go get github.com/Workiva/go-datastructures/...C:\Users\Administrator\go>go get -u github.com/Workiva/go-datastructures/...C:\Users\Administrator\go>cd srcC:\Users\Administrator\go\src>cd github.comC:\Users\Administrator\go\src\github.com>cd WorkivaC:\Users\Administrator\go\src\github.com\Workiva>cd go-datastructuresC:\Users\Administrator\go\src\github.com\Workiva\go-datastructures>go get -t -u./...C:\Users\Administrator\go\src\github.com\Workiva\go-datastructures>go test ./...?       github.com/Workiva/go-datastructures    [no test files]ok      github.com/Workiva/go-datastructures/augmentedtree      2.126sok      github.com/Workiva/go-datastructures/batcher    1.363sok      github.com/Workiva/go-datastructures/bitarray   1.581sok      github.com/Workiva/go-datastructures/btree/immutable    15.153sok      github.com/Workiva/go-datastructures/btree/palm 1.064sok      github.com/Workiva/go-datastructures/btree/plus 1.783sok      github.com/Workiva/go-datastructures/cache      0.820s?       github.com/Workiva/go-datastructures/common     [no test files]ok      github.com/Workiva/go-datastructures/fibheap    1.669sok      github.com/Workiva/go-datastructures/futures    0.614sok      github.com/Workiva/go-datastructures/hashmap/fastinteger        1.228sok      github.com/Workiva/go-datastructures/list       2.105s?       github.com/Workiva/go-datastructures/mock       [no test files]ok      github.com/Workiva/go-datastructures/numerics/hilbert   0.640sok      github.com/Workiva/go-datastructures/numerics/optimization      1.128sok      github.com/Workiva/go-datastructures/queue      0.696sok      github.com/Workiva/go-datastructures/rangetree  1.715sok      github.com/Workiva/go-datastructures/rangetree/skiplist 1.274s?       github.com/Workiva/go-datastructures/rtree      [no test files]ok      github.com/Workiva/go-datastructures/rtree/hilbert      1.655sok      github.com/Workiva/go-datastructures/set        0.662sok      github.com/Workiva/go-datastructures/slice      0.761sok      github.com/Workiva/go-datastructures/slice/skip 1.057sok      github.com/Workiva/go-datastructures/sort       1.279sok      github.com/Workiva/go-datastructures/threadsafe/err     0.714sok      github.com/Workiva/go-datastructures/tree/avl   1.533sok      github.com/Workiva/go-datastructures/trie/ctrie 13.429sok      github.com/Workiva/go-datastructures/trie/dtrie 0.713sok      github.com/Workiva/go-datastructures/trie/xfast 1.482sok      github.com/Workiva/go-datastructures/trie/yfast 1.070sC:\Users\Administrator\go\src\github.com\Workiva\go-datastructures>

5. 簡單使用

開啟 ”LiteIDE“ ,  檔案 -> 開啟目錄 -> 選擇 "C:\Users\Administrator\go\src" 下的 github.com 目錄

效果如下:

右擊 LiteIDE 中的  "github.com" 選擇  “建立目錄” 輸入 "src" -> 點擊“建立”

右擊 “src” 目錄 選擇 “建立檔案”輸入 “main.go” 點擊 “建立並編輯”

測試代碼如下:

package mainimport ("fmt""github.com/Workiva/go-datastructures/list")func main() {ll := list.Emptyfmt.Println(ll.IsEmpty())ll = ll.Add(10)ll = ll.Add(12)ll = ll.Add(14)fmt.Println(ll.Length())var i uintfor i = 0; i < ll.Length(); i++ {item, ok := ll.Get(i)if ok {fmt.Println("item(", i, ") = ", item)}}fmt.Println("------------------------------------")tmp, err := ll.Insert("Hello World!", ll.Length())if err != nil {fmt.Println("list insert err: ", err)} else {ll = tmp}for i = 0; i < ll.Length(); i++ {item, ok := ll.Get(i)if ok {fmt.Println("item(", i, ") = ", item)}}fmt.Println("------------------------------------")}

右擊 “src” 選擇 “鎖定編譯目錄” 編譯運行,輸出如下:

true3item( 0 ) =  14item( 1 ) =  12item( 2 ) =  10------------------------------------item( 0 ) =  14item( 1 ) =  12item( 2 ) =  10item( 3 ) =  Hello World!------------------------------------成功: 進程結束代碼 0.

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.