twitter
    Find out what I'm doing, Follow Me :)

Hash Table එක

Saerch එන්ජිම හදපු හැ‍ටි හා සබැදියි......
Hash table එකක් යනු භාවිතයට ඉතා පහසු දත්ත සැකසුමකි. එහිදී දත්ත වලට key එකක් ලබා දී ඒ අනුව දත්ත ගබඩා කර‍යි.

Key එකක් ලබාගන්නේ කෙසේද?....
පහත වචන සලකා බලමු...

වචනය      
hash code එක       key එක (hash code(mod 101))

සර්ච්
1245759 25

දත්ත
227811409 51

එන්ජිම
66066423 0

Hash code එකක් යනු සෑම වචනයක් සදහාම අනන්‍ය code එකක් ලබා දෙන ක්‍රමයකි. එහිදී ලැබෙන අනන්‍ය code එක ප්‍රථමක සංඛ්‍යාවකින් බෙදූ විට ලැබෙනා සංඛ්‍යාව එම ප්‍රථමක සංඛ්‍යාවට වඩා අඩු සංඛ්‍යාවකි. එනම් (0-100) අතර වේ.
එකම කී එකක් ඇති වචන කිහිපයක් තිබිය හැක. එවි‍ට දත්ත ඇතුලත් කිරී‍මට Link List එකක් ඇතුලත් ක‍ල හැක. එය සාමා‍න්යහ ක්‍රමයයි. මෙහිදී Dynamic Array හෝ පහසුව තකා Array List භාවිතා කල හැක. මෙම දෙ‍විදියේදීම දත්ත සැකැස්ම අවශ්‍ය පරිදි වර්දනය වේ.

Text File සර්ච් කිරිම

sub folder එකක් ඇතුලේ text file පමනක් සොයගැනීමට ක්‍රම කිහිපයක් ඇත.
මේ සදහා file list හො file filter එකක් යොදාගත හැක.
file filter එකක් යොද ගනීනම් මුලින් filter එක අපට අවෂ්‍ය පරිදි එම interface එකේ attributes සාද ගත යුතුය. පහත පරිදි එය සකසා ගත හැක.

protected fileFilter()
{
txtFilter = new FileFilter() //filefilter atribute වෙනස් කිරීම
{
public boolean accept(File file)
{
String sPath = file.getName();//file වල නම් ලබා ගැනීම

if( sPath.endsWith(".txt") )
{
return true;
}
else
{
return false;
}
}
};

}

ඉහත interface එක වෙනත් ෆයිල් වර්ග සොයගැනීමට ද යොද ගත හැක. ".txt" යන ස්ථානයෙහි ඔබට අවෂ්‍ය extention (උදා- ".jpg" , ".avi") එක ලබා දීමෙන් එය කරගැනීමට පුලුවන්.

මෙමගින් අපි text file සොයගත්තද එය එක් ෆොල්ඩරයක් සදහා පමණි. දැන් එය sub folder වලත් සර්ච් කල හැකි ලෙස සාදන්නේ කෙසේදැයි බලමු. මෙ සදහා recurtion method එකක් භාවිතා කිරීම වැඩය පහසු කරවයි. recurtion method

එකක් යනු method එකක් මගින් එම method එකම නැවත නැවත call කිරීමයි.

එම method එක වැඩ කරන විටම සොයගත් text ෆයිල් වෙනස් නොවන List එකකට දම ගතයුතුය. අවසානයේ text ෆයිල් list එක පහසුවෙන් ලැබේ. අදාල code එක පහත පරිදි වේ.

protected void getFiles(String dirPath) throws IOException
{
File dir = new File(dirPath);
if(dir.exists()) // සියලු file තෝරා ගැනීම හා list කිරීම
{
File[] allFiles = dir.listFiles();
if(allFiles != null)
{

for(int n = 0; n < allFiles.length; n++)
{
if(allFiles[n].isDirectory())
{
String ss=allFiles[n].getPath();

this.getFiles(ss);
}
}
}
else
{
System.out.println("No files in folder: "+ dirPath);
}

File[] txtFiles = dir.listFiles(txtFilter); // සියලු text file තෝරා ගැනීම හා list කිරීම
if(txtFiles != null)
{
for(int n = 0; n < txtFiles.length; n++)
{
String path=txtFiles[n].getCanonicalPath(); //absolute path එක ලබා ගැනීම
r.read(path); //read කරන්න ‍යැවීම
}
}
else
{
System.out.println("No text files in folder: "+ dirPath);
}

}
else
{
System.out.println("Folder "+ dirPath + " does not exist!");
}
}

Searching එන්ජිම හැදුවෙ මෙහෙමයි

Department එකේ හරියට වැඞ. ඒ අස්සෙ මෙන්න search එන්ජිමක් හදන්න දුන්නෙ නැතෑ JAVA වලින්.
මොනව කරන්නද? හැදුව

විස්තරය
මෙමගින් ඕනෑම text file එකක දී ඇති වචනයක් හෝ වචන ඛණ්ඩයක් සොයා ගත හැකි විය යුතුය.
* දී ඇති ෆෝල්ඩරයක ඇති අනු ෆෝල්ඩර වල text file ද සොයා ගත යුතුය.
*text file එකක ඇති වචන අතර හිස් තැනක් හෝ මෙම විරාම ලකුණු තිබිය හැක {, . ; :}
*මෟදුකාංගය භාවිතා කරන්නා වචනයක් හෝ වචන ඛණ්ඩයක සංයෝජනයක් දුන් විට ( &- සහ ‍‍‍‍‍‍‍‍| -හෝ )
එම වචනය හෝ වචන ඛණ්ඩය ඇති text file Path එක ලබා දිය යුතුය.

උදාහරණය
text file ඇති ස්ථානයන් හා එහි අඩංගු වචන

File1.txt (Path - C:\SearchEngineFiles\File1.txt)
In computer science, a hash table, or a hash map, is a

data structure that associates keys with values.

File2.txt (Path - C:\SearchEngineFiles\SubFolder2\

File2.txt)
Project Text File Search Engine
The major advantage of binary search trees over other

data structures is that the related sorting
algorithms and search algorithms such as in-order

traversal can be very efficient.

File3.txt (Path - C:\SearchEngineFiles\SubFolder3\ File3.txt)
In computer science, a stack is an abstract data type and
data structure based on the principle of Last In
First Out.
The following are sample queries and expected answers

මෟදුකාංගය භාවිතා කරන්නා පහත වචනය හෝ වචන ඛණ්ඩය දුන් විට එම වචනය ඇති File Path පහත පරිදි

ලබා දිය යුතුය.

වචනය : computer
File1.txt (Path - C:\SearchEngineFiles\File1.txt)
File3.txt (Path - C:\SearchEngineFiles\SubFolder3\ File3.txt)
වචන ඛණ්ඩය(හෝ): hash | binary
File1.txt (Path - C:\SearchEngineFiles\File1.txt)
File2.txt (Path - C:\SearchEngineFiles\SubFolder3\

File3.txt)
වචන ඛණ්ඩය(සහ): data & structure & stack
File3.txt (Path - C:\SearchEngineFiles\SubFolder3\ File3.txt)