Skip to content

Index.go: question around line 75 #3

@brjg

Description

@brjg

In function 'add', each time append a posting. In function 'Add', for each changed term, sort the postings according to their DID to maintain sorted.

In 'add' function, instead of append the new posting at the end, if use binary search to find the loc to insert, we maintain the sorted order by nature. Then we don't need the work in 'Add' function. It will become more efficient.

something like this around https://github.com/topicai/weakand/blob/develop/index.go#L75:

for term, tf := range d.Terms {
    insertPos = sort.Search(len(idx.Ivt[term]), func(i int) bool {return idx.Ivt[term][i].DocId >= did})
    idx.Ivt[term] = append(idx.Ivt[:insertPos], append(Posting{DocId: did, TF: tf}, idx.Ivt[insertPos:]...)...)
    // changed[term]++
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions