Can I use 'POS to find a character in a array ?

Guest
If I have a array of character.

type wheel_string is array (char_index'left to char_index'right) of
character;

Can I use 'POS to find a character in the array ?

index := the_enigma.rotor(i).wheel'pos(ch);

Or do I have to compare every character with the one that I am looking
for ?

Thank you
 
On May 9, 2:20 pm, HansWernerMarsc...@web.de wrote:
If I have a array of character.

type wheel_string is array (char_index'left to char_index'right) of
character;

Can I use 'POS to find a character in the array ?
'pos returns the position within the array...I think that's what you
mean to say or ask.

index := the_enigma.rotor(i).wheel'pos(ch);
Assuming that 'index' is an integer than 'index' will be a number that
tells you the index within 'wheel_string' where the character 'ch' is
at.

Or do I have to compare every character with the one that I am looking
for ?
You shouldn't have to.

KJ
 
On Fri, 9 May 2008 11:20:21 -0700 (PDT),
HansWernerMarschke@web.de wrote:

If I have a array of character.

type wheel_string is array (char_index'left to char_index'right) of
character;

Can I use 'POS to find a character in the array ?

index := the_enigma.rotor(i).wheel'pos(ch);
eh? Can I assume that the record element
the_enigma.rotor(i).wheel
is of type wheel_string? If so, then the answer is very
clearly "no"; you're trying to search through this array,
locating the index at which character ch is found in it,
I assume. That's not even close to what 'pos is supposed
to do. Your example is surely illegal, isn't it? The
predefined attribute 'POS applies only to a discrete TYPE,
not to a data object.

Or do I have to compare every character with the one
that I am looking for ?
Yes.

Alternatively, build a reverse-index array, indexed by
CHARACTER, in which you put the index number at which
each character is to be found. You can presumably
build this reverse index at the same time as you
build the forward "wheel" array.
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan.bromley@MYCOMPANY.com
http://www.MYCOMPANY.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
 
Can I assume that the record element
the_enigma.rotor(i).wheel
is of type wheel_string? If so, then the answer is very
clearly "no"; you're trying to search through this array,
locating the index at which character ch is found in it,
I assume. That's not even close to what 'pos is supposed
to do. Your example is surely illegal, isn't it? The
predefined attribute 'POS applies only to a discrete TYPE,
not to a data object.

Well, I got an error using this construct.
By discrete type you mean something like integer ?

May the FPGA be with you
 
On Fri, 9 May 2008 15:11:04 -0700 (PDT), HansWernerMarschke@web.de
wrote:

Can I assume that the record element
the_enigma.rotor(i).wheel
is of type wheel_string? If so, then the answer is very
clearly "no"; you're trying to search through this array,
locating the index at which character ch is found in it,
I assume. That's not even close to what 'pos is supposed
to do. Your example is surely illegal, isn't it? The
predefined attribute 'POS applies only to a discrete TYPE,
not to a data object.
The problem there is that if "wheel" is an array (data object) you can
manipulate the values in it - moving characters around - and 'pos cannot
follow those changes. The positions need to be fixed at compile time.
Otherwise you need to search.

Well, I got an error using this construct.
By discrete type you mean something like integer ?
Integer, or in this case, try enumeration...

type wheel_3 is ('a', 'b', 'c', ... 'z');
type wheel_4 is ('z', 'y', 'x', ... 'a');

This will allow the use of 'pos, but now each wheel is a different type.
The desing of each wheel is fixed when you create the machine, which
seems appropriate, and allows'pos instead of searching.

variable p : integer;
p := wheel_3'pos('c'); -- returns 2 (first pos is 0)

Therefore if the second position is fitted with wheel 3 today, you need
to know which type to apply 'pos to. A case statement will do;
fortunately you can hide this in a function...

function wheel_pos ( ch : in character, wh : in wheel_index) is
begin
case wh is
when 1 => return wheel_1'pos(ch);
when 2 => return wheel_2'pos(ch);
when 3 => return wheel_3'pos(ch);
when 4 => return wheel_4'pos(ch);
when others => return ("X");
end case;
end function wheel_pos;

p := wheel_pos('c',3);

I don't know how this will synthesise; it should, but it might be quite
large.

- Brian
 

Welcome to EDABoard.com

Sponsor

Back
Top