1
|
1 // Very simple integer vectors for indexing -*- C++ -*- |
|
2 /* |
|
3 |
|
4 Copyright (C) 1992, 1993 John W. Eaton |
|
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 |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (_idx_vector_h) |
|
25 #define _idx_vector_h 1 |
|
26 |
|
27 #ifdef __GNUG__ |
|
28 #pragma interface |
|
29 #endif |
|
30 |
|
31 #include <assert.h> |
|
32 |
|
33 #define FAIL assert(0) /* XXX FIXME XXX */ |
|
34 |
164
|
35 class ostream; |
|
36 class Matrix; |
|
37 class Range; |
|
38 |
1
|
39 class idx_vector |
|
40 { |
|
41 public: |
|
42 idx_vector (void); |
|
43 idx_vector (const idx_vector& a); |
|
44 |
164
|
45 idx_vector (const Matrix& m, int do_ftn_idx, |
191
|
46 const char *rc = (char *) 0, int z_len = 0); |
1
|
47 |
|
48 idx_vector (const Range& r); |
|
49 |
|
50 ~idx_vector (void); |
|
51 |
|
52 idx_vector& operator = (const idx_vector& a); |
|
53 |
191
|
54 operator void * () const; |
|
55 |
1
|
56 int capacity (void) const; |
|
57 int length (void) const; |
|
58 |
|
59 int elem (int n) const; |
|
60 int checkelem (int n) const; |
|
61 int operator () (int n) const; |
|
62 |
|
63 // other stuff |
|
64 |
|
65 int max (void) const; |
|
66 int min (void) const; |
|
67 |
|
68 int one_zero_only (void) const; |
|
69 int zeros_count (void) const; |
|
70 int ones_count (void) const; |
|
71 |
208
|
72 void sort (void); |
|
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 |
191
|
89 void init_state (const char *rc = (char *) 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; |
|
96 data = (int *) 0; |
|
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 data = (int *) 0; |
|
107 num_zeros = 0; |
|
108 num_ones = 0; |
|
109 len = 0; |
|
110 one_zero = 0; |
|
111 initialized = 0; |
|
112 } |
|
113 |
|
114 inline idx_vector::operator void * () const |
|
115 { |
|
116 return initialized ? (void *) 1 : (void *) 0; |
|
117 } |
1
|
118 |
|
119 inline int idx_vector::capacity (void) const { return len; } |
|
120 inline int idx_vector::length (void) const { return len; } |
|
121 |
|
122 inline int idx_vector::elem (int n) const { return data[n]; } |
|
123 |
|
124 inline int |
|
125 idx_vector::checkelem (int n) const |
|
126 { |
|
127 if (n < 0 || n >= len) |
|
128 FAIL; |
|
129 |
|
130 return elem (n); |
|
131 } |
|
132 |
|
133 inline int idx_vector::operator () (int n) const { return checkelem (n); } |
|
134 |
|
135 inline int idx_vector::max (void) const { return max_val; } |
|
136 inline int idx_vector::min (void) const { return min_val; } |
|
137 |
|
138 inline int idx_vector::one_zero_only (void) const { return one_zero; } |
|
139 inline int idx_vector::zeros_count (void) const { return num_zeros; } |
|
140 inline int idx_vector::ones_count (void) const { return num_ones; } |
|
141 |
|
142 #endif |
|
143 |
|
144 /* |
|
145 ;;; Local Variables: *** |
|
146 ;;; mode: C++ *** |
|
147 ;;; page-delimiter: "^/\\*" *** |
|
148 ;;; End: *** |
|
149 */ |