Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
implemeting using hashes or array

Posted by sachin_chat (sachin_chat), 19 June 2006
hi , i am very new to java programming. i want to implement some thing shown below.

i read a file and parse a line and find tokens from it. for example

cache  M  var1  p1_seg  ram

i get tokens by
instCache = tokens.nextToken();
instType = tokens.nextToken();
instVar = tokens.nextToken();
instSeg = tokens.nextToken();
instModule = tokens.nextToken();

i have such type of many strings in file. i have to parse them and find the names of variable, type of cahe operation , segment name and module name.

there can be many strings which have same combinations of variable name , mod name , seg.
what  i want to do is for each combination of var name , seg name and mod name , i will maintain a entry and will update tyoe count if it M or H as many times.

for example

cache  M  var1  p1_seg  ram
cache  M  var1  p1_seg  ram

if there are two such entries ,

var1.p1_seg_ram will have count of M to be 2

how this can be impleted using hashes or arrays effectively

Posted by admin (Graham Ellis), 19 June 2006
If each of the lines can have a different format, then it stikes me that you would be better to hold all the various attributes that are possible in an object, and use object inheritance to relate them to one another - that way you decouple your data structure from your model.

Then store the objects in an ArrayList or Vector ... you won't be using a hash unless you have a unique key for each, and you won't be using an array unless you're sure of the number of items you have before you start populating it.

Posted by sachin_chat (sachin_chat), 19 June 2006
thanks graham,

what i was thinking was to use a class ( as structure in c) and define two members

string name ( to hold name of variable+mod+seg)
int index

then i will create a object of it . every time after i parse the line , i will compare it with object.name.

if it is null then i will add object to some array ( that i have to think of) and if  it matches with any of onject.name i will incraese my index count by 1.

what are your suggestion on this

please comment any thing wich i had thought wrong

Posted by admin (Graham Ellis), 20 June 2006
It looks sensible from such a short / summary spec.;   some people might question the need for a separate index held within each item, but I'll encourage it for anything except the tinisest of jobs.   That way, so can keep track of which object is which without having to rely on the position that something's found at in a list.



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho