Check-in [9f5054e305]
Overview
SHA1:9f5054e305b33a4e99e54809a6a31dd1e6bba890
Date: 2014-12-30 15:01:38
User: spaskalev
Comment:Minor opmitization to fibonacci's decoding. Changed plaindiff to show line numbers starting from 1.
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | folders | manifest
Tags And Properties
Context
2014-12-30
22:59
[ffb139e305] Dropped the Nth method and return a populated slice by fibonacci.New(size). Changed all access to direct indexing. CC at 100% (user: spaskalev, tags: trunk)
15:01
[9f5054e305] Minor opmitization to fibonacci's decoding. Changed plaindiff to show line numbers starting from 1. (user: spaskalev, tags: trunk)
14:03
[7a1684ea05] Added encoding/fibonacci (cc: 100%) (user: spaskalev, tags: trunk)
Changes

Modified src/0dev.org/commands/plaindiff/main.go from [b2d6e402f0] to [98fd531468].

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
	gen := source(result)
	out := bufio.NewWriter(os.Stdout)
	for have, added, mark := gen(); have; have, added, mark = gen() {
		var from []line = hd.line(!added)

		fmt.Fprintln(out)
		for i := mark.From; i < mark.Length; i++ {
			fmt.Fprint(out, i)
			if added {
				fmt.Fprint(out, " > ")
			} else {
				fmt.Fprint(out, " < ")
			}
			fmt.Fprintln(out, from[i].text)
		}







|







29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
	gen := source(result)
	out := bufio.NewWriter(os.Stdout)
	for have, added, mark := gen(); have; have, added, mark = gen() {
		var from []line = hd.line(!added)

		fmt.Fprintln(out)
		for i := mark.From; i < mark.Length; i++ {
			fmt.Fprint(out, i+1) // Line numbers start from 1 for most people :)
			if added {
				fmt.Fprint(out, " > ")
			} else {
				fmt.Fprint(out, " < ")
			}
			fmt.Fprintln(out, from[i].text)
		}

Modified src/0dev.org/encoding/fibonacci/fib.go from [bab2f5c2b7] to [36b31aa589].

53
54
55
56
57
58
59

60
61
62






63
64
65
66
67
68
	return
}

// Returns an integer from a fibonacci code as specified in the package doc.
func (f Numbers) Decode(value uint64) (result uint64) {
	i := 1
	for (value & 3) != 3 {

		if (value & 1) == 1 {
			result += f.Nth(i)
		}






		value >>= 1
		i++
	}
	result += f.Nth(i) - 1
	return
}







>


|
>
>
>
>
>
>






53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
	return
}

// Returns an integer from a fibonacci code as specified in the package doc.
func (f Numbers) Decode(value uint64) (result uint64) {
	i := 1
	for (value & 3) != 3 {
		// Add the fibonacci number for the current bit if it is raised
		if (value & 1) == 1 {
			result += f.Nth(i)

			// We know that the next bit cannot be raised by Zeckendorf's theorem
			value >>= 2
			i += 2
			continue
		}

		value >>= 1
		i++
	}
	result += f.Nth(i) - 1
	return
}