From ba0780c240986bbd1a8871db5f51e7abc2e84e05 Mon Sep 17 00:00:00 2001 From: bt3gl <138340846+bt3gl-cryptographer@users.noreply.github.com> Date: Tue, 8 Aug 2023 17:03:31 -0700 Subject: [PATCH] Delete map_sum.py --- tries/map_sum.py | 42 ------------------------------------------ 1 file changed, 42 deletions(-) delete mode 100644 tries/map_sum.py diff --git a/tries/map_sum.py b/tries/map_sum.py deleted file mode 100644 index 36efcaa..0000000 --- a/tries/map_sum.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- -# author: bt3gl - -''' -Design a map that allows you to do the following: -- Maps a string key to a given value. -- Returns the sum of the values that have a key with a prefix equal to a given str. -''' - -class Node: - - def __init__(self): - self.children = {} - self.score = 0 - - -class MapSum: - - def __init__(self): - self.map = {} - self.root = Node() - - def insert(self, key: str, val: int) -> None: - delta = val - self.map.get(key, 0) - self.map[key] = val - - node = self.root - node.score += delta - for c in key: - node = node.children.setdefault(c, Node()) - node.score += delta - - def sum(self, prefix: str) -> int: - node = self.root - for c in prefix: - if c not in node.children: - return 0 - node = node.children[c] - - return node.score -