Monday, April 17, 2017

OSX spotlight search on external folders
OSX allows external folders to be connected on the MacBook. These folders can be accessed over file system protocols that support either linux only or both linux and Windows platforms. Usually external folders are larger than any on the local disk because they are sought to expand the capacity of the local storage. These remote folders can be quite large ranging from a few Gigabytes all the way to order of terabytes.
Spotlight search enables user to quickly lookup a file based on some content words. Files that appear in the results are already indexed so the lookup is faster than scanning tools like grep. Spotlight search works based on populating an index from existing folders. This index can be arbitrarily large depending on the amount of data indexed.
External files and folders can be added to Spotlight search, by way of configuration. We go to System Preferences, Spotlight and Privacy and add folders and disks through the plus sign at the bottom left.
We can exclude some folders to reduce the load on Spotlight. Folders that are included must have connectivity for the duration of the indexing until the indexes are built. We can start and stop the indexing using command line tools like mdutil.
Where external files and folders are added, their index can become larger than usual. Typically the metadata is stored in a hidden folder .Spotlight-V100 at the root of the indexed volume. When indexes and the data are both large, it would benefit to separate the index from the data on the disk because they have different access. The values of the attributes that get stored in the metadata folder depends on the com.apple.metadata:kMDItemFinderComment.
Usually the Spotlight preferences involve Search results and privacy tabs which can help with customizing the Spotlight search.
Indexes may get out of date as new contents are added and the folders are included or excluded from Spotlight search. Rebuilding the index works in these regards.

#codingexercise
Given a right triangle of numbers, find the largest of the sum of numbers that appear on the paths starting from the top towards the base, so that on each path the next number is located directly below or below-and-one-place-to-the-right.
void GetMaxSumTriangle(int[,] M, int n, ref List<int> sums)
{
if (n== 0) { sums[0] += M[0,0]; return; }
GetMaxSumTriangle(M,n-1, ref sums);
sums[0] = M[n-1, 0] + M[n,0];
for (int j = 1; j <=n; j++){
     top = (j <n ? M[n-1, j] + M[n,j] : 0)
     topleft = (j-1>=0 ? M[n-1,j-1] + M[n,j] : 0)
     sums[j] = Math.max(top, topleft) + sums[j];
}
}
sums.max();
For example:
2
4 1
1 2 7
Sums:
2
6 3
7 8 10

The critical path changes at every level.

No comments:

Post a Comment