[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Index based on multiple fields, was Re: Adding comparision function
- From: "Ashwin Hirschi" <deery@...>
- Date: Thu, 02 Mar 2006 18:47:14 +0100
I originally tried indexing with an anonymous table as the key, ie
connection_record[ {proto="tcp", source_ip="1.2.3.4", source_port="123",
dest_ip="3.4.5.6", dest_port="567"} ] = whatever
When I want to update the table I tried constructing another anonymous
table with the exact same keys & values. This didn't work, I presume
due to the fact that they pointed to different tables, albeit with the
same values.
Correct.
So what I did was borrow from awk, and create a string key, i.e.:
connection_record[
"tcp"..SUBSEP.."1.2.3.4"..SUBSEP.."123"..SUBSEP.."3.4.5.6"..SUBSEP..567"
] = whatever
where SUBSEP is a character guaranteed to not be in the fields making up
the key.
This, however, seems kludgy.
Hey, if it works well, it's not kludgy! [;-)]
Is there a "lua" way to accomplish this task more elegantly?
Another approach would be to manage a tree of tables, I guess. The trees in each level corresponding to one index property. Can be quite quick, depending on what you need to do.
A third (and somewhat more eloborate) solution is interfacing with a small database engine like SQLite. That would enable you to have easy access to (for example) in-memory database tables, allowing you to search & update complex structures very efficiently.
My point is: always keep in mind that if "standard" Lua doesn't quite provide you with the solution you're looking for, it's always incredibly easy to integrate something (into it) that will.
Ashwin.
--
no signature is a signature.