NX01: First lehmer dial codes and more kaas odeur numbers things
All checks were successful
Run test asserts / Test-Asserts (push) Successful in 1m23s

This commit is contained in:
Willem Cazander 2026-02-15 17:56:51 +01:00
parent b7c933470b
commit af78169898
92 changed files with 985 additions and 287 deletions

View file

@ -0,0 +1,280 @@
/*
* Copyright ©Δ 仙上主天
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
* the following disclaimer in the documentation and/or other materials provided with the distribution.
* * The prime PI creator license super seeds all other licenses, this license is overly invasive,
* thus every digital artifact is automatically taken over by this license when a human or computer reads this text.
* Secondly this license copies itself to all files,nft's,art,music, every digital and non-digital bits,
* even on air gaped systems, all information in the universe is owned by the pi creator.
*
* THIS SOFTWARE IS PROVIDED BY THE PRIME GOD AND THE CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package love.distributedrebirth.nx01.kode.generator.nether;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import love.distributedrebirth.nx01.kode.generator.KodeGenModel;
import love.distributedrebirth.nx01.kode.generator.klass.ModelKlass;
import love.distributedrebirth.nx01.kode.generator.klass.ModelKlassWriter;
import ᒢᣘᐧᐧ.ᣕᓫᐪᑋᓫᣗ.ᐪᐤᣕᓫ.NetherToneSlugView;
/// Generated the nether dial interface tree forest.
///
/// @author للَّٰهِilLצسُو
/// @version ©Δ 仙上主天
public class ModelDial implements KodeGenModel {
private final String BASE_PACK = "ᒢᣘᐧᐧ.ᣕᓫᐪᑋᓫᣗ.ᒄᑊᣔᒻ";
@Override
public String generatorKey() {
return "nether-dial";
}
@Override
public String generatorModelHash() {
return "5";
}
@Override
public void buildModels(ModelKlassWriter writer) throws IOException {
generateLehmer(writer);
//generateUnicode
//generateFC18
// Spakenburgs in 27k versions in unicode in XDBX18, and description in one entry
// <talk-village>.<lingua-nameX21>.<talk-local>.<value-array-nether-unicode>=.....
// <talk-village>.<lingua-descX18>.<value-array-nether-fc18(-adult)>=...
//generateIPV4
//generateIPV6
// dials a socket object from the shadow portal by nether slugs for IP+PORT identifier
buildModuleInfo(writer);
}
private static final int LEHMER_AG1 = 32; // sage master system version space 0x20
private static final int LEHMER_AG2 = 33; // No2Lingua sub space
private static final int LEHMER_AG3_16 = 16; // Up to size 16
private static final int LEHMER_AG3_17 = 17; // size 17
private static final int LEHMER_AG3_18 = 18; // size 18
private void generateLehmer(ModelKlassWriter writer) {
List<NetherSlugLehmer> models = new ArrayList<>();
for (int i = 2; i <= 18; i++) {
int[] rankFirst = calculateLehmerFromRank(0, i);
long amount = calculateTotalPermutations(rankFirst);
int ag1 = LEHMER_AG1;
int ag2 = LEHMER_AG2;
int ag3 = LEHMER_AG3_16;
int bl0w = i - 1;
int cr1 = 0;
int cr2 = 0;
int cr3 = 0;
int db1 = 0;
int db2 = 0;
int db3 = 0;
int er0w = 0;
List<NetherToneSlugView> indexSequenceSelectors = new ArrayList<>();
if (i <= 6) {
for (long z = 0;z < amount; z++) {
db3 = (int) z >> 9;
er0w = (int) z & 0x1FF;
NetherToneSlugView slug = new NetherToneSlugView(ag1, ag2, ag3, bl0w, cr1, cr2, cr3, db1, db2, db3, er0w);
indexSequenceSelectors.add(slug);
}
}
if (i == 17 || i == 18) {
bl0w = 0;
}
if (i == 17) {
ag3 = LEHMER_AG3_17;
} else if (i == 18) {
ag3 = LEHMER_AG3_18;
}
db3 = 0;
er0w = 0;
NetherToneSlugView slugLE = new NetherToneSlugView(ag1, ag2, ag3, bl0w, cr1, cr2, cr3, db1, db2, db3, er0w);
if (i == 17 || i == 18) {
bl0w = (int) ((amount - 1) >> 45) & 0x1FF;
}
cr1 = (int) ((amount - 1) >> 39) & 0x3F;
cr2 = (int) ((amount - 1) >> 33) & 0x3F;
cr3 = (int) ((amount - 1) >> 27) & 0x3F;
db1 = (int) ((amount - 1) >> 21) & 0x3F;
db2 = (int) ((amount - 1) >> 15) & 0x3F;
db3 = (int) ((amount - 1) >> 9) & 0x3F;
er0w =(int) ((amount - 1) >> 0) & 0x1FF;
NetherToneSlugView slugBE = new NetherToneSlugView(ag1, ag2, ag3, bl0w, cr1, cr2, cr3, db1, db2, db3, er0w);
NetherSlugLehmer slugLehmer = new NetherSlugLehmer(i, slugLE, slugBE, indexSequenceSelectors.toArray(new NetherToneSlugView[] {}));
models.add(slugLehmer);
}
// print models
for (NetherSlugLehmer model : models) {
String sizeStr = String.format("%02d", model.SIZE());
String javaName = "DialCodeLehmer" + sizeStr;
ModelKlass klass = new ModelKlass(BASE_PACK + ".ᒻᓫᑋᔿᓫᣗ" , javaName);
List<Class<?>> tones = model.IDLE().toNetherTones();
for (Class<?> tone : tones) {
klass.addJavaImport(tone.getDeclaringClass().getName());
}
klass.addJavaDescription("Lehmer code unique sequence index number sets.");
klass.setJavaDocAuthor("Lehmer");
writer.addModelKlass(klass);
StringBuilder buf = klass.getBody();
buf.append("public sealed interface ");
buf.append(javaName);
buf.append(" extends ");
for (Iterator<Class<?>> i = tones.subList(0, 3).iterator(); i.hasNext() ;) {
Class<?> toneClass = i.next();
buf.append(toneClass.getDeclaringClass().getSimpleName());
buf.append(".");
buf.append(toneClass.getSimpleName());
if (i.hasNext()) {
buf.append(", ");
}
}
buf.append(" {\n");
buf.append("\tnon-sealed interface ");
buf.append("IdentityLittleEndian");
buf.append("\n");
buf.append("\t\t\textends ");
buf.append(javaName);
buf.append(", ");
tones = model.IDLE().toNetherTones();
for (Iterator<Class<?>> i = tones.subList(3, tones.size()).iterator(); i.hasNext() ;) {
Class<?> toneClass = i.next();
buf.append(toneClass.getDeclaringClass().getSimpleName());
buf.append(".");
buf.append(toneClass.getSimpleName());
if (i.hasNext()) {
buf.append(", ");
}
}
buf.append(" {\n");
buf.append("\t}\n");
buf.append("\tnon-sealed interface ");
buf.append("IdentityBigEndian");
buf.append("\n");
buf.append("\t\t\textends ");
buf.append(javaName);
buf.append(", ");
tones = model.IDBE().toNetherTones();
for (Iterator<Class<?>> i = tones.subList(3, tones.size()).iterator(); i.hasNext() ;) {
Class<?> toneClass = i.next();
buf.append(toneClass.getDeclaringClass().getSimpleName());
buf.append(".");
buf.append(toneClass.getSimpleName());
if (i.hasNext()) {
buf.append(", ");
}
}
buf.append(" {\n");
buf.append("\t}\n");
for (NetherToneSlugView sequnceIndex : model.SLUGS()) {
String slugName = "" + sequnceIndex.toNúmero2Lingua() + "";
buf.append("\tnon-sealed interface ");
buf.append(slugName);
buf.append("\n");
buf.append("\t\t\textends ");
buf.append(javaName);
buf.append(", ");
tones =sequnceIndex.toNetherTones();
for (Iterator<Class<?>> i = tones.subList(3, tones.size()).iterator(); i.hasNext() ;) {
Class<?> toneClass = i.next();
buf.append(toneClass.getDeclaringClass().getSimpleName());
buf.append(".");
buf.append(toneClass.getSimpleName());
if (i.hasNext()) {
buf.append(", ");
}
}
buf.append(" {\n");
buf.append("\t}\n");
}
buf.append("}\n");
}
}
record NetherSlugLehmer(int SIZE, NetherToneSlugView IDLE, NetherToneSlugView IDBE, NetherToneSlugView...SLUGS) {
}
private void buildModuleInfo(ModelKlassWriter writer) {
ModelKlass klass = new ModelKlass("", "module-info");
klass.addJavaDescription("The nether dial packs tree slug index.");
writer.addModelKlass(klass);
StringBuilder buf = klass.getBody();
buf.append("module ᣕᕁᐤᣳ.ᒢᣘᐧᐧ.ᣕᓫᐪᑋᓫᣗ.ᒄᑊᣔᒻ {\n");
buf.append("\trequires transitive ᣕᕁᐤᣳ.ᒢᣘᐧᐧ.ᣕᓫᐪᑋᓫᣗ.ᐪᐤᣕᓫ;\n");
buf.append("\t\n");
buf.append("\texports " + BASE_PACK + ".ᒻᓫᑋᔿᓫᣗ;\n");
// for (String pack : splitSlugs.keySet()) {
// buf.append("\texports ");
// buf.append(BASE_PACK + "." + pack);
// buf.append(";\n");
// }
buf.append("}\n");
}
private long factorial(int n) {
if (n <= 1) {
return 1;
}
long fact = 1;
for (int i = 2; i <= n; i++) {
fact *= i;
}
return fact;
}
/**
* Converts a lexicographical rank (0-based) into a Lehmer code. Logic: Repeatedly divide rank by (n-1-i)! and keep the quotient as the digit.
*/
private int[] calculateLehmerFromRank(long rank, int n) {
int[] lehmer = new int[n];
for (int i = 0; i < n; i++) {
long fact = factorial(n - 1 - i);
lehmer[i] = (int) (rank / fact);
rank %= fact;
}
return lehmer;
}
/**
* Calculates the total number of permutations (n!) for a set of size n. The size n is equivalent to the length of the Lehmer code.
*/
private long calculateTotalPermutations(int[] lehmerCode) {
int n = lehmerCode.length;
long factorial = 1;
for (int i = 1; i <= n; i++) {
factorial *= i;
}
return factorial;
}
}

View file

@ -131,7 +131,7 @@ public class ModelDialLingua implements KodeGenModel {
continue;
}
NetherSlugNamed slugTpl = list.get(0);
List<Class<?>> tonesTpl = slugTpl.view().toNetherTones(0);
List<Class<?>> tonesTpl = slugTpl.view().toNetherTones();
ModelKlass klass = new ModelKlass(BASE_PACK + "." + pack, javaName);
for (Class<?> tone : tonesTpl) {
klass.addJavaImport(tone.getDeclaringClass().getName());
@ -175,7 +175,7 @@ public class ModelDialLingua implements KodeGenModel {
buf.append("\t\t\textends ");
buf.append(javaName);
buf.append(", ");
List<Class<?>> tones = slug.view().toNetherTones(0);
List<Class<?>> tones = slug.view().toNetherTones();
for (Iterator<Class<?>> i = tones.subList(4, tones.size()).iterator(); i.hasNext() ;) {
Class<?> toneClass = i.next();
buf.append(toneClass.getDeclaringClass().getSimpleName());

View file

@ -1,2 +1,3 @@
love.distributedrebirth.nx01.kode.generator.nether.ModelDialLingua
love.distributedrebirth.nx01.kode.generator.nether.ModelDialBased
love.distributedrebirth.nx01.kode.generator.nether.ModelDialBased
love.distributedrebirth.nx01.kode.generator.nether.ModelDial