<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Stephen Adah on Medium]]></title>
        <description><![CDATA[Stories by Stephen Adah on Medium]]></description>
        <link>https://medium.com/@steveadahson?source=rss-611f1ef6da0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*mpkXb8SZwZejs0yM</url>
            <title>Stories by Stephen Adah on Medium</title>
            <link>https://medium.com/@steveadahson?source=rss-611f1ef6da0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 14:02:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@steveadahson/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building a Hash Table in Python from Scratch]]></title>
            <link>https://medium.com/@steveadahson/building-a-hash-table-in-python-from-scratch-eb33613c486d?source=rss-611f1ef6da0------2</link>
            <guid isPermaLink="false">https://medium.com/p/eb33613c486d</guid>
            <dc:creator><![CDATA[Stephen Adah]]></dc:creator>
            <pubDate>Thu, 04 Dec 2025 11:42:31 GMT</pubDate>
            <atom:updated>2025-12-04T11:42:31.736Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Author: <em>Stephen Adah</em></strong></p><p><em>Software Engineer | Backend Developer | Python Enthusiast</em></p><p><strong>Introduction</strong></p><p>A <strong>Hash Table</strong> is one of the most fundamental data structures in computer science. It provides a way to store key–value pairs and retrieve them efficiently — typically in constant time <strong>O(1)</strong> on average.</p><p>While Python provides a built-in dictionary (dict) that uses hashing internally, implementing your own hash table helps you truly understand how this powerful structure works under the hood.</p><p>In this article, I’ll walk you through how I implemented a simple hash table class in Python — complete with <strong>insert</strong>, <strong>lookup</strong>, and <strong>delete</strong> functionalities.</p><p><strong>What Is a Hash Table?</strong></p><p>A hash table is like a giant <strong>cabinet of buckets</strong>. Each bucket holds one or more values.<br> To store data, a <strong>hash function</strong> converts a key (like “name” or 123) into a specific index that determines <strong>which bucket</strong> the data goes into.</p><p><strong>Simple Visualization</strong></p><pre>Hash Table (bucket size = 10)<br>-------------------------------------<br>Index | Stored Value<br>-------------------------------------<br>  0   | []<br>  1   | []<br>  2   | []<br>  3   | []<br>  4   | &quot;Thomas Michael&quot;<br>  5   | []<br>  6   | []<br>  7   | []<br>  8   | []<br>  9   | []<br>-------------------------------------</pre><p>If our hash function returns 4 for the key, the value is stored in bucket index 4.</p><p><strong>The Implementation</strong></p><p>Let’s break down the Python code for our Hash class</p><pre>#!/usr/bin/python3<br>&quot;&quot;&quot;A module of a simple hash table implementation.&quot;&quot;&quot;<br><br>class Hash:<br>    &quot;&quot;&quot;A class of hash table&quot;&quot;&quot;<br><br>    def __init__(self, bucket):<br>        &quot;&quot;&quot;Object constructor<br>        Args:<br>            bucket (int): size of the bucket<br>        Raise:<br>            TypeError: if bucket is not an integer<br>            ValueError: if bucket &lt;= 0<br>        &quot;&quot;&quot;<br>        if not isinstance(bucket, int):<br>            raise TypeError(&quot;Bucket must be an integer&quot;)<br>        elif bucket &lt;= 0:<br>            raise ValueError(&quot;Bucket must be greater than 0&quot;)<br><br>        self.__bucket = bucket<br>        self.__table = [[] for _ in range(bucket)]<br>        print(f&quot;Bucket Size: {self.__bucket}, Table: {self.__table}&quot;)</pre><p>Each <strong>bucket</strong> is represented as an empty list inside a list (self.__table).</p><p><strong>Hash Function</strong></p><p>The <strong>hash function</strong> determines the index for each key.</p><p>For integer keys</p><pre>def hash_function(self, key):<br>    if not isinstance(key, int):<br>        raise TypeError(&quot;Key must be an integer&quot;)<br>    elif key &lt;= 0:<br>        raise ValueError(&quot;Key must be greater than 0&quot;)<br><br>    return (key % self.__bucket)</pre><p>For example, if the bucket size is 10 and the key is 13,<br> 13 % 10 = 3, so the value is stored at index 3.</p><p><strong>Inserting Data</strong></p><pre>def insert_value(self, key, value):<br>    index = self.hash_function(key)<br>    self.__table[index] = value<br>    print(f&quot;{self.__table[index]} stored at index {index}&quot;)</pre><p>When we insert:</p><pre>The second value (13) hashes to the same bucket index as 3, due to 13 % 10 = 3.<br>If another value had the same result, we’d call that a collision</pre><p><strong>Lookup</strong></p><pre>def look_up(self, key):<br>    index = self.hash_function(key)<br>    print(f&quot;Value of {key} is {self.__table[index]}&quot;)<br>    return self.__table[index]</pre><p>Retrieving the value is simple — we hash the key again and fetch from that index.</p><p><strong>Delete Value</strong></p><pre>def delete_value(self, key, value):<br>    index = self.hash_function(key)<br>    self.__table[index] = []<br>    print(f&quot;Value of key: {self.__table[index]}&quot;)</pre><p>This method removes the value by resetting the bucket to an empty list.</p><p><strong>Example Run</strong></p><pre>if __name__==&quot;__main__&quot;:<br>    hash = Hash(10)<br>    hash.insert_value(4, &quot;Thomas Michael&quot;)<br>    hash.insert_value(13, &quot;Abigail Gambo&quot;)<br><br>    value = hash.look_up(13)<br>    print(f&quot;Returned value of 13: {value}&quot;)<br><br>    hash.delete_value(13, &quot;Abigail Gambo&quot;)<br>    hash.print_hash_table()</pre><p><strong>Output:</strong></p><pre>Bucket Size: 10, Table: [[], [], [], [], [], [], [], [], [], []]<br>Thomas Michael stored at index 4<br>Abigail Gambo stored at index 3<br>Value of 13 is Abigail Gambo<br>Returned value of 13: Abigail Gambo<br>Value of key: []<br>Bucket Size: 10, Table: [[], [], [], [], &#39;Thomas Michael&#39;, [], [], [], [], []]</pre><p><strong>Hashing String Keys</strong></p><p>When keys are <strong>strings</strong>, we can use a <strong>rolling hash function</strong> that multiplies each character’s Unicode value (ord(char)) by a constant (commonly 31), and then takes the modulo by the bucket size.</p><pre>elif isinstance(key, str):<br>    hash_val = 0<br>    for char in key:<br>        hash_val = (hash_val * 31 + ord(char))<br>    return hash_val % self.__bucket</pre><p>For example, for “base”:</p><pre>hash_val = (((0 * 31 + &#39;b&#39;) * 31 + &#39;a&#39;) * 31 + &#39;s&#39;) * 31 + &#39;e&#39;</pre><p>The ord() function converts a character into its <strong>Unicode integer</strong> value.<br> So, ‘b’ → 98, ‘a’ → 97, ‘s’ → 115, ‘e’ → 101.</p><p><strong>ASCII Diagram of “base” Hash Flow</strong></p><pre>Characters:  b    a    s    e<br>Unicode:    98   97  115  101<br><br>Rolling Hash Calculation:<br>hash_val = (((0*31 + 98)*31 + 97)*31 + 115)*31 + 101<br>hash_val = 303716<br>index = 303716 % bucket_size<br>If the bucket size is 10,<br>303716 % 10 = 6,<br>so &quot;base&quot; maps to bucket index 6</pre><p><strong>Hashing UUID Keys</strong></p><p>We can easily support <strong>UUID</strong> objects by converting them to strings and hashing them as we do with any string key:</p><pre>import uuid<br><br>key = uuid.uuid4()          # e.g. 7fa51ce0-99f9-4d7a-9f27-bb8438b7d1d8<br>index = hash_function(str(key))</pre><p>This way, even complex UUIDs can be uniformly distributed across buckets.</p><p><strong>Summary</strong></p><pre>Operation            Description                      Average Time Complexity<br><br>Insert              Add key–value pair                O(1)<br>Lookup              Retrieve value by key             O(1)<br>Delete              Remove value by key               O(1)<br><br>Collision Handling(To be improved — e.g., chaining)—</pre><p><strong>Next Steps</strong></p><p>This version is intentionally simple — perfect for learning.<br> In a more advanced version, you can add:</p><ul><li><strong>Collision handling</strong> using chaining or open addressing.</li><li><strong>Resizing</strong> the hash table when it gets full.</li><li><strong>Custom objects as keys</strong> by implementing __hash__.</li></ul><p><strong>Conclusion</strong></p><p>Implementing your own hash table is an excellent exercise for understanding data structure design and how efficient lookup mechanisms (like Python dictionaries) work internally.</p><p>With a good grasp of hashing logic, you can apply this to caching systems, symbol tables, or even your own database indexing strategies.</p><p><strong>If you enjoyed this article, feel free to share, star, or follow me for more Python data structure insights.</strong></p><p>My Linkedin: https://www/linkedin.com/in/stephen-adah-se-74614b145</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eb33613c486d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[POSTMORTEM]]></title>
            <link>https://medium.com/@steveadahson/postmortem-a919adc550eb?source=rss-611f1ef6da0------2</link>
            <guid isPermaLink="false">https://medium.com/p/a919adc550eb</guid>
            <category><![CDATA[postmortem]]></category>
            <dc:creator><![CDATA[Stephen Adah]]></dc:creator>
            <pubDate>Sun, 18 Feb 2024 12:26:58 GMT</pubDate>
            <atom:updated>2024-02-18T12:26:58.419Z</atom:updated>
            <content:encoded><![CDATA[<p>POSTMORTEM</p><p>The incidence report for an Apache outage that occured on Feb 17, 2024. We apologize to everyone who was affected.</p><p>ISSUE SUMMARY</p><p>On Sat 17, Feb 2024, 08:01 GMT, our Apache Server return 500 internal<br> server error. The error lasted for 3 hours before it was resolved. 100% of <br> traffic to our website were not able to access the http response. The root<br> cause of the problem, was as a result of a typo error in the configuration setting file.<br> Instead of “php” string, it was typed as “phpp” string. <br><br> TIMELINE<br><br> — 09:00 GMT: issue detected<br> — 08:55 GMT: datadog detected the issue<br> — 09:15 GMT: checking if the servers were running and if an issue with the servers networking<br> — 09:45 GMT: the issue was escalated to the software engineering team<br> — 10:15 GMT: the typo error (“phpp”) was detected and corrected to “php”<br> 10:20 GMT: 100% of traffic back online<br><br> ROOT CAUSE AND RESOLUTION<br> <br> A configuration change was released into our production environment at 08:01 GMT. This configuration was not released to our testing environment before released to production. Therefore a string error caused an internal server error. 100% of traffic could not accessed the site. At 08:55 GMT, the monitoring system detected the incidence and alerted the on-call engineer who investigated and escalated the issue to the software engineering team.<br> <br>After several investigation, using tmux and strace. It was discoverd that <br> typo error in the configuration file was ressponsible for the error. Therefore, the error was corrected at 10:15 GMT and 100% traffic were restored back to the website.<br><br> <br> CORRECTION AND PREVENTIVE MEASURES<br><br> This incidence occured because the configuraton change was not tested before it was deployed.<br> To avoid future reoccurence of this incidence. Every modification of configuration settings must be properly tested in our testing environment before deploying to our production environment.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a919adc550eb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WHAT HAPPENS WHEN YOU TYPE HTTPS://WWW.GOOGLE.COM]]></title>
            <link>https://medium.com/@steveadahson/what-happens-when-you-type-https-www-google-com-aee607806752?source=rss-611f1ef6da0------2</link>
            <guid isPermaLink="false">https://medium.com/p/aee607806752</guid>
            <category><![CDATA[an-article-for-you]]></category>
            <dc:creator><![CDATA[Stephen Adah]]></dc:creator>
            <pubDate>Sat, 27 Jan 2024 19:24:14 GMT</pubDate>
            <atom:updated>2024-01-27T19:29:57.472Z</atom:updated>
            <content:encoded><![CDATA[<p>WHAT HAPPENS WHEN YOU TYPE HTTPS://WWW.GOOGLE.COM IN YOUR BROWSER AND PRESS ENTER?<br>You may have been using a Web Browser application (Chrome, Firefox, Edge etc.) for a long time and most have performed some sites browsing. Have you ever wondered about the underlining architecture that is happening at the background?<br>I will take you through a brief explanation in order for you to have some understanding. Firstly, I want you to know that there are a lot of web networking activities that took place among many servers (machines/systems) in the background. These servers contain one or more servers’ applications that are interacting with one another through an appropriate communication protocol to serve you with the resources you are looking for.<br>In my explanation, there are some things which we are going to looks into. These comprises the following; DNS request, TCP/IP, Firewall, HTTPS/SSL, Load-balancer, Web server, Application server and Database. I will explain them one after the other in their sequential arrangement and how they interact with one another to present you with the information/data you requested.</p><p>DNS REQUEST<br>Domain Name Server (DNS) is a server that map out the domain name and the ip address of the host server of the website in a type of a record. Therefore, when you type a domain name such as www.google.com. Your web browser application will request the ip address that was mapped to the domain name that you type. IPv4 address is in a form like this 56.678.345.123 which is not human friendly. So, the concept of a domain name came, in order to have something that is human readable, easily remember and easy to work with. Therefore, the primary function of DNS is to serves the web browser with the IP address of the website hosting server. This will enable the web browser to locate the website hosting server. This bring us to next subject below;</p><p>TCP/IP<br>TCP/IP stands for Internet Protocol suite. It is a set of rules that defines how servers and clients interact over the network. How data should be transfer from one point to another. How it should be broken into packets, addressed, transmitted, routed and received at the destination. Therefore, with this protocol which require the IP address the web browser sourced from the DNS. The web browser and the web server (we shall look into it later) in the web hosting server, are about to interact and share data.</p><p>FIREWALL<br>Firewall is an essential part of the underling architecture. It is a network security device that monitors and filters incoming and outgoing network traffic based on an established security rule. So, the firewall allows your web browser to access the website because you are communicating with the sites based on the right established security rule.</p><p>HTTPS/SSL<br>HTTPS stands for Hypertext Transfer Protocol Secure. And SSL stands for Secure Socket Layer. This URL type HTTPS://WWW.GOOGLE.COM implies that the communication/interactions will be through a secure network HTTPS. This HTTPS is very much possible because of SSL which has being configured/integrated in the underlining architecture. It also implies that the firewall is configured to only allow traffic through a secure HTTP over the network. It helps to ensure that your communication and data are secured from hackers when interacting with the website/web application.</p><p>LOAD-BALANCER<br>Load-balancer is a software application that distributes traffic to the various web servers using a define algorithm. A website such as google, usually have a very large number of traffics. Therefore, in order for users to get quick response from the web server. More than one web servers are used, which is possible with the use of Load Balancer. The Load Balancer is position between the web browser of the user and the web server. It receives the user request and direct it to a web server based on a define algorithm such as Round-robin. This ensure that no web server is over loaded with traffic requests.</p><p>WEB SERVER<br>The Web Server is a software application that serves static content such as HTML, pages, images or plain text files. Application such as Nginx and Apache are examples of a web server. When the user request for a static content, the traffic goes to a web server application. In this case of HTTPS, the request and response is served through a secure Hypertext Transfer Protocol.</p><p>THE APPLICATION SERVER<br>The application server hosts and serve business logic/application logic of the web application. Unlike the web server that hosts and serves static content. It is the integration of the application server that makes the web application a dynamic. Being dynamic means that, users can interact with the site, save data into the site, login etc. Now that the user is able to interact with the site with data’s, this brings us to the subject of database.</p><p>DATABASE<br>Database as the name implies, is an application (software) that stores collected created data’s and give access, update and deletion of those data. Therefore, data’s like user’s login, password, phone number, email, etc. are stored in the database. An example of a database is MySQL.</p><p>In summary, when you type https://www.google.com into your web browser and press enter. The web browser retrieves the IP address that is mapped with the domain name from DNS and locate the Load Balancer that is standing in between the web server and your web browser. The Load Balancer then distributes your request to a web server based on a certain define algorithms such as Round-robin. The web server serves static content as a response to your request through a secure hypertext transfer protocol meaning on port 443. Then for a dynamic web application. You interact with the site by using some data’s such as login details. This is possible because of the application server which host the application logic. These data are stored in a database which enable the retrieval, modifying and possibly deletion for these data.<br>I believe you now understand what happens when you enter the domain name and press enter. For any question regarding the explanation feel free to asked and I will response to your questions with the right answers. Thanks for your time.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aee607806752" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>