dkl9 commited on 2025-202 23:33:57
Showing 1 changed files, with 2 additions and 2 deletions.
| ... | ... |
@@ -9,7 +9,7 @@ from typing import Generator |
| 9 | 9 |
def cost(token_child: tuple[str, "Trie"]) -> tuple: |
| 10 | 10 |
token, child = token_child |
| 11 | 11 |
weight = child.deep_weight |
| 12 |
- return child.deep_usage / weight, child.min_depth, len(token), token |
|
| 12 |
+ return child.deep_usage / weight, -weight, child.min_depth, len(token), token |
|
| 13 | 13 |
|
| 14 | 14 |
class Trie: |
| 15 | 15 |
def __init__(self, weight: int = 0): |
| ... | ... |
@@ -28,7 +28,7 @@ class Trie: |
| 28 | 28 |
|
| 29 | 29 |
def add(self, word: list[str], weight: int = 1): |
| 30 | 30 |
self.deep_weight += weight |
| 31 |
- self.min_depth = min(self.min_depth, sum(len(t) for t in word)) |
|
| 31 |
+ self.min_depth = min(self.min_depth, len(word)) |
|
| 32 | 32 |
if word: |
| 33 | 33 |
self.children[word[0]].add(word[1:], weight) |
| 34 | 34 |
else: |
| 35 | 35 |