Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Associate arrays in PB

230 views
Skip to first unread message

Dan Cooperstock

unread,
Aug 3, 2009, 10:06:12 AM8/3/09
to
I need functionality like an associative array in languages like
JavaScript, or a Map/Dictionary in Java/.NET. I.e. I need to associate one
string value with another (the key), and be able to do quick lookups on the
keys.

I'm thinking of just creating a 2-string-field external DW, and use the
Find function for the lookups, all encapsulated in an NVO that instantiates
the DW in a DataStore. However, that seems like a rather heavyweight
solution, although it should be reasonably fast.

Any other suggestions? I did think of using JSCRIPT through COM, which I
know is possible, but that also seems heavyweight. I don't think I should
write it entirely from scratch in an NVO, because I suspect that the DW
Find function would be faster than any lookup I would write. (Not that I
plan to use this for huge associative arrays, mind you.)

Thanks.

---------------------------
Dan Cooperstock
DONATION web site: http://www.Software4Nonprofits.com
DONATION Support forums: http://forums.Software4Nonprofits.com
Email: mailto:in...@Software4Nonprofits.com
Phone: 416-423-7722

Dan Cooperstock

unread,
Aug 3, 2009, 10:07:46 AM8/3/09
to
Dan Cooperstock <in...@Software4NonProfits.com> wrote in
news:Xns9C5C66C7BB7C1in...@192.138.151.106:

> I need functionality like an associative array in languages like
> JavaScript, or a Map/Dictionary in Java/.NET. I.e. I need to associate
> one string value with another (the key), and be able to do quick
> lookups on the keys.

P.S. This is a native PB app, so please don't suggest I just use the .NET
fetaures in recent versions of PB. (I'm still using 10.2 anyways, since it
seems completely adequate for my needs.)

Scott Morris

unread,
Aug 3, 2009, 10:33:13 AM8/3/09
to
"Dan Cooperstock" <in...@Software4NonProfits.com> wrote in message
news:Xns9C5C66C7BB7C1in...@192.138.151.106...

>I need functionality like an associative array in languages like
> JavaScript, or a Map/Dictionary in Java/.NET. I.e. I need to associate one
> string value with another (the key), and be able to do quick lookups on
> the
> keys.
>
> I'm thinking of just creating a 2-string-field external DW, and use the
> Find function for the lookups, all encapsulated in an NVO that
> instantiates
> the DW in a DataStore. However, that seems like a rather heavyweight
> solution, although it should be reasonably fast.

This would be my choice. I'm guessing that the datawindow code is highly
optimized within PB and, since it is likely already used in your
application, should be extremely lightweight.

> Any other suggestions? I did think of using JSCRIPT through COM, which I
> know is possible, but that also seems heavyweight. I don't think I should
> write it entirely from scratch in an NVO, because I suspect that the DW
> Find function would be faster than any lookup I would write. (Not that I
> plan to use this for huge associative arrays, mind you.)

PFC already has list, queue, stack, and tree classes.


Dan Cooperstock

unread,
Aug 3, 2009, 10:36:47 AM8/3/09
to
"Scott Morris" <bo...@bogus.com> wrote in news:4a76f529$2@forums-3-
dub.sybase.com:

> PFC already has list, queue, stack, and tree classes.

I don't think any of them would act as an associative array with lookup by
a key, though, would they?

Scott Morris

unread,
Aug 3, 2009, 12:27:37 PM8/3/09
to
>> PFC already has list, queue, stack, and tree classes.
>
> I don't think any of them would act as an associative array with lookup by
> a key, though, would they?

Have a look. List and Tree both have a Find function.


Jerry Siegel [TeamSybase]

unread,
Aug 3, 2009, 1:16:33 PM8/3/09
to
This posting from the general group may be helpful:

At 18:24 on jui 20 2009, Jerry Siegel said :

> Are you trying to implement an associative array?
> http://en.wikipedia.org/wiki/Associative_array

It sound like. If so, my PbniHash extension (associative array = hash
table) could help :
http://sebastien.kirche.free.fr/powerbuilder/en

HTH.
--
S�bastien Kirche

--
Report Bugs: http://case-express.sybase.com/cx/welcome.do
Product Enhancement Requests:
http://my.isug.com/cgi-bin/1/c/submit_enhancement


"Scott Morris" <bo...@bogus.com> wrote in message
news:4a770ff9$3...@forums-3-dub.sybase.com...

Jerry Siegel [TeamSybase]

unread,
Aug 3, 2009, 1:25:12 PM8/3/09
to
Find _is_ pretty fast, since it's C++ code operating on memory (no I/O). The
one weakness is that it is a linear search. If you have a lot of entries and
a high probability of not-found, you could easily write a half-interval (AKA
binary) search on the DW/DS. That would require that the rows be sorted by
key. http://en.wikipedia.org/wiki/Binary_search_algorithm


"Scott Morris" <bo...@bogus.com> wrote in message

news:4a76f529$2...@forums-3-dub.sybase.com...

0 new messages