
function [hashmap_size_out, hashmap_out, wordslist_out] = update_hashmap(words, hashmap_size, hashmap, min_word_len, wordslist, stems, min_wordcount)



    
    if nargin<3
        hashmap = java.util.Properties;
    end

    if nargin<2
        hashmap_size = size(hashmap);
    end
    
    if nargin<4
        min_word_len = 1;
    end
    
    if nargin<5
        wordslist = {};
    end
    
    if nargin<6
        stems = {};
    end
    
    if nargin<7
        min_wordcount = 3;
    end
    


    % curr_mapsize = size(hashmap);
    curr_mapsize = hashmap_size;
    
    
    num_words = length(words);
    for i = 1:num_words
       
        word = char(words(i));
        
        
        if strcmp(word, 'kohustus')
            
            qqq = 1; %#ok<NASGU>
            
        end
        
        
        if length(word) >= min_word_len
        
            if ~hashmap.containsKey(word)

                % curr_mapsize = curr_mapsize + 1;
                % hashmap.put(word, curr_mapsize);
                
                
                if ~isempty(stems)
                    
                    stem = char(stems(i));
                    
                    
                    if strcmp(stem, 'kohustus')
            
                        qqq = 1; %#ok<NASGU>

                    end
                    
                    
                    if ~hashmap.containsKey(stem)
                        
                        curr_mapsize = curr_mapsize + 1;
                        data = [curr_mapsize; 1; 0; 0];
                                                
                        if 1 >= min_wordcount
                            % hashmap_size = max(hashmap_size, curr_mapsize);
                            hashmap_size = hashmap_size + 1;
                            data(3) = 1;
                            data(4) = hashmap_size;
                        end
                        
                        hashmap.put(word, data);
                        hashmap.put(stem, data);
                        
                    else     % if ~hashmap.containsKey(stem)
                        
                        data = hashmap.get(stem);
                        % stem_index = data(1);
                        usage_count = data(2);
                        usage_count = usage_count + 1;
                        data(2) = usage_count;
                        
                        
                        if usage_count >= min_wordcount && ~data(3)
                            % hashmap_size = max(hashmap_size, stem_index);
                            hashmap_size = hashmap_size + 1;
                            data(3) = 1;
                            data(4) = hashmap_size;
                        end

                        hashmap.put(word, data);
                        hashmap.put(stem, data);

                        
                    end     % if ~hashmap.containsKey(stem)
                    
                else     % if ~isempty(stems)
                    
                    curr_mapsize = curr_mapsize + 1;
                    data = [curr_mapsize; 1; 0; 0];                    
                    
                    if 1 >= min_wordcount
                        % hashmap_size = max(hashmap_size, curr_mapsize);
                        hashmap_size = hashmap_size + 1;
                        data(3) = 1;
                        data(4) = hashmap_size;
                    end
                    
                    hashmap.put(word, data);
                    
                end     % if ~isempty(stems)
                
                
                wordslist(curr_mapsize) = {word};
                
            else     % if ~hashmap.containsKey(word)                
                
                
                if ~isempty(stems)
                    
                    stem = char(stems(i));
                    data = hashmap.get(stem);
                    % stem_index = data(1);
                    usage_count = data(2);
                    usage_count = usage_count + 1;
                    data(2) = usage_count;
                    
                    if usage_count >= min_wordcount && ~data(3)
                        % hashmap_size = max(hashmap_size, stem_index);
                        hashmap_size = hashmap_size + 1;
                        data(3) = 1;
                        data(4) = hashmap_size;
                    end
                    
                    hashmap.put(word, data);
                    hashmap.put(stem, data);
                    
                else
                    
                    data = hashmap.get(word);
                    usage_count = data(2);
                    usage_count = usage_count + 1;
                    data(2) = usage_count;
                    
                    if usage_count >= min_wordcount && ~data(3)
                        % hashmap_size = max(hashmap_size, stem_index);
                        hashmap_size = hashmap_size + 1;
                        data(3) = 1;
                        data(4) = hashmap_size;
                    end                    
                    
                    hashmap.put(word, data);
                    
                end     % if ~isempty(stems)
                
                
            end     % if ~hashmap.containsKey(word)
            
        end     % if length(word) > min_word_len
        
    end     % for i = 1:num_words


    hashmap_size_out = hashmap_size;
    hashmap_out = hashmap;
    wordslist_out = wordslist;
    
    
end
