当前位置: 首页>>代码示例>>Golang>>正文


Golang types.Int函数代码示例

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


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

示例1: TestMapSetIterators

func TestMapSetIterators(x *testing.T) {
	t := (*T)(x)
	SIZE := 100
	set := NewMapSet(NewSortedSet(10))
	for i := 0; i < SIZE; i++ {
		item := &types.MapEntry{types.Int(rand.Intn(1000)), types.Int(rand.Intn(1000))}
		t.assert_nil(set.Put(item.Key, item.Value))
	}
	item, items := set.Items()()
	key, keys := set.Keys()()
	for items != nil && keys != nil {
		if !item.(*types.MapEntry).Key.Equals(key) {
			t.Fatal("item != key")
		}
		item, items = items()
		key, keys = keys()
	}
	t.assert("uneven iteration", items == nil && keys == nil)
	item, items = set.Items()()
	val, vals := set.Values()()
	for items != nil && vals != nil {
		if !item.(*types.MapEntry).Value.(types.Int).Equals(val.(types.Int)) {
			t.Fatal("item != key")
		}
		item, items = items()
		val, vals = vals()
	}
	t.assert("uneven iteration", items == nil && keys == nil)
}
开发者ID:jmptrader,项目名称:data-structures,代码行数:29,代码来源:mapset_test.go

示例2: TestAddHasDeleteRandom

func TestAddHasDeleteRandom(x *testing.T) {
	t := (*T)(x)
	SIZE := 100
	set := NewSortedSet(10)
	items := make([]types.Int, 0, SIZE)
	for i := 0; i < SIZE; i++ {
		item := types.Int(rand.Intn(1000))
		for set.Has(item) {
			item = types.Int(rand.Intn(1000))
		}
		items = append(items, item)
		t.assert_nil(set.Add(item))
	}
	for i, item := range items {
		t.assert(fmt.Sprintf("i %v, !set.Has(item)", i), set.Has(item))
	}
	for i := 0; i < 10; i++ {
		item, err := set.Random()
		t.assert_nil(err)
		t.assert(fmt.Sprintf("!set.Has(item)", i), set.Has(item))
	}
	for _, item := range items {
		t.assert_nil(set.Delete(item))
	}
	for i, item := range items {
		t.assert(fmt.Sprintf("i %v, !set.Has(item)", i), !set.Has(item))
	}
	_, err := set.Random()
	t.assert(fmt.Sprintf("err == nil"), err != nil)
	t.assert_nil(set.Add(types.Int(1)))
	item, err := set.Random()
	t.assert_nil(err)
	t.assert(fmt.Sprintf("item == 1"), item.Equals(types.Int(1)))
}
开发者ID:jmptrader,项目名称:data-structures,代码行数:34,代码来源:sortedset_test.go

示例3: Test_put_no_root_split

func Test_put_no_root_split(t *testing.T) {
	a := NewLeaf(2, false)
	if err := a.put_kv(types.Int(1), 1); err != nil {
		t.Error(err)
	}
	p, err := a.put(types.Int(1), 2)
	if err != nil {
		t.Error(err)
	} else {
		if p != a {
			t.Errorf("p != a")
		}
		if !p.has(types.Int(1)) {
			t.Error("p didn't have the right keys", p)
		}
	}
	p, err = a.put(types.Int(1), 3)
	if err != nil {
		t.Error(err)
	} else {
		if p != a {
			t.Errorf("p != a")
		}
		if !p.has(types.Int(1)) {
			t.Error("p didn't have the right keys", p)
		}
		if p.next == nil {
			t.Error("p.next should not be nil")
		}
		t.Log(p)
		t.Log(p.next)
	}
}
开发者ID:roger2000hk,项目名称:data-structures,代码行数:33,代码来源:bptree_test.go

示例4: TestMapSetAddHasDeleteRandom

func TestMapSetAddHasDeleteRandom(x *testing.T) {
	t := (*T)(x)
	SIZE := 100
	a := NewMapSet(NewSortedSet(10))
	items := make([]*types.MapEntry, 0, SIZE)
	for i := 0; i < SIZE; i++ {
		item := &types.MapEntry{types.Int(rand.Intn(1000)), types.Int(rand.Intn(1000))}
		for a.Has(item) {
			item = &types.MapEntry{types.Int(rand.Intn(1000)), types.Int(rand.Intn(1000))}
		}
		items = append(items, item)
		t.assert_nil(a.Add(item))
	}
	set := NewMapSet(NewSortedSet(10))
	t.assert_nil(set.Extend(a.Items()))
	t.assert("set == a", set.Equals(a))
	for i, item := range items {
		thing, err := set.Item(item)
		t.assert_nil(err)
		t.assert(fmt.Sprintf("i %v, thing == item", i), thing.Equals(item))
		t.assert(fmt.Sprintf("i %v, !set.Has(item)", i), set.Has(item))
	}
	for _, item := range items {
		t.assert_nil(set.Delete(item))
	}
	for i, item := range items {
		t.assert(fmt.Sprintf("i %v, !set.Has(item)", i), !set.Has(item))
	}
}
开发者ID:jmptrader,项目名称:data-structures,代码行数:29,代码来源:mapset_test.go

