Example #1
0
func mostRecent(l *list.List, val int) {

	for e := l.Front(); e != nil; e = e.Next() {
		if e.Value == val {
			l.MoveToFront(e)
			break
		}
	}
}
Example #2
0
File: lst.go Project: tgrijalva/lst
func bmp(l *list.List, args []string) {
	switch len(args) {
	case 0:
		fmt.Println("What item do you want to bump?")
		os.Exit(1)
	case 1:
		// Check if first arg is int
		n, err := strconv.Atoi(args[0])
		if err != nil {
			fmt.Printf("%q is not an item number.\n", args[0])
			os.Exit(1)
		}

		// Make suer (n) > 1
		if n < 1 {
			fmt.Printf("%q is not an item number.\n", args[0])
			os.Exit(1)
		} else if n == 1 {
			fmt.Println("Can't bump first item.")
			os.Exit(1)
		} else if n > l.Len() {
			fmt.Printf("item [%d] is out of bounds.\n", n)
			os.Exit(1)
		}

		// Bump item (n)
		// Grab item n
		itemNumber, element := 1, l.Front()
		for itemNumber < n {
			element = element.Next()
			itemNumber++
		}

		// Update date
		element.Value.(ListItem)[DATE] = time.Now().Format(DATE_FORMAT)

		// Move it to the front
		l.MoveToFront(element)
		fmt.Printf("Bumping item [%d]\n", n)

	default:
		fmt.Println("Too many arguments.")
		os.Exit(1)
	}
}
Example #3
0
func main() {
	var l *list.List
	l = list.New()

	a := &A{123}

	m := uint64(uint32(2<<16) * uint32(2<<13))
	e := uint64(2 << 29)

	fmt.Printf("m = e || %v = %v\n", m, e)

	fmt.Printf("\nBack: %v\n", l.Back())

	fmt.Println("\ntry move to front with nil...")
	l.MoveToFront((*list.Element)(a))

	fmt.Println("\ntry removing nil from list...")
	l.Remove(nil)
}