Compare commits
18
Commits
ee9ee013e5
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
12e68b4dae | ||
|
|
bdb7ce0469 | ||
|
|
2d4870b0e8 | ||
|
|
d09a4e9280 | ||
|
|
931e774fb7 | ||
|
|
8d2f0a6519 | ||
|
|
0fffca4e9a | ||
|
|
c4fdb3a0d3 | ||
|
|
e971ac700f | ||
|
|
e39d177f45 | ||
|
|
9ba2ce9d6b | ||
|
|
17908b55e8 | ||
|
|
f702f99b3b | ||
|
|
ff678d71d1 | ||
|
|
8e42faf6af | ||
|
|
10f0555011 | ||
|
|
832cf45441 | ||
|
|
1e05501c1e |
@@ -26,7 +26,6 @@ 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,6 +17,7 @@ class Counter():
|
||||
@dataclass
|
||||
class Minter(Persistent):
|
||||
legalstring: ClassVar[str] = "0123456789bcdfghjkmnpqrstvwxz"
|
||||
xdig: tuple[str] = tuple(legalstring)
|
||||
alphacount: ClassVar[int] = len(legalstring)
|
||||
digitcount: ClassVar[int] = 10
|
||||
|
||||
@@ -138,7 +139,6 @@ 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,13 +164,44 @@ class Minter(Persistent):
|
||||
continue
|
||||
remainder = num % div
|
||||
num = int(num / div)
|
||||
s = xdig[remainder] + s
|
||||
s = self.xdig[remainder] + s
|
||||
if self.template[-1] == "k":
|
||||
s += "+"
|
||||
return s
|
||||
|
||||
def _checkbar(self, id):
|
||||
pass
|
||||
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
|
||||
|
||||
|
||||
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.genid()
|
||||
n = noid.mint()
|
||||
print("noid:", n)
|
||||
print(noid.active_counters)
|
||||
print(noid.inactive_counters)
|
||||
|
||||
Reference in New Issue
Block a user