示例5: LoadEdge

func LoadEdge(g *goiso.Graph, vids types.Map, data []byte) (err error) {
	obj, err := ParseJson(data)
	if err != nil {
		return err
	}
	_src, err := obj["src"].(json.Number).Int64()
	if err != nil {
		return err
	}
	_targ, err := obj["targ"].(json.Number).Int64()
	if err != nil {
		return err
	}
	src := int(_src)
	targ := int(_targ)
	label := strings.TrimSpace(obj["label"].(string))
	if o, err := vids.Get(types.Int(src)); err != nil {
		return err
	} else {
		u := o.(*goiso.Vertex)
		if o, err := vids.Get(types.Int(targ)); err != nil {
			return err
		} else {
			v := o.(*goiso.Vertex)
			g.AddEdge(u, v, label)
		}
	}
	return nil
}
开发者ID:timtadh,项目名称:graple,代码行数:29,代码来源:graph.go

示例6: TestFixedSorted

func TestFixedSorted(x *testing.T) {
	t := (*T)(x)
	SIZE := 100
	set := NewFixedSorted(SIZE, false)
	items := make([]types.Int, 0, SIZE)
	for i := 0; i < SIZE; i++ {
		item := types.Int(rand.Intn(1000))
		for set.Has(item) {
			item = types.Int(rand.Intn(1000))
		}
		items = append(items, item)
		t.assert_nil(set.Add(item))
	}
	t.assert(fmt.Sprintf("set.Full() (%v)", set.Full()), set.Full())
	t.assert(fmt.Sprintf("set.Size == %d (%d)", SIZE, set.Size()), set.Size() == SIZE)
	for i, item := range items {
		t.assert(fmt.Sprintf("i %v, !set.Has(item)", i), set.Has(item))
	}
	for _, item := range items {
		t.assert_nil(set.Delete(item))
	}
	for i, item := range items {
		t.assert(fmt.Sprintf("i %v, !set.Has(item)", i), !set.Has(item))
	}
}
开发者ID:jmptrader,项目名称:data-structures,代码行数:25,代码来源:fixed_test.go

示例7: TestMapSetMapFunc

func TestMapSetMapFunc(x *testing.T) {
	t := (*T)(x)
	SIZE := 100
	set := types.Map(NewMapSet(NewSortedSet(10)))
	items := make([]*types.MapEntry, 0, SIZE)
	for i := 0; i < SIZE; i++ {
		item := &types.MapEntry{types.Int(rand.Intn(1000)), types.Int(rand.Intn(1000))}
		for set.Has(item.Key) {
			item = &types.MapEntry{types.Int(rand.Intn(1000)), types.Int(rand.Intn(1000))}
		}
		items = append(items, item)
		t.assert_nil(set.Put(item.Key, item.Value))
	}
	for i, item := range items {
		t.assert(fmt.Sprintf("i %v, !set.Has(item, %v)", i, item), set.Has(item.Key))
	}
	t.assert("size == 100", set.Size() == 100)
	for _, item := range items {
		rm, err := set.Remove(item.Key)
		t.assert_nil(err)
		t.assert("item == rm", item.Value.(types.Int).Equals(rm.(types.Int)))
	}
	for i, item := range items {
		t.assert(fmt.Sprintf("i %v, set.Has(item)", i), !set.Has(item.Key))
	}
}
开发者ID:jmptrader,项目名称:data-structures,代码行数:26,代码来源:mapset_test.go

示例8: TestSubtract

func TestSubtract(x *testing.T) {
	t := (*T)(x)
	a := FromSlice([]types.Hashable{types.Int(0), types.Int(1), types.Int(2), types.Int(3)})
	b := FromSlice([]types.Hashable{types.Int(1), types.Int(2), types.Int(4)})
	c := FromSlice([]types.Hashable{types.Int(0), types.Int(3)})
	d := FromSlice([]types.Hashable{types.Int(4)})
	t.assert("a - b == c", t.assert_set(a.Subtract(b)).Equals(c))
	t.assert("b - a == d", t.assert_set(b.Subtract(a)).Equals(d))
}
开发者ID:jmptrader,项目名称:data-structures,代码行数:9,代码来源:sortedset_test.go

