Giter VIP home page Giter VIP logo

Comments (3)

bmatsuo avatar bmatsuo commented on May 21, 2024

I think its possible that a straightforward solution to this problem is to have the Scanner.Set and Scanner.SetNext functions actually call Cursor.Get, setting Scanner.Key, Scanner.Val, and Scanner.Err and buffering the result for the next call to Scanner.Scan.

    err := env.View(func(txn *lmdb.Txn) (err error) {
        scanner := lmdbscan.New(txn, dbi)
        defer scanner.Close()

        for scanner.SetNext(nil, nil, lmdb.NextNoDup, lmdb.NextDup)  {
            var vals [][]byte
            k := scanner.Key()
            for scanner.Scan() {
                vals = append(vals, scanner.Val())
            }
            log.Printf("k=%q vals=%q", k, vals)

            // this may even be optional
            if scanner.Err() != nil {
                return scanner.Err()
            }
        }
        return scanner.Err()
    })
    if err != nil {
        panic(err)
    }

I believe that this can also work for scanning DupFixed databases.

    err := env.View(func(txn *lmdb.Txn) (err error) {
        scanner := lmdbscan.New(txn, dbi)
        defer scanner.Close()

        for scanner.Set(nil, nil, lmdb.NextNoDup) {
            var vals [][]byte
            k := scanner.Key()
            dup0 := scanner.Val()
            if scanner.SetNext(nil, nil, lmdb.GetMultiple, lmdb.NextMultiple) {
                vals = [][]byte{dup0}
            }
            for scanner.Scan() {
                multi := lmdb.WrapMulti(scanner.Val(), len(dup0))
                vals = append(vals, multi.Vals()...)
            }
            log.Printf("k=%q vals=%q", k, vals)

            // this may even be optional
            if scanner.Err() != nil {
                return scanner.Err()
            }
        }
        return scanner.Err()
    })
    if err != nil {
        panic(err)
    }

from lmdb-go.

bmatsuo avatar bmatsuo commented on May 21, 2024

I think the proposed solution seems pretty good. The lmdb.GetMultiple example is a little clumsy. But afaict at the moment that is because the operation itself is a little clumsy, forcing a distinction between duplicates and a single value.

from lmdb-go.

bmatsuo avatar bmatsuo commented on May 21, 2024

I think this is orthogonal to a separate method to set opnext, proposed in #18. If such a method exists it should probably advance the cursor when it is called and return a bool too.

from lmdb-go.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.