forked from emer/emergent
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix James' drift PR, add ringidx.FIx fixed len ring index, add rest o…
…f random distributions based on gonum distuv funs
- Loading branch information
Randall C. O'Reilly
committed
Apr 15, 2021
1 parent
b91438e
commit 16a70c9
Showing
4 changed files
with
59 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (c) 2019, The Emergent Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package ringidx | ||
|
||
// FIx is a fixed-length ring index structure -- does not grow | ||
// or shrink dynamically. | ||
type FIx struct { | ||
Zi int `desc:"the zero index position -- where logical 0 is in physical buffer"` | ||
Len int `desc:"the length of the buffer -- wraps around at this modulus"` | ||
} | ||
|
||
// Idx returns the physical index of the logical index i. | ||
// i must be < Len. | ||
func (fi *FIx) Idx(i int) int { | ||
i += fi.Zi | ||
if i >= fi.Len { | ||
i -= fi.Len | ||
} | ||
return i | ||
} | ||
|
||
// IdxIsValid returns true if given index is valid: >= 0 and < Len | ||
func (fi *FIx) IdxIsValid(i int) bool { | ||
return i >= 0 && i < fi.Len | ||
} | ||
|
||
// Shift moves the zero index up by n. | ||
func (fi *FIx) Shift(n int) { | ||
fi.Zi = fi.Idx(n) | ||
} |