Bi-directional access to lookup tables
Posted: 02 May 2014 12:10
Hi,
you describe a way how to use a lookup table on your site about DOS - String Manipulation:
However, with that given method of accessing an item of a pair, you can just search for the left-sided item in order to return the right-sided item.
I wanted a way to access and return both items of a pair.
My first idea was to use a second table in which the order of the elements in a pair is inverted.
But that requires much work of coding and space or runtime for inverting the items.
So my next idea was to create an algorithm which uses just one table and looks up the right-sided element and returns the left-sided element of a pair.
Unfortunately didn't work for cutting of the end of the string so I had to find a different way for doing that and I found two further possibilities to do so:
and
After that, I just needed to cut the left side of the string until to the latest ; (semicolon) which I did with
All together, the code looks either like that
or like that
What do you think which of those two codes could be better?
Do you have suggestions for improving my code or better ideas to realize a bi-directional access to lookup tables?
you describe a way how to use a lookup table on your site about DOS - String Manipulation:
Code: Select all
SET v=Mai
SET map=Jan-01;Feb-02;Mar-03;Apr-04;Mai-05;Jun-06;Jul-07;Aug-08;Sep-09;Oct-10;Nov-11;Dec-12
CALL SET v=%%map:*%v%-=%%
SET v=%v:;=&rem.%
ECHO.%v%
However, with that given method of accessing an item of a pair, you can just search for the left-sided item in order to return the right-sided item.
I wanted a way to access and return both items of a pair.
My first idea was to use a second table in which the order of the elements in a pair is inverted.
But that requires much work of coding and space or runtime for inverting the items.
So my next idea was to create an algorithm which uses just one table and looks up the right-sided element and returns the left-sided element of a pair.
Unfortunately
Code: Select all
SET v=05
CALL SET v=%%map:-%v%=&rem.%%
Code: Select all
call set v=%%map:-%v%="%%
call set "v=%v%
and
Code: Select all
call set v=-%iv%%%map:*-%v%=%%
call set v=%%map:%v%=%%
After that, I just needed to cut the left side of the string until to the latest ; (semicolon) which I did with
Code: Select all
set a=%a:;=&set a=%
All together, the code looks either like that
Code: Select all
SET map=Jan-01;Feb-02;Mar-03;Apr-04;Mai-05;Jun-06;Jul-07;Aug-08;Sep-09;Oct-10;Nov-11;Dec-12
SET v=05
call set v=%%map:-%v%="%%
call set "v=%v%
set v=%v:;=&set v=%
echo.%v%
or like that
Code: Select all
SET map=Jan-01;Feb-02;Mar-03;Apr-04;Mai-05;Jun-06;Jul-07;Aug-08;Sep-09;Oct-10;Nov-11;Dec-12
SET v=05
call set v=-%v%%%map:*-%v%=%%
call set v=%%map:%v%=%%
set v=%v:;=&set v=%
echo.%v%
What do you think which of those two codes could be better?
Do you have suggestions for improving my code or better ideas to realize a bi-directional access to lookup tables?