예제 #1
0
func main() {
	fmt.Println("Game of Lists")

	// Game setup
	fmt.Print("How many players? ")
	totalPlayers := 0
	_, err := fmt.Scanf("%d", &totalPlayers)
	if err != nil {
		fmt.Println(err)
	}
	scorecard := Game{list.Init(), make([]Player, totalPlayers), 0}
	name := ""
	for i := 0; i < totalPlayers; i++ {
		fmt.Printf("Player %v's name: ", i+1)
		_, err := fmt.Scanf("%v", &name)
		if err != nil {
			fmt.Println(err)
		}
		scorecard.AddPlayer(name, i)
	}
	fmt.Println(scorecard)
	topscore := 0
	fmt.Print("Play up too? ")
	_, err = fmt.Scanf("%d", &topscore)
	if err != nil {
		fmt.Println(err)
	}
	scorecard.topScore = topscore

	scorecard.Play()
}
예제 #2
0
파일: main.go 프로젝트: oswystan/studygo
//==================================================
// env GODEBUG=gctrace=1,schedtrace=1000 ./grammar
//
// even one struct{xxx} nested into another struct{xxx} the gc can
// collect the memory too.
//==================================================
func memory() {
	type stdata struct {
		data [64 * 1024]byte
	}
	type stmemory struct {
		used int
		data *stdata
	}

	list := list.New()
	i := 0
	for {
		c := new(stmemory)
		d := new(stdata)
		c.data = d
		list.PushBack(c)
		time.Sleep(10 * time.Millisecond)
		if c == nil {
			break
		}
		i++
		if i%1024 == 0 {
			i = 0
			//this will cause gc to collect memory to the minimal size
			fmt.Printf("do list init\n")
			list.Init()
		}
	}
}
예제 #3
0
func (txs *txStore) Abort(tx string) error {
	if list, ok := txs.transactions[tx]; ok {
		list.Init()
		delete(txs.transactions, tx)
		return nil
	}
	return txUnknown
}
예제 #4
0
func expandClass(regex []int) string {
	list := New()
	list.Init()
	nextEscape := false
	escaped := false
	var toDelete *Element
	for reg_index := 0; reg_index < len(regex); reg_index++ {
		escaped = nextEscape
		nextEscape = false
		switch regex[reg_index] {
		case '\\':
			if escaped {
				escaped = false
				list.PushBack(int('\\'))
				toDelete = nil
			} else {
				nextEscape = true
				toDelete = list.PushBack(int('\\'))
			}
			break
		case '-':
			if escaped {
				escaped = false
				list.PushBack(int('-'))
				toDelete.Value = Delete
			} else {
				if reg_index > 0 && reg_index < len(regex)-1 {
					start := regex[reg_index-1]
					end := uint8(regex[reg_index+1])
					for char := uint8(start + 1); char < end; char++ {
						list.PushBack(int(char))
					}
				} else {
					//ERROR
					fmt.Println("invalid character class")
				}
			}
			break
		default:
			list.PushBack(regex[reg_index])
			break
		}
	}
	for e := list.Front(); e != nil; e = e.Next() {
		if e.Value.(int) == Delete {
			list.Remove(e)
		}
	}
	out := string(list.Remove(list.Front()).(int))
	for e := list.Front(); e != nil; e = e.Next() {
		out += string('|')
		out += string(e.Value.(int))
	}
	return out
}