UNIVERS  15.3
UNIVERS base processing software API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SortedAr.H
1 // SortedAr.H $Revision: 1.9 $ $Date: 2005/05/24 11:39:40 $
2 
3 #if !defined __SortedAr_H
4 
5 #define __SortedAr_H
6 
7 #include <mix/Types.h>
8 #include <mix/DynAr.H>
9 
10 /*************************************************************
11  * Abstract Dynamyc Array with sorting feature
12  *************************************************************/
13 
14 class SortedAr : public DynAr
15 {
16 protected:
17 
18  // Recursive function of quick sort.
19  void quick_sort (Compar order, unsigned L, unsigned R);
20 
21  // Recursive function of binary search procedure. Returns
22  // index of found item or -1 is search failed.
23  int quick_find (const char* item, Compar order,
24  unsigned L, unsigned R) const;
25 
26 public:
27 
28  SortedAr (const SortedAr& sortedar)
29  : DynAr(sortedar) {};
30  SortedAr (unsigned size, unsigned quant, unsigned volume)
31  : DynAr(size, quant, volume) {};
32 
33  // NO_ORDER, EQUAL - no sorting
34  // ASCENT_ORDER, LESS - ascent order: a(i)<=a(i+1)
35  // DESCENT_ORDER, GREATER - descent order: a(i)>=a(i+1)
36  virtual void sort (Compar order);
37 
38  // Usual compare between two elements; dummy version
39  virtual Compar compare (const char* item1,
40  const char* item2) const;
41 
42  // Search for needed item, meaning array is already sorted in
43  // ascent order. Returns -1 if item is not found.
44  virtual int quick_find_ascent (const char* item) const {
45  if(0 == count()) return -1;
46  return quick_find(item, ASCENT_ORDER, 0, count() - 1);
47  }
48 
49  // Search for needed item, meaning array is already sorted in
50  // descent order. Returns -1 if item is not found.
51  virtual int quick_find_descent (const char* item) const {
52  if(0 == count()) return -1;
53  return quick_find(item, DESCENT_ORDER, 0, count() - 1);
54  }
55 
56  // Find item and return index of it or -1 if search failed.
57  // Redefines DynAr version of method with type specific comparation
58  // by compare() virtual method.
59  virtual int slow_find (const char* item) const;
60 
61  // Search for the range, which includes given item value. Ascent
62  // order of the array is expected. EQUAL is returned in case of
63  // existent range (returned in L..R, L<=R). LESS and GREATER means
64  // the value is out of the whole range of array.
65  virtual Compar find_range_ascent (const char* value,
66  unsigned& L,
67  unsigned& R) const;
68 
69  // Search for the range, which includes given item value. Descent
70  // order of the array is expected. EQUAL is returned in case of
71  // existent range (returned in L..R, L<=R). LESS and GREATER means
72  // the value is out of the whole range of array.
73  virtual Compar find_range_descent (const char* value,
74  unsigned& L,
75  unsigned& R) const;
76 
77 };
78 
79 
80 #endif // SortedAr.H
Definition: SortedAr.H:14
Definition: DynAr.H:22