Skip to content

Instantly share code, notes, and snippets.

// Package xorshift implements a 64-bit version of Marsaglia's xorshift PRNG as
// described in http://www.jstatsoft.org/v08/i14/paper.
// The generator has a period of 2^64-1 and passes most of the tests in the
// dieharder test suit.
package xorshift
// *Xor64Source implements the rand.Source interface from math/rand.
type Xor64Source uint64
// seed0 is used as default seed to initialize the generator.
// how can we do a tree in Rust, where each node
// tells its children to update, and in turn, the
// child may update the parent?
//
// The following example illustrates the technique. Notice how we
// can't let the children have full backpointers to
// parent nodes, and instead have to have them point
// back to parent.data. Otherwise the two paths
// (parent) and (parent->child) overlap, and modifying
// parent could unsafely clobber (parent->child) use.
just a couple of hints as you are learning the language
I do very little with apply. If necessary to process a matrix in row form, as this seems to be doing, I would define a function that did the row transformation, then apply it once.
sort takes the very useful additional parameter index=T, which will return the sorted order, obviating the need to do separate ranking.
For really sophisticated searching of sorted things, there is findInterval, which does binary search. It took me a while to find it in R. But it's incredibly nice. Here's an example of using sort (with i=T), and findInterval together.
# si.sample() :
# put a arbitrarily sampled sequence of events into a regularly sampled line,