GoLang
lovecj111
这个作者很懒,什么都没留下…
展开
-
java CountDownLatch与golang WaitGroup的用法
主线程等待所有线程执行结束再继续执行public class TestCountDownLatch { static int loopCount = 10; static CountDownLatch latch = new CountDownLatch(loopCount); static class Hello implements Runnable{ private int i; private Hello(int i){原创 2020-11-28 19:17:22 · 506 阅读 · 0 评论 -
golang 生成 protobuf 代码模板
在项目开发中会使用protobuf作为通信的模板或者存储的模板使用protobuf时需要定义.proto文件然后根据proto文件生成对应语言的模板代码下面是以golang语言为例子生成模板代码的步骤首先需要去protobuf官网下载一个protoc-3.8.0-win32.zip的包这里用3.8.0版本解压之后的目录结构是在bin目录下有一个exe文件用于生成模板代码还需要一个辅...原创 2019-08-28 11:19:43 · 941 阅读 · 0 评论 -
GoLang实现冒泡排序
func main() {arr := [...]int{5, 4, 3, 2, 1}fmt.Println("排序前", arr) //[5 4 3 2 1]temp := 0//第1轮(5会移动到最后1个位置)for j := 0; j < len(arr) - 1; j++ { if arr[j] > arr[j + 1] { temp = arr[j] ar...原创 2019-08-29 15:15:25 · 125 阅读 · 0 评论 -
GoLang实现的二分查找算法
func BinarySearch(arr *[9]int, val int) int { return binarySearch(arr, 0, len(arr) - 1, val)}func binarySearch(arr *[9]int, leftIndex int, rightIndex int, val int) int { if leftIndex > rightIn...原创 2019-09-02 12:03:37 · 512 阅读 · 0 评论