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 |
164
|
31 class ostream; |
|
32 class Matrix; |
|
33 class Range; |
|
34 |
1
|
35 class idx_vector |
|
36 { |
|
37 public: |
|
38 idx_vector (void); |
|
39 idx_vector (const idx_vector& a); |
|
40 |
164
|
41 idx_vector (const Matrix& m, int do_ftn_idx, |
191
|
42 const char *rc = (char *) 0, int z_len = 0); |
1
|
43 |
|
44 idx_vector (const Range& r); |
|
45 |
|
46 ~idx_vector (void); |
|
47 |
|
48 idx_vector& operator = (const idx_vector& a); |
|
49 |
191
|
50 operator void * () const; |
|
51 |
1
|
52 int capacity (void) const; |
|
53 int length (void) const; |
|
54 |
|
55 int elem (int n) const; |
|
56 int checkelem (int n) const; |
|
57 int operator () (int n) const; |
|
58 |
|
59 // other stuff |
|
60 |
|
61 int max (void) const; |
|
62 int min (void) const; |
|
63 |
|
64 int one_zero_only (void) const; |
|
65 int zeros_count (void) const; |
|
66 int ones_count (void) const; |
|
67 |
208
|
68 void sort (void); |
|
69 |
1
|
70 // i/o |
|
71 |
|
72 friend ostream& operator << (ostream& os, const idx_vector& a); |
|
73 |
|
74 private: |
|
75 |
|
76 int len; |
|
77 int one_zero; |
|
78 int num_zeros; |
|
79 int num_ones; |
|
80 int max_val; |
|
81 int min_val; |
191
|
82 int initialized; |
1
|
83 int *data; |
|
84 |
191
|
85 void init_state (const char *rc = (char *) 0, int z_len = 0); |
1
|
86 void convert_one_zero_to_idx (void); |
|
87 }; |
|
88 |
|
89 inline idx_vector::idx_vector (void) |
191
|
90 { |
|
91 len = 0; |
|
92 data = (int *) 0; |
|
93 num_zeros = 0; |
|
94 num_ones = 0; |
|
95 one_zero = 0; |
|
96 initialized = 0; |
|
97 } |
1
|
98 |
|
99 inline idx_vector::~idx_vector (void) |
191
|
100 { |
|
101 delete [] data; |
|
102 data = (int *) 0; |
|
103 num_zeros = 0; |
|
104 num_ones = 0; |
|
105 len = 0; |
|
106 one_zero = 0; |
|
107 initialized = 0; |
|
108 } |
|
109 |
|
110 inline idx_vector::operator void * () const |
|
111 { |
|
112 return initialized ? (void *) 1 : (void *) 0; |
|
113 } |
1
|
114 |
|
115 inline int idx_vector::capacity (void) const { return len; } |
|
116 inline int idx_vector::length (void) const { return len; } |
|
117 |
|
118 inline int idx_vector::elem (int n) const { return data[n]; } |
|
119 |
|
120 inline int idx_vector::operator () (int n) const { return checkelem (n); } |
|
121 |
|
122 inline int idx_vector::max (void) const { return max_val; } |
|
123 inline int idx_vector::min (void) const { return min_val; } |
|
124 |
|
125 inline int idx_vector::one_zero_only (void) const { return one_zero; } |
|
126 inline int idx_vector::zeros_count (void) const { return num_zeros; } |
|
127 inline int idx_vector::ones_count (void) const { return num_ones; } |
|
128 |
|
129 #endif |
|
130 |
|
131 /* |
|
132 ;;; Local Variables: *** |
|
133 ;;; mode: C++ *** |
|
134 ;;; page-delimiter: "^/\\*" *** |
|
135 ;;; End: *** |
|
136 */ |