• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang golang-set.NewSetFromSlice函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/deckarep/golang-set.NewSetFromSlice函数的典型用法代码示例。如果您正苦于以下问题:Golang NewSetFromSlice函数的具体用法?Golang NewSetFromSlice怎么用?Golang NewSetFromSlice使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewSetFromSlice函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: TestDiff

func TestDiff(t *testing.T) {
	existing := mapset.NewSetFromSlice([]interface{}{"1.1.1.1", "2.2.2.2"})
	addedIP := "3.3.3.3"
	updated := existing.Clone()
	updated.Add(addedIP)

	added, removed := diff(existing, updated)
	if len(added) != 1 {
		t.Fatalf("Diff failed for an Add update. Expecting 1 element, but got %d elements", len(added))
	}
	if added[0].String() != addedIP {
		t.Fatalf("Expecting : %v, Got : %v", addedIP, added[0])
	}
	if len(removed) > 0 {
		t.Fatalf("Diff failed for remove use-case. Expecting 0 element, but got %d elements", len(removed))
	}

	updated = mapset.NewSetFromSlice([]interface{}{addedIP})
	added, removed = diff(existing, updated)
	if len(removed) != 2 {
		t.Fatalf("Diff failed for a remove update. Expecting 2 element, but got %d elements", len(removed))
	}
	if len(added) != 1 {
		t.Fatalf("Diff failed for add use-case. Expecting 1 element, but got %d elements", len(added))
	}
}
开发者ID:YujiOshima,项目名称:libnetwork,代码行数:26,代码来源:hostdiscovery_test.go


示例2: FindNames

func FindNames(db_collections []string, provided_collections []string) ([]string, error) {
	if len(provided_collections) < 1 {
		return db_collections, nil
	} else {
		db_collections_i := make([]interface{}, len(db_collections))
		provided_collections_i := make([]interface{}, len(provided_collections))

		for i, v := range db_collections {
			db_collections_i[i] = v
		}

		for i, v := range provided_collections {
			provided_collections_i[i] = v
		}

		db_set := set.NewSetFromSlice(db_collections_i)
		provided_set := set.NewSetFromSlice(provided_collections_i)
		result_set := db_set.Intersect(provided_set)

		result_collection := make([]string, len(result_set.ToSlice()))

		for i, v := range result_set.ToSlice() {
			result_collection[i] = v.(string)
		}

		return result_collection, nil
	}
}
开发者ID:Talkdesk,项目名称:seed,代码行数:28,代码来源:mongo_target.go


示例3: main

func main() {
	//note that the set accepts []interface{}
	X := []interface{}{10, 12, 12, 12, 13}
	Y := []interface{}{12, 14, 15}

	Sx := set.NewSetFromSlice(X)
	Sy := set.NewSetFromSlice(Y)
	result1 := Sx.Difference(Sy)
	result2 := Sy.Difference(Sx)

	fmt.Println(result1)
	fmt.Println(result2)
}
开发者ID:suntong,项目名称:lang,代码行数:13,代码来源:Set-Go_Diff.go


示例4: ToSet

func ToSet(strings []string) set.Set {
	// First convert to array of []interface{} .. yikes!
	generics := make([]interface{}, len(strings))
	for i, v := range strings {
		generics[i] = v
	}

	return set.NewSetFromSlice(generics)
}
开发者ID:yosiat,项目名称:npm-downloader,代码行数:9,代码来源:set.go


示例5: Test_Regex

func (suite *StatsTestSuite) Test_Regex() {
	// We'll make a new client with actual regexps.
	pageViewRegexes := make([]map[string]string, 0)
	httpsRequestRegexes := []map[string]string{make(map[string]string), make(map[string]string)}
	httpsRequestRegexes[0]["regex"] = `^[a-z0-9\.]*\.(example\.com)$`
	httpsRequestRegexes[0]["replace"] = "$1"
	httpsRequestRegexes[1]["regex"] = `^.*example\.org$`
	httpsRequestRegexes[1]["replace"] = "replacement"
	regexps, _ := MakeRegexps(pageViewRegexes, httpsRequestRegexes)

	suite.httpClient = &http.Client{
		Transport: &http.Transport{
			Dial: makeStatsDialer(_SERVER_ID, regexps),
		},
	}

	// Using both HTTP and HTTPS will help us to exercise both methods of hostname parsing
	for _, scheme := range []string{"http", "https"} {
		// No subdomain, so won't match regex
		url := fmt.Sprintf("%s://example.com/index.html", scheme)
		resp, err := suite.httpClient.Get(url)
		suite.Nil(err)
		resp.Body.Close()

		// Will match the first regex
		url = fmt.Sprintf("%s://www.example.com/index.html", scheme)
		resp, err = suite.httpClient.Get(url)
		suite.Nil(err)
		resp.Body.Close()

		// Will match the second regex
		url = fmt.Sprintf("%s://example.org/index.html", scheme)
		resp, err = suite.httpClient.Get(url)
		suite.Nil(err)
		resp.Body.Close()

		payload := GetForServer(_SERVER_ID)
		suite.NotNil(payload, "should get stats because we made HTTP reqs; %s", scheme)

		expectedHostnames := mapset.NewSet()
		expectedHostnames.Add("(OTHER)")
		expectedHostnames.Add("example.com")
		expectedHostnames.Add("replacement")

		hostnames := make([]interface{}, 0)
		for hostname := range payload.hostnameToStats {
			hostnames = append(hostnames, hostname)
		}

		actualHostnames := mapset.NewSetFromSlice(hostnames)

		suite.Equal(expectedHostnames, actualHostnames, "post-regex hostnames should be processed as expecteds; %s", scheme)
	}
}
开发者ID:Teank,项目名称:psiphon-tunnel-core,代码行数:54,代码来源:transferstats_test.go


示例6: TestNoCallback

func TestNoCallback(t *testing.T) {
	hd := hostDiscovery{}
	hd.nodes = mapset.NewSetFromSlice([]interface{}{"1.1.1.1", "2.2.2.2"})
	update := []*discovery.Entry{{Host: "1.1.1.1", Port: "0"}, {Host: "2.2.2.2", Port: "0"}}

	added := false
	removed := false
	hd.processCallback(update, func() {}, func(hosts []net.IP) { added = true }, func(hosts []net.IP) { removed = true })
	if added || removed {
		t.Fatalf("Not expecting any callback notification. But received a callback")
	}
}
开发者ID:YujiOshima,项目名称:libnetwork,代码行数:12,代码来源:hostdiscovery_test.go


示例7: TestRemovedCallback

func TestRemovedCallback(t *testing.T) {
	hd := hostDiscovery{}
	hd.nodes = mapset.NewSetFromSlice([]interface{}{"1.1.1.1", "2.2.2.2"})
	update := []*discovery.Entry{&discovery.Entry{Host: "1.1.1.1", Port: "0"}}

	added := false
	removed := false
	hd.processCallback(update, func(hosts []net.IP) { added = true }, func(hosts []net.IP) { removed = true })
	if !removed {
		t.Fatalf("Expecting a Removed callback notification. But none received")
	}
}
开发者ID:AlphaStaxLLC,项目名称:libnetwork,代码行数:12,代码来源:hostdiscovery_test.go



注:本文中的github.com/deckarep/golang-set.NewSetFromSlice函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang hdkeychain.ExtendedKey类代码示例发布时间:2022-05-23
下一篇:
Golang doozer.Conn类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap