1
|
1 // Very simple integer vectors for indexing -*- C++ -*- |
|
2 /* |
|
3 |
383
|
4 Copyright (C) 1992, 1993, 1994 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 |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
383
|
24 #if !defined (octave_idx_vector_h) |
|
25 #define octave_idx_vector_h 1 |
1
|
26 |
164
|
27 class ostream; |
|
28 class Matrix; |
|
29 class Range; |
|
30 |
1
|
31 class idx_vector |
|
32 { |
|
33 public: |
|
34 idx_vector (void); |
|
35 idx_vector (const idx_vector& a); |
|
36 |
164
|
37 idx_vector (const Matrix& m, int do_ftn_idx, |
191
|
38 const char *rc = (char *) 0, int z_len = 0); |
1
|
39 |
|
40 idx_vector (const Range& r); |
|
41 |
|
42 ~idx_vector (void); |
|
43 |
|
44 idx_vector& operator = (const idx_vector& a); |
|
45 |
191
|
46 operator void * () const; |
|
47 |
1
|
48 int capacity (void) const; |
|
49 int length (void) const; |
|
50 |
|
51 int elem (int n) const; |
|
52 int checkelem (int n) const; |
|
53 int operator () (int n) const; |
|
54 |
|
55 // other stuff |
|
56 |
|
57 int max (void) const; |
|
58 int min (void) const; |
|
59 |
|
60 int one_zero_only (void) const; |
|
61 int zeros_count (void) const; |
|
62 int ones_count (void) const; |
|
63 |
208
|
64 void sort (void); |
416
|
65 void sort_uniq (void); |
208
|
66 |
434
|
67 void shorten (int n); // Unsafe. Avoid at all cost. |
|
68 |
1
|
69 // i/o |
|
70 |
|
71 friend ostream& operator << (ostream& os, const idx_vector& a); |
|
72 |
|
73 private: |
|
74 |
|
75 int len; |
|
76 int one_zero; |
|
77 int num_zeros; |
|
78 int num_ones; |
|
79 int max_val; |
|
80 int min_val; |
191
|
81 int initialized; |
1
|
82 int *data; |
|
83 |
191
|
84 void init_state (const char *rc = (char *) 0, int z_len = 0); |
1
|
85 void convert_one_zero_to_idx (void); |
|
86 }; |
|
87 |
|
88 inline idx_vector::idx_vector (void) |
191
|
89 { |
|
90 len = 0; |
|
91 data = (int *) 0; |
|
92 num_zeros = 0; |
|
93 num_ones = 0; |
|
94 one_zero = 0; |
|
95 initialized = 0; |
|
96 } |
1
|
97 |
|
98 inline idx_vector::~idx_vector (void) |
191
|
99 { |
|
100 delete [] data; |
|
101 data = (int *) 0; |
|
102 num_zeros = 0; |
|
103 num_ones = 0; |
|
104 len = 0; |
|
105 one_zero = 0; |
|
106 initialized = 0; |
|
107 } |
|
108 |
|
109 inline idx_vector::operator void * () const |
|
110 { |
|
111 return initialized ? (void *) 1 : (void *) 0; |
|
112 } |
1
|
113 |
|
114 inline int idx_vector::capacity (void) const { return len; } |
|
115 inline int idx_vector::length (void) const { return len; } |
|
116 |
|
117 inline int idx_vector::elem (int n) const { return data[n]; } |
|
118 |
|
119 inline int idx_vector::operator () (int n) const { return checkelem (n); } |
|
120 |
|
121 inline int idx_vector::max (void) const { return max_val; } |
|
122 inline int idx_vector::min (void) const { return min_val; } |
|
123 |
|
124 inline int idx_vector::one_zero_only (void) const { return one_zero; } |
|
125 inline int idx_vector::zeros_count (void) const { return num_zeros; } |
|
126 inline int idx_vector::ones_count (void) const { return num_ones; } |
|
127 |
|
128 #endif |
|
129 |
|
130 /* |
|
131 ;;; Local Variables: *** |
|
132 ;;; mode: C++ *** |
|
133 ;;; page-delimiter: "^/\\*" *** |
|
134 ;;; End: *** |
|
135 */ |