2 #ifndef JAWS_ASSOC_ARRAY_H
3 #define JAWS_ASSOC_ARRAY_H
5 template <class KEY
, class DATA
> class JAWS_Assoc_Array_Iterator
;
7 template <class KEY
, class DATA
>
10 friend class JAWS_Assoc_Array_Iterator
<KEY
, DATA
>;
13 JAWS_Assoc_Array (int maxsize
= 1024);
16 int index (const KEY
&k
);
17 // Returns the index into the array associated with key k
18 // Returns -1 if not found.
20 DATA
* find (const KEY
&k
);
21 // Returns the data associated with key k. 0 if not found.
23 DATA
* find_by_index (int i
);
24 // Returns the data associated with array index i. Returns 0 if the
27 DATA
* insert (const KEY
&k
, const DATA
&d
);
28 // Inserts a *copy* of the key and data into the associated array.
29 // Both KEY and DATA must have well defined semantics for copy
30 // construction. This method returns a pointer to the inserted item
31 // copy, or 0 if an error occurred. NOTE: if an identical key
32 // already exists in the tree, no new item is created, and the
33 // returned pointer addresses the existing item associated with the
36 int remove (const KEY
&k
);
37 // Removes the item associated with the given key from the
38 // tree and destroys it. Returns 1 if it found the item
39 // and successfully destroyed it, 0 if it did not find the
40 // item, or -1 if an error occurred.
43 // Destroys all keys and associated data.
46 int find_i (const KEY
&k
);
47 // If k points to an associated data item, then this function
48 // returns the index into the arrays that hold it. Otherwise, it
49 // returns an index suitable to insert the item. If the item is not
50 // found and the table is full, maxsize_ is returned.
58 template <class KEY
, class DATA
>
59 class JAWS_Assoc_Array_Iterator
62 JAWS_Assoc_Array_Iterator (const JAWS_Assoc_Array
<KEY
, DATA
> &aa
);
63 ~JAWS_Assoc_Array_Iterator ();
75 // declare private and do not define: explicitly
76 // prevent assignment and copy construction of iterators
77 JAWS_Assoc_Array_Iterator (const JAWS_Assoc_Array_Iterator
<KEY
, DATA
> &);
78 void operator= (const JAWS_Assoc_Array_Iterator
<KEY
, DATA
> &);
81 const JAWS_Assoc_Array
<KEY
, DATA
> &aa_
;
84 // The current item pointed by iterator.
87 // The next item to be pointed to by iterator.
90 #include "JAWS/Assoc_Array.cpp"
92 #endif /* !defined (JAWS_ASSOC_ARRAY_H) */