Home » Source Code » Hash algorithms » lshcode/lshins.m

lshcode/lshins.m ( File view )

  • By 毛宁 2014-10-28
  • View(s):33
  • Download(s):0
  • Point(s): 1
			function T = lshins(T,x,ind)
% T = lshins(T,X)
%     insert data (columns of X) into T
% NOTE: LSH will only index the data - not store it! You need to keep
% around the original data, in order to go back from indices to actual
% points, if that's what you want to do.
% T = lshins(T,X,IND)
%   instead of assuming that columns of X have indices 1..size(X,2), uses IND
% (C) Greg Shakhnarovich, TTI-Chicago (2008)

% fields of T:
% buckets : bukets(j,:) is the hash key of bucket j
% Index : Index{
} contains indices of data in bucket j
% count : count(j) contains the size of bucket j

if (nargin < 3 | isempty(ind))

% insert in each table
for j=1:length(T)
  % the # of buckets before new data
  % find, for each data point, the corresp. bucket
  % bucket numbers are represented as arrays of uint8
  buck = findbucket(T(j).type,x,T(j).I);
  % now x(:,n) goes to bucket with key uniqBuck(bID(n))
  [uniqBuck,ib,bID] = unique(buck,'rows');
  keys = lshhash(uniqBuck);
  if (T(j).verbose > 0)
    fprintf(2,'%d distinct buckets\n',length(ib));
  % allocate space for new buckets -- possibly excessive
  T(j).buckets=[T(j).buckets; zeros(length(ib),T(j).I.k,'uint8')];
  for b=1:length(ib)
    % find which data go to bucket uniqBuck(b)
    thisBucket = find(bID==bID(ib(b)));
    % find out if this bucket already has anything
    % first, which bucket is it?
    ihash = T(j).bhash{
}; % possible matching buckets
    if (isempty(ihash)) % nothing matches
      isb = [];
    else % may or may not match
      isb = ihash(find(all(bsxfun(@eq,uniqBuck(b,:),T(j).buckets(ihash,:)),2)));
    % note: this search is the most costly operation
    %isb = find(all(bsxfun(@eq,uniqBuck(b,:),T(j).buckets),2));
    if (~isempty(isb)) 
      % adding to an existing bucket.
}); % # elements in the bucket prior
                                        % to addition
      newIndex = [T(j).Index{
}  ind(thisBucket)];
      % creating new bucket
(Please download the complete source code to view)
Expand> <Close

Want complete source code? Download it here

Point(s): 1

0 lines left, continue to read
Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
0.00 B2009-06-26|22:00
findbucket.m653.00 B2008-11-10|12:45
lpnorm.m3.79 kB2008-11-10|12:45
lsh.m3.18 kB2008-11-10|12:45
lshfunc.m2.94 kB2008-11-10|12:45
lshhash.m957.00 B2008-11-10|12:45
lshins.m3.21 kB2008-11-10|12:45
lshlookup.m3.07 kB2009-06-26|21:35
lshprep.m1.56 kB2008-11-10|12:45
lshstats.m2.36 kB2009-06-26|21:36
processRange.m1.01 kB2008-11-10|12:45
README10.58 kB2009-06-26|22:00
Sponsored links

lshcode/lshins.m (12.66 kB)

Need 1 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point


Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com


CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D