Giter Club home page Giter Club logo

permutate's People

Contributors

mmstick avatar swfsql avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

permutate's Issues

Tuples feature

Hello mmstick, thanks for this crate!
I started to adapt it for the tuples usage and it is "usable" for now. But still 100% behind the remaining features and documentation, let alone the binary and benchmarking.

In any case, I'll be happy to point you for this feature. I intend to PR whenever it's eventually ready.
Best regards,

fork: https://github.com/swfsql/permutate

Permutator repeats elements

I'm using Permutator like this:

let list: &[&[&i32]] = &[&[&0, &1, &2]];
let permutator = Permutator::new(&list);

for permutation in permutator {
    println!("permutation: {:?}", permutation);
}

Result is:

permutation: [0, 0, 0]
permutation: [0, 0, 1]
permutation: [0, 0, 2]
permutation: [0, 1, 0]
permutation: [0, 1, 1]
permutation: [0, 1, 2]
permutation: [0, 2, 0]
permutation: [0, 2, 1]
permutation: [0, 2, 2]
permutation: [1, 0, 0]
permutation: [1, 0, 1]
permutation: [1, 0, 2]
permutation: [1, 1, 0]
permutation: [1, 1, 1]
permutation: [1, 1, 2]
permutation: [1, 2, 0]
permutation: [1, 2, 1]
permutation: [1, 2, 2]
permutation: [2, 0, 0]
permutation: [2, 0, 1]
permutation: [2, 0, 2]
permutation: [2, 1, 0]
permutation: [2, 1, 1]
permutation: [2, 1, 2]
permutation: [2, 2, 0]
permutation: [2, 2, 1]
permutation: [2, 2, 2]

Numbers should not be repeated, that's combinations instead of permutations. Is it possible to just obtain an iterator where elements are just permutated between one another?

Expected output is:

permutation: [0, 1, 2]
permutation: [0, 2, 1]
permutation: [1, 0, 2]
permutation: [1, 2, 0]
permutation: [2, 0, 1]
permutation: [2, 1, 0]

A shared buffer instead of generating a new Vec every time

The current Iterator::next impl returns a new Vec for every iteration.

It would be nice if there was also an API like fn next(output: &mut [T]) -> bool that populated the given output buffer with the values of the next iteration, and returned false at the end of iteration.

The closest analogy to this in the stdlib is std::io::Read::read, although that's only for u8 buffers.

Setting the permutation iteration?

I was referred to your crate for handling permutations but have been told if I want the 36th permutation for example, the iterator would likely calculate every permutation up until that point? Would it be possible to support avoiding that?

Use case is for permutating long strings with various rules, if I calculate the first 10 trillion permutations and terminate the program, as long as I had the current iteration number it should be possible to provide that to resume progress on my permutations when running the program again and providing the iteration number? It would be nice not to do all that processing if it can be avoided :)

Example of how I'd assume it might be approached. A string with the length of 3 where the first two elements are "a" ... "z" and the third 0 ... 9. I'd have aa0, aa1 and so forth, if I wanted the 36th permutation it'd would probably do something like:

// Gets the individual index per permutation char representing a string
fn permutation_index(element_sizes:Vec<u32>, index:u32) -> Vec<usize> {
    let mut r = element_sizes.iter().rev().scan(index, |x, y|
        if *x == 0 { None } else {
            let (div, rem) = (*x / y, *x % y);
            *x = div;
            Some(rem as usize)
        }
    ).collect::<Vec<usize>>();
    // flip the order back to the original direction
    r.reverse();
    r
}


fn main() {
    // [a...z, a...z, 0...9], [0, 0, 0] == "aa0", [0, 0, 1] == "aa1"
    let element_sizes = vec![26, 26, 10];
    let nth_permutation = 36;
    
    let index = permutation_index(element_sizes, nth_permutation);
    
    // [3, 6] "ad6"
    println!("done {:?}", index);
}

Some users on IRC suggested:

This crate could benefit from specializing Iterator::nth().

You could add a #[derive(serialize, deserialze)] on your Iterator, save it and open it whenever you need


Technically for my case, it might make more sense to just provide the iteration value such as "ad6" or it's index [3, 6] or [0, 3, 6] depending on what works better for your crate.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.