Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

34
LINES

< > BotCompany Repo | #1034542 // LexicographicIterator

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (5631L/31K).

1  
srecord noeq LexicographicIterator(S alphabet) extends ItIt<S> {
2  
  new IntBuffer l;
3  
  
4  
  *(S *alphabet, int minLength) {
5  
    repeat minLength { l.add(0); }
6  
  }
7  
  
8  
  public bool hasNext() {
9  
    ret true; // haha!
10  
  }
11  
  
12  
  public S next() {
13  
    S s = makeString();
14  
    int i = 0;
15  
    while (i < l(l)) {
16  
      int n = l.get(i);
17  
      if (n+1 < l(alphabet)) {
18  
        l.set(i, n+1);
19  
        break;
20  
      }
21  
      l.set(i++, 0);
22  
    }
23  
    if (i >= l(l)) l.add(0);
24  
    ret s;
25  
  }
26  
  
27  
  S makeString() {
28  
    int n = l(l);
29  
    char[] chars = new[n];
30  
    for i to n:
31  
      chars[i] = alphabet.charAt(l.get(i));
32  
    ret str(chars);
33  
  }
34  
}

Author comment

Began life as a copy of #1004581

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1034542
Snippet name: LexicographicIterator
Eternal ID of this version: #1034542/2
Text MD5: dc4b9e3bc65ff8de05f7bf5ac532fdcf
Transpilation MD5: cf6896d60e8da81a8ca145cb7a9606e4
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-02-11 21:53:20
Source code size: 658 bytes / 34 lines
Pitched / IR pitched: No / No
Views / Downloads: 138 / 229
Version history: 1 change(s)
Referenced in: [show references]