草庐IT

acts_as_tree

全部标签

arrays - 无法对二维数组的列进行 slice "cannot use Sudoku[0:9][0] (type [9]int) as type []int in assignment"

我正在使用9x9二维数组的slice制作一个简单的数独游戏。我仍然刚开始使用Golang并且有一些C++经验。我不断收到错误消息“无法将数独[0:9][0](类型[9]int)用作赋值中的类型[]int”。varrow1[]int=数独[0][0:9]该行正确地获取了二维数组第一行的值并将它们放入row1slice中,但是使用varcol1[]int=Sudoku[0:9][0]会导致上面的错误消息。我能做什么?提前致谢!例如,packagemainimport"fmt"funcmain(){varSudoku[9][9]intfmt.Println(Sudoku)varrow1[]i

go - "Cannot use myType as type interface{}"?我以为在 Go 中所有类型都算作 interface{}?

这个问题在这里已经有了答案:Convert[]stringto[]interface{}[duplicate](3个答案)Convertingsliceofstructstosliceofemptyinterface[duplicate](1个回答)Whycan'tIsubstituteasliceofonetypeforanotherinGo?(3个答案)Whycan'tIpassa`func()[]int`as`func()[]interface{}`ingo?(2个答案)Whyaslice[]structdoesn'tbehavesameas[]builtin?(3个答案)关闭4

go - 传播时 "Cannot use variable of type []struct as []interface"

这个问题在这里已经有了答案:sliceofstruct!=sliceofinterfaceitimplements?(6个答案)关闭8个月前。原型(prototype)函数functest(i...interface{}){//Codehere}预期用途typefoostruct{//Fields}foos:=[]foo{//foo1,foo2...}test(foos...)//ERRORtest(foos[1],foos[2],...)//OK错误cannotusefoos(variableoftype[]foos)as[]interface{}valueinargumenttot

go - 未能使测试套件通过 golang "sayHello() used as value"

我试图让这个测试套件通过命令提示符(hello-world_test.go):packagehelloworldimport"testing"funcTestHelloWorld(t*testing.T){output:=sayHello()if"Hello,World!"!=output{t.Fatalf("output:%s\nexpected:Hello,World!",output)}}我的代码如下(helloworld.go):packagehelloworldimport"fmt"funcsayHello(){fmt.Println("Hello,World!")}通过命令

戈朗 : Passing structs as parameters of a function

尝试通过在线类(class)自学围棋。而且我正在尝试稍微偏离路线以扩展我的学习。该类(class)让我们使用几个变量编写一个简单的函数,该函数将获取这两个变量并打印出一行。所以我有:funcmain(){vargreeting:="hello"varname:="cleveland"message:=printMessage(greeting,name)fmt.Println(message)}funcprintMessage(greetingstring,namestring)(messagestring){returngreeting+""+name+"!"}稍后类(class)介

go - 不能使用 p[idx + 1 :] (type []Person) as type Person in append

这个问题在这里已经有了答案:cannotusetype[]runeastyperuneinappend(1个回答)关闭2个月前。packagemainimport("fmt")typePersonstruct{namestringageint}funcmain(){p:=[]Person{{"Kate",20},{"Simon",30},{"John",28},{"Lake",19},}n:=[]string{"Simon","Kate","Lake",}foridx:=0;idx我有上面的代码来删除pslice中显示在nslice中的人。但是在编译的时候出现了如下错误:./main.

go - 关于 "cannot use time.Now() (type time.Time) as type "

使用以下类型定义获取“不能使用time.Now()(类型time.Time)作为字段值中的类型typetime”import("time")typetypetimetime.TimetypeFriendsstruct{NamestringBirthdaytypetime}John:=Friends{Name:"John",Birthday:time.Now()}如果我用直接类型形式(time.Time)替换typetime,就没有问题。GO的规则背后是什么??:> 最佳答案 time.Time和typetime是不同的类型(尽管它们

algorithm - 戈朗 : benchmark Radix Tree Lookup

为了练习Golang,我一直在尝试对我编写的RadixTree实现进行基准测试。但我遇到了“我应该如何对其进行基准测试?”的问题。在下面的代码中显示了两种情况,或者说我想对LookUp函数进行基准测试的不同方式。情况1:使用存在于树上的单个byteslice段,这意味着它将通过所有子节点等成功查找...情况2:使用函数从树中的现有数据生成随机slice,这意味着它也将成功查找...我知道花费的时间将取决于树的深度...我认为案例2是否接近现实世界的实现?问题:哪种情况对基准测试更有效或更有用?基准:funcBenchmarkLookUp(b*testing.B){radix:=New(

go - 如何在Workiva/go-data structures/中使用b tree/plus

我一直需要二叉树的实现。我在这里找到了一个。https://github.com/Workiva/go-datastructures/tree/master/btree/plus但我不太确定如何使用它。这个repo中的其他数据结构非常简单。只需调用他的包并运行这些方法。但是这个btree有点令人困惑我只是想要一个简单的示例,说明如何创建、插入和检索由此包创建的树。创建btree/plus插入key检索范围 最佳答案 godoc因为它说“在撰写本文时,树还没有完全完成”,而且它似乎根本没有公开用于创建树的公共(public)接口(in

xml - 戈朗 :xml unmarshall not working as expected

获取xml格式的响应:https://sites.google.com/feeds/activity/site/siteName2009-09-10T05:24:23.120ZActivityGoogleSites1https://sites.google.com/feeds/activity/site/siteName/9403759969528760622009-09-10T03:38:42.585ZhomeUserdeletedhomeUseruser@gmail.comhttps://sites.google.com/feeds/activity/site/siteName/7