示例9: Test_leaf_split_equal

func Test_leaf_split_equal(t *testing.T) {
	a := NewLeaf(3, false)
	insert_linked_list_node(a, nil, nil)
	if err := a.put_kv(types.Int(1), 1); err != nil {
		t.Error(err)
	}
	if err := a.put_kv(types.Int(3), 3); err != nil {
		t.Error(err)
	}
	if err := a.put_kv(types.Int(5), 5); err != nil {
		t.Error(err)
	}
	p, q, err := a.leaf_split(types.Int(3), 2)
	if err != nil {
		t.Error(err)
	} else {
		if p != a {
			t.Errorf("p != a")
		}
		if q == nil {
			t.Errorf("q == nil")
		}
		if !p.has(types.Int(1)) {
			t.Error("p didn't have the right keys", p)
		}
		if !q.has(types.Int(3)) || q.count(types.Int(3)) != 2 || !q.has(types.Int(5)) {
			t.Error("q didn't have the right keys", q, q.count(types.Int(3)))
		}
	}
}
开发者ID:roger2000hk,项目名称:data-structures,代码行数:30,代码来源:bptree_test.go

示例10: Test_internal_insert_split_less

func Test_internal_insert_split_less(t *testing.T) {
	a := NewInternal(3)
	leaf := NewLeaf(1, false)
	if err := leaf.put_kv(types.Int(1), 1); err != nil {
		t.Error(err)
	}
	if err := a.put_kp(types.Int(1), leaf); err != nil {
		t.Error(err)
	}
	if err := a.put_kp(types.Int(3), nil); err != nil {
		t.Error(err)
	}
	if err := a.put_kp(types.Int(5), nil); err != nil {
		t.Error(err)
	}
	p, q, err := a.internal_insert(types.Int(2), nil)
	if err != nil {
		t.Error(err)
	} else {
		if p != a {
			t.Errorf("p != a")
		}
		if q == nil {
			t.Errorf("q == nil")
		}
		if !p.has(types.Int(1)) || !p.has(types.Int(2)) {
			t.Error("p didn't have the right keys", p)
		}
		if !q.has(types.Int(3)) || !q.has(types.Int(5)) {
			t.Error("q didn't have the right keys", q)
		}
	}
}
开发者ID:roger2000hk,项目名称:data-structures,代码行数:33,代码来源:bptree_test.go

示例11: digraphLabelset

func digraphLabelset(n *digraph.EmbListNode) (types.Set, error) {
	p := n.Pat
	s := set.NewSortedSet(len(p.V) + len(p.E))
	for i := range p.V {
		s.Add(types.Int(p.V[i].Color))
	}
	for i := range p.E {
		s.Add(types.Int(p.E[i].Color))
	}
	return s, nil
}
开发者ID:timtadh,项目名称:sfp,代码行数:11,代码来源:dbscan.go

示例12: extensionsFromEmbeddings

func extensionsFromEmbeddings(dt *Digraph, pattern *subgraph.SubGraph, ei subgraph.EmbIterator, seen map[int]bool) (total int, overlap []map[int]bool, fisEmbs []*subgraph.Embedding, sets []*hashtable.LinearHash, exts types.Set) {
	if dt.Mode&FIS == FIS {
		seen = make(map[int]bool)
		fisEmbs = make([]*subgraph.Embedding, 0, 10)
	} else {
		sets = make([]*hashtable.LinearHash, len(pattern.V))
	}
	if dt.Mode&OverlapPruning == OverlapPruning {
		overlap = make([]map[int]bool, len(pattern.V))
	}
	exts = set.NewSetMap(hashtable.NewLinearHash())
	add := validExtChecker(dt, func(emb *subgraph.Embedding, ext *subgraph.Extension) {
		exts.Add(ext)
	})
	for emb, next := ei(false); next != nil; emb, next = next(false) {
		seenIt := false
		for idx, id := range emb.Ids {
			if fisEmbs != nil {
				if seen[id] {
					seenIt = true
				}
			}
			if overlap != nil {
				if overlap[idx] == nil {
					overlap[idx] = make(map[int]bool)
				}
				overlap[idx][id] = true
			}
			if seen != nil {
				seen[id] = true
			}
			if sets != nil {
				if sets[idx] == nil {
					sets[idx] = hashtable.NewLinearHash()
				}
				set := sets[idx]
				if !set.Has(types.Int(id)) {
					set.Put(types.Int(id), emb)
				}
			}
			for _, e := range dt.G.Kids[id] {
				add(emb, &dt.G.E[e], idx, -1)
			}
			for _, e := range dt.G.Parents[id] {
				add(emb, &dt.G.E[e], -1, idx)
			}
		}
		if fisEmbs != nil && !seenIt {
			fisEmbs = append(fisEmbs, emb)
		}
		total++
	}
	return total, overlap, fisEmbs, sets, exts
}
开发者ID:timtadh,项目名称:sfp,代码行数:54,代码来源:extensions.go

示例13: Test_internal_split_greater

func Test_internal_split_greater(t *testing.T) {
	a := NewInternal(3)
	if err := a.put_kp(types.Int(1), nil); err != nil {
		t.Error(err)
	}
	if err := a.put_kp(types.Int(3), nil); err != nil {
		t.Error(err)
	}
	if err := a.put_kp(types.Int(5), nil); err != nil {
		t.Error(err)
	}
	p, q, err := a.internal_split(types.Int(4), nil)
	if err != nil {
		t.Error(err)
	} else {
		if p != a {
			t.Errorf("p != a")
		}
		if q == nil {
			t.Errorf("q == nil")
		}
		if !p.has(types.Int(1)) {
			t.Error("p didn't have the right keys", p)
		}
		if !q.has(types.Int(3)) || !q.has(types.Int(4)) || !q.has(types.Int(5)) {
			t.Error("q didn't have the right keys", q)
		}
	}
}
开发者ID:roger2000hk,项目名称:data-structures,代码行数:29,代码来源:bptree_test.go

示例14: TestSortedAddMarshalUnmarshalGet

func TestSortedAddMarshalUnmarshalGet(x *testing.T) {
	t := (*T)(x)
	SIZE := 100
	list := NewSorted(10, false)
	items := make([]types.Int, 0, SIZE)
	for i := 0; i < SIZE; i++ {
		item := types.Int(rand.Intn(10) + 1)
		items = append(items, item)
		t.assert_nil(list.Add(item))
	}
	for _, item := range items {
		i, has, err := list.Find(item)
		t.assert("has", has)
		t.assert_nil(err)
		lg, err := list.Get(i)
		t.assert_nil(err)
		t.assert(fmt.Sprintf("i %v, items[i] == list.Get(i), %v, %v", i, item, lg), lg.Equals(item))
	}
	marshal, unmarshal := types.IntMarshals()
	mlist1 := NewMSorted(list, marshal, unmarshal)
	bytes, err := mlist1.MarshalBinary()
	t.assert_nil(err)
	mlist2 := &MSorted{MList: MList{MarshalItem: marshal, UnmarshalItem: unmarshal}, AllowDups: false}
	t.assert_nil(mlist2.UnmarshalBinary(bytes))
	list2 := mlist2.Sorted()
	for _, item := range items {
		i, has, err := list2.Find(item)
		t.assert("has", has)
		t.assert_nil(err)
		lg, err := list2.Get(i)
		t.assert_nil(err)
		t.assert(fmt.Sprintf("i %v, items[i] == list.Get(i), %v, %v", i, item, lg), lg.Equals(item))
	}
}
开发者ID:jmptrader,项目名称:data-structures,代码行数:34,代码来源:sorted_test.go

示例15: LoadVertex

func LoadVertex(g *goiso.Graph, supportAttr string, vids types.Map, nodeAttrs *bptree.BpTree, supportAttrs map[int]string, data []byte) (err error) {
	obj, err := ParseJson(data)
	if err != nil {
		return err
	}
	_id, err := obj["id"].(json.Number).Int64()
	if err != nil {
		return err
	}
	label := strings.TrimSpace(obj["label"].(string))
	id := int(_id)
	vertex := g.AddVertex(id, label)
	err = vids.Put(types.Int(id), vertex)
	if err != nil {
		return err
	}
	if nodeAttrs != nil {
		bid := make([]byte, 4)
		binary.BigEndian.PutUint32(bid, uint32(vertex.Idx))
		err = nodeAttrs.Add(bid, data)
		if err != nil {
			return err
		}
		if supportAttr != "" {
			if _, has := obj[supportAttr]; !has {
				return fmt.Errorf("vertex did not have required supportAttr %v\n%v", supportAttr, string(data))
			}
			supportAttrs[vertex.Idx] = obj[supportAttr].(string)
		}
	}
	return nil
}
开发者ID:timtadh,项目名称:graple,代码行数:32,代码来源:graph.go


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