From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,e8550e5b10c2c0 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-02-27 16:07:17 PST Path: archiver1.google.com!postnews1.google.com!not-for-mail From: mheaney@on2.com (Matthew Heaney) Newsgroups: comp.lang.ada Subject: Re: phone number database Date: 27 Feb 2003 16:07:16 -0800 Organization: http://groups.google.com/ Message-ID: <1ec946d1.0302271607.607503a1@posting.google.com> References: <3E5D00D6.F6A20AD2@boeing.com> NNTP-Posting-Host: 66.162.65.162 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1046390836 5790 127.0.0.1 (28 Feb 2003 00:07:16 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 28 Feb 2003 00:07:16 GMT Xref: archiver1.google.com comp.lang.ada:34697 Date: 2003-02-28T00:07:16+00:00 List-Id: Stephen Leake wrote in message news:... > "Anders Wirzenius" writes: > > > I HAVE: > > 1. > > Six phone numbers: 1795, 2006, 2007, 2012, 2013, 2014. > > 2. > > A log (text file) from the company's phone system with data like: > > From_Phone_Nr, To_Phone_Nr, Answering_Time, Duration... > > > > I WANT TO: > > 3. > > Pick only those log data where the To_Phone_Nr is one of the six numbers. > > 4. > > Set up some statistics about those phone calls. > > 5. > > Be able to add or remove phone numbers from the list (six becomes > > seven some sunny winterday). > > > > I WISH I HAD: > > type Help_Desk is (1795, 2006, 2007, 2012, 2013, 2014); -- with the > > dynamics described under point 5. > > > What is a proper way to implement "To_Phone_Nr in Help_Desk" ? > > Use a SAL binary tree > (http://users.erols.com/leakstan/Stephe/Ada/Sal_Packages/index.htm) to > store the help desk phone numbers; then do [ex snipped] If you just want a membership test, you can always use a set: package Phone_Number_Type is new Charles.Sets.Sorted.Unbounded (Phone_Number_Type); Set : Phone_Number_Types.Container_Type; if Find (Set, Phone_Number) /= Back (Set) then ... If you need to store some data with each number, you can could still use a set: type Info_Type is record Phone_Number : Phone_Number_Type; ... end record; function "<" (L, R : Info_Type) return Boolean is begin return L.Phone_Number < R.Phone_Number; end; package Phone_Number_Info is new Charles.Sets.Sorted.Unbounded (Info_Type, "<"); Set : Phone_Number_Info.Container_Type; procedure Op (X : Phone_Number_Type) is I : constant Iterator_Type := Find (Set, X); begin if I /= Back (Set) then declare Info : Info_Type renames To_Access (I).all; begin --manipulate Info as necessary end; end if; end Op; You could also use a map, which stores the phone number separately from the info: package Phone_Number_Info is new Charles.Maps.Sorted.Unbounded (Phone_Number_Type, Info_Type); --extra info only, sans phone number Map : Phone_Number_Info.Container_Type; procedure Op (X : Phone_Number_Type) is I : constant Iterator_Type := Find (Map, X); begin if I /= Back (Map) then declare Info : Info_Type renames To_Access (I).all; begin --manipulate Info as necessary end; end if; end Op; To add another phone number, just insert it into the set or map. For example: procedure Add (X : Phone_Number_Type; Y : Info_Type) is I : Iterator_Type; Success : Boolean; begin Insert (Map, X, Y, I, Success); if not Success then --X already in map end if; end Add; You could also use the hashed versions, and use the phone number itself as the value of the hash function for the phone number key. Then your lookups would only have O(1) average time complexity. The hashed associative containers are nice because you can preallocate the actual hash table: Map : Hashed_Map_Subtype; Resize (Map, Size => 6); That guarantees there's no hash table allocation until the load factor exceeds 1. http://home.earthlink.net/~matthewjheaney/charles/ Drop me a line if you have any questions about Charles. Matt