520
|
1 // idx-vector.h -*- C++ -*- |
1
|
2 /* |
|
3 |
1009
|
4 Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton |
1
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
1
|
21 |
|
22 */ |
|
23 |
383
|
24 #if !defined (octave_idx_vector_h) |
|
25 #define octave_idx_vector_h 1 |
1
|
26 |
1297
|
27 #if defined (__GNUG__) |
|
28 #pragma interface |
|
29 #endif |
|
30 |
164
|
31 class ostream; |
|
32 class Matrix; |
|
33 class Range; |
|
34 |
453
|
35 class |
|
36 idx_vector |
1
|
37 { |
|
38 public: |
|
39 idx_vector (void); |
|
40 idx_vector (const idx_vector& a); |
|
41 |
164
|
42 idx_vector (const Matrix& m, int do_ftn_idx, |
526
|
43 const char *rc = 0, int z_len = 0); |
1
|
44 |
|
45 idx_vector (const Range& r); |
|
46 |
|
47 ~idx_vector (void); |
|
48 |
|
49 idx_vector& operator = (const idx_vector& a); |
|
50 |
191
|
51 operator void * () const; |
|
52 |
1
|
53 int capacity (void) const; |
|
54 int length (void) const; |
|
55 |
|
56 int elem (int n) const; |
|
57 int checkelem (int n) const; |
|
58 int operator () (int n) const; |
|
59 |
|
60 // other stuff |
|
61 |
|
62 int max (void) const; |
|
63 int min (void) const; |
|
64 |
|
65 int one_zero_only (void) const; |
|
66 int zeros_count (void) const; |
|
67 int ones_count (void) const; |
|
68 |
208
|
69 void sort (void); |
416
|
70 void sort_uniq (void); |
208
|
71 |
434
|
72 void shorten (int n); // Unsafe. Avoid at all cost. |
|
73 |
1
|
74 // i/o |
|
75 |
|
76 friend ostream& operator << (ostream& os, const idx_vector& a); |
|
77 |
|
78 private: |
|
79 |
|
80 int len; |
|
81 int one_zero; |
|
82 int num_zeros; |
|
83 int num_ones; |
|
84 int max_val; |
|
85 int min_val; |
191
|
86 int initialized; |
1
|
87 int *data; |
|
88 |
526
|
89 void init_state (const char *rc = 0, int z_len = 0); |
1
|
90 void convert_one_zero_to_idx (void); |
|
91 }; |
|
92 |
|
93 inline idx_vector::idx_vector (void) |
191
|
94 { |
|
95 len = 0; |
1135
|
96 data = 0; |
191
|
97 num_zeros = 0; |
|
98 num_ones = 0; |
|
99 one_zero = 0; |
|
100 initialized = 0; |
|
101 } |
1
|
102 |
|
103 inline idx_vector::~idx_vector (void) |
191
|
104 { |
|
105 delete [] data; |
|
106 } |
|
107 |
|
108 inline idx_vector::operator void * () const |
|
109 { |
|
110 return initialized ? (void *) 1 : (void *) 0; |
|
111 } |
1
|
112 |
|
113 inline int idx_vector::capacity (void) const { return len; } |
|
114 inline int idx_vector::length (void) const { return len; } |
|
115 |
|
116 inline int idx_vector::elem (int n) const { return data[n]; } |
|
117 |
|
118 inline int idx_vector::operator () (int n) const { return checkelem (n); } |
|
119 |
|
120 inline int idx_vector::max (void) const { return max_val; } |
|
121 inline int idx_vector::min (void) const { return min_val; } |
|
122 |
|
123 inline int idx_vector::one_zero_only (void) const { return one_zero; } |
|
124 inline int idx_vector::zeros_count (void) const { return num_zeros; } |
|
125 inline int idx_vector::ones_count (void) const { return num_ones; } |
|
126 |
|
127 #endif |
|
128 |
|
129 /* |
|
130 ;;; Local Variables: *** |
|
131 ;;; mode: C++ *** |
|
132 ;;; page-delimiter: "^/\\*" *** |
|
133 ;;; End: *** |
|
134 */ |