API – Part 1

When you have scripts to read, write filesystems from or to machine and could go countless, it is always best to manage the directory structure nested and each sub tree go recursively nested to accomadate at that level. The benefit is that it helps in not also specific lookup, but precise write up and added broader search. We appreciate performance boost also by this structure of nested files – directory structure.

$type = type of user identifier
$handle = some seed sort, say

///////////////// handle the logic as below ///////////////////////////
$handle = strtolower($handle);
$hash = 0;
for($i=0; $i < strlen($handle) ; $i++)
{
$value = substr($handle, $i, 1);
$hash = $hash*23 + ord($value);
$hash %= 8000;
}
$home=””;
if ($type ==”user”)
{
$home .=SERVER_PATH.(1+($hash % 8));
}
$hash >>=3;
$hash %=1000;
if ($type ==”user”)
{
$home .= “/$hash/$handle”;
}
else
{
$home .= “/$hash/”;
}
return $home;
}    #    end function.
///////////////////////////////////////////////////////////////////////////

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: