Compare commits
10
Commits
main
..
ee9ee013e5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ee9ee013e5 | ||
|
|
3d47bd6c1c | ||
|
|
902c34c0fe | ||
|
|
06452ee9f8 | ||
|
|
690865cd69 | ||
|
|
518e9957b4 | ||
|
|
7a7cc79ac5 | ||
|
|
138aba5034 | ||
|
|
f7e7554d5c | ||
|
|
1905df5943 |
@@ -26,6 +26,7 @@ if __name__ == "__main__":
|
||||
minter.store(f"{args.name}.noid")
|
||||
case "mint":
|
||||
minter = Minter.load(f"{args.name}.noid")
|
||||
print(minter)
|
||||
print(f"New noid: {minter.genid()}")
|
||||
minter.store(f"{args.name}.noid")
|
||||
case _:
|
||||
|
||||
@@ -17,7 +17,6 @@ class Counter():
|
||||
@dataclass
|
||||
class Minter(Persistent):
|
||||
legalstring: ClassVar[str] = "0123456789bcdfghjkmnpqrstvwxz"
|
||||
xdig: tuple[str] = tuple(legalstring)
|
||||
alphacount: ClassVar[int] = len(legalstring)
|
||||
digitcount: ClassVar[int] = 10
|
||||
|
||||
@@ -139,6 +138,7 @@ class Minter(Persistent):
|
||||
# 8. return s
|
||||
s = ""
|
||||
varwidth = 0
|
||||
xdig = list(self.legalstring)
|
||||
rmask = list(self.template)
|
||||
rmask.reverse()
|
||||
while num != 0 or not varwidth:
|
||||
@@ -164,44 +164,13 @@ class Minter(Persistent):
|
||||
continue
|
||||
remainder = num % div
|
||||
num = int(num / div)
|
||||
s = self.xdig[remainder] + s
|
||||
s = xdig[remainder] + s
|
||||
if self.template[-1] == "k":
|
||||
s += "+"
|
||||
return s
|
||||
|
||||
def _checkchar(self, id):
|
||||
# 1. Return undef if id is not set
|
||||
# 2. init lastchar to last char of the id, and remove that char from id
|
||||
# 3. init pos to 1
|
||||
# 4. init sum to 0
|
||||
# 5. declare c
|
||||
# 6. for each character of the id
|
||||
# - get the ordinal value of the character
|
||||
# - increment sum with the pos * the index value of the char in legalstring
|
||||
# - increment pos
|
||||
# 7. init checkchar to the value of xdig[sum % alphacount]
|
||||
# 8. return the concat of id and checkchar is lastchar equal to '+' or checkchar
|
||||
# 9. return None
|
||||
if id is None:
|
||||
return None
|
||||
lastchar = id[-1]
|
||||
sum = 0
|
||||
for idx, char in enumerate(id[:-1], 1):
|
||||
sum += idx * (self.legalstring.index(char) if self.legalstring.index(char) else 0)
|
||||
checkchar = self.xdig[sum % self.alphacount]
|
||||
if lastchar == "+" or lastchar == checkchar:
|
||||
return id[:-1] + checkchar
|
||||
else:
|
||||
return None
|
||||
|
||||
def mint(self, n=1):
|
||||
for _ in range(n):
|
||||
_id = self.genid()
|
||||
if self.template[-1] == "k":
|
||||
_id = self._checkchar(_id)
|
||||
if _id is not None:
|
||||
return self.prefix + _id
|
||||
return self.prefix + _id
|
||||
def _checkbar(self, id):
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ if __name__ == "__main__":
|
||||
for i in range(noid.oatop + 2):
|
||||
print(f"--> {i=}")
|
||||
try:
|
||||
n = noid.mint()
|
||||
n = noid.genid()
|
||||
print("noid:", n)
|
||||
print(noid.active_counters)
|
||||
print(noid.inactive_counters)
|
||||
|
||||
Reference in New Issue
Block a user