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     29   	gen := source(result)
    30     30   	out := bufio.NewWriter(os.Stdout)
    31     31   	for have, added, mark := gen(); have; have, added, mark = gen() {
    32     32   		var from []line = hd.line(!added)
    33     33   
    34     34   		fmt.Fprintln(out)
    35     35   		for i := mark.From; i < mark.Length; i++ {
    36         -			fmt.Fprint(out, i)
           36  +			fmt.Fprint(out, i+1) // Line numbers start from 1 for most people :)
    37     37   			if added {
    38     38   				fmt.Fprint(out, " > ")
    39     39   			} else {
    40     40   				fmt.Fprint(out, " < ")
    41     41   			}
    42     42   			fmt.Fprintln(out, from[i].text)
    43     43   		}

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

    53     53   	return
    54     54   }
    55     55   
    56     56   // Returns an integer from a fibonacci code as specified in the package doc.
    57     57   func (f Numbers) Decode(value uint64) (result uint64) {
    58     58   	i := 1
    59     59   	for (value & 3) != 3 {
           60  +		// Add the fibonacci number for the current bit if it is raised
    60     61   		if (value & 1) == 1 {
    61     62   			result += f.Nth(i)
           63  +
           64  +			// We know that the next bit cannot be raised by Zeckendorf's theorem
           65  +			value >>= 2
           66  +			i += 2
           67  +			continue
    62     68   		}
           69  +
    63     70   		value >>= 1
    64     71   		i++
    65     72   	}
    66     73   	result += f.Nth(i) - 1
    67     74   	return
    68     75   }