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