<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://learn.cemetech.net/index.php?action=history&amp;feed=atom&amp;title=TI-BASIC%3ADictionary</id>
	<title>TI-BASIC:Dictionary - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://learn.cemetech.net/index.php?action=history&amp;feed=atom&amp;title=TI-BASIC%3ADictionary"/>
	<link rel="alternate" type="text/html" href="http://learn.cemetech.net/index.php?title=TI-BASIC:Dictionary&amp;action=history"/>
	<updated>2026-05-28T02:39:37Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.3</generator>
	<entry>
		<id>http://learn.cemetech.net/index.php?title=TI-BASIC:Dictionary&amp;diff=1183&amp;oldid=prev</id>
		<title>Maintenance script: Initial automated import</title>
		<link rel="alternate" type="text/html" href="http://learn.cemetech.net/index.php?title=TI-BASIC:Dictionary&amp;diff=1183&amp;oldid=prev"/>
		<updated>2016-02-24T18:38:55Z</updated>

		<summary type="html">&lt;p&gt;Initial automated import&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;A dictionary (also known as a map) is a data structure in which one piece of data maps to another piece of data, and the first datum (the key) maps to and only to the second datum (the value). Much like how a word in a dictionary maps to a definition.  However, there can be multiple keys for the same value. The major operations for a dictionary are &amp;#039;&amp;#039;put&amp;#039;&amp;#039;, &amp;#039;&amp;#039;contains&amp;#039;&amp;#039;, &amp;#039;&amp;#039;get&amp;#039;&amp;#039;, and &amp;#039;&amp;#039;remove&amp;#039;&amp;#039;. &amp;#039;&amp;#039;Put&amp;#039;&amp;#039; adds a key and a value to the dictionary. &amp;#039;&amp;#039;Contains&amp;#039;&amp;#039; indicates whether or not a key is to be found within the dictionary. &amp;#039;&amp;#039;Get&amp;#039;&amp;#039; retrieves the value associated with the given key. &amp;#039;&amp;#039;Remove&amp;#039;&amp;#039; removes a key and value pair based on a given key.&lt;br /&gt;
&lt;br /&gt;
= Implementation in TI-Basic =&lt;br /&gt;
&lt;br /&gt;
The most easily created dictionary in TI-Basic is implemented using a string. The string would have many keys and values, separated by delimiters (similar to the string implementations of [[TI-BASIC:Stack|stacks]] and [[TI-BASIC:Queue|queues]]). The string can have keys and values of any length so a delimiter must be used to separate the keys and values from each other. The delimiter can be any short string that will &amp;#039;&amp;#039;&amp;#039;never&amp;#039;&amp;#039;&amp;#039; appear in any of the entries. To create a dictionary store an instance of the delimiter into the string. This is because in TI-Basic, one cannot add to empty strings, and for our implementation, each key and value &amp;#039;&amp;#039;&amp;#039;must&amp;#039;&amp;#039;&amp;#039; be surrounded by a delimiter on either end. The reason for this will become clear soon. We must also add a padding character at each end. This will be to remove special cases for the remove operation.&lt;br /&gt;
&lt;br /&gt;
 :&amp;quot;?::?&amp;quot;→Str0&lt;br /&gt;
 &lt;br /&gt;
It does not matter onto which end we put data because we can get and remove data from any point in the dictionary so for this instance, we&amp;#039;re going to add to the end of the dictionary.&lt;br /&gt;
&lt;br /&gt;
 :sub(Str0,1,length(Str0)-1)+&amp;quot;KEY&amp;quot;+&amp;quot;::&amp;quot;+&amp;quot;VALUE&amp;quot;+&amp;quot;::&amp;quot;+&amp;quot;?&amp;quot;→Str0&lt;br /&gt;
&lt;br /&gt;
To find whether a key is contained with in the dictionary use [[TI-BASIC:Instring|inString(]]. If it returns 0, the key is not in the dictionary.&lt;br /&gt;
&lt;br /&gt;
 :inString(&amp;quot;::&amp;quot;+KEY+&amp;quot;::&amp;quot;)→N&lt;br /&gt;
&lt;br /&gt;
To retrieve a value, we first have to find the location of the key using the [[TI-BASIC:Instring|inString(]] function. Then we add to that the length of the key and the lengths of the two surrounding delimiters. We now know the location of the first character of the value. To find the length of value use inString( starting at that location and subtract it from the first location.&lt;br /&gt;
&lt;br /&gt;
 :&amp;quot;KEY&amp;quot;→Str1&lt;br /&gt;
 :&amp;quot;::&amp;quot;→Str2&lt;br /&gt;
 :inString(Str0,Str2+Str1+Str2)&lt;br /&gt;
 :If Ans:Then&lt;br /&gt;
 :Ans+length(Str1)+2*length(Str2)→N&lt;br /&gt;
 :inString(Str0,Str2,N)→M&lt;br /&gt;
 :sub(Str0,N,M-N)→Str3&lt;br /&gt;
 :End&lt;br /&gt;
&lt;br /&gt;
To remove a value, we have to use the same code as above to locate the end of the key-value segment of the string. We then concatenate the part of the string before the key-value combination and the part of the string after the key-value combination. This is why we added the surrounding characters (&amp;quot;?&amp;quot;), because we can&amp;#039;t concatenate with an empty string in TI-Basic.&lt;br /&gt;
&lt;br /&gt;
 :instring(Str0,Str2+Str1+Str2)→N&lt;br /&gt;
 :Ans+length(Str1)+2*length(Str2)&lt;br /&gt;
 :inString(Str0,Str2,Ans)+length(Str2)→M&lt;br /&gt;
 :sub(Str0,1,N-1)+sub(Str0,M,length(Str0)-M+1)→Str1[[Category:TI-BASIC]]&lt;br /&gt;
[[Category:TIBD]]&lt;/div&gt;</summary>
		<author><name>Maintenance script</name></author>
	</entry>
</feed>