Mercurial > gemma
comparison pkg/common/delta.go @ 5710:37c8feeecb4d
Merged branch sr-v2 into default.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 20 Feb 2024 21:28:56 +0100 |
parents | 3bc15e38c7e8 |
children |
comparison
equal
deleted
inserted
replaced
5672:b1a10654bf0f | 5710:37c8feeecb4d |
---|---|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 | |
2 // without warranty, see README.md and license for details. | |
3 // | |
4 // SPDX-License-Identifier: AGPL-3.0-or-later | |
5 // License-Filename: LICENSES/AGPL-3.0.txt | |
6 // | |
7 // Copyright (C) 2024 by via donau | |
8 // – Österreichische Wasserstraßen-Gesellschaft mbH | |
9 // Software engineering by Intevation GmbH | |
10 // | |
11 // Author(s): | |
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> | |
13 | |
14 package common | |
15 | |
16 // Delta returns a function which returns its argument when called | |
17 // the first time and the delta to the last call afterwards. | |
18 func Delta() func(int64) int64 { | |
19 var last int64 | |
20 return func(x int64) (y int64) { | |
21 y = x - last | |
22 last = x | |
23 return | |
24 } | |
25 } | |
26 | |
27 // InvDelta is the inverse function to Delta. A sequence of numbers | |
28 // fed into the function generated by InvDelta restores | |
29 // the values fed into the function generated by Delta. | |
30 func InvDelta() func(int64) int64 { | |
31 var last int64 | |
32 return func(x int64) (y int64) { | |
33 y = x + last | |
34 last = y | |
35 return | |
36 } | |
37 } |