Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3494986
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:04:18+00:00 2026-05-18T12:04:18+00:00

The Go spec states : The comparison operators == and != (§Comparison operators) must

  • 0

The Go spec states:

The comparison operators == and != (§Comparison operators) must be fully defined for operands of the key type; thus the key type must not be a struct, array or slice. If the key type is an interface type, these comparison operators must be defined for the dynamic key values; failure will cause a run-time panic.

I wish to create a map of hash values which come from the Hash interface, which returns []byte, but for which all my hashes are done with the same algorithm (thereby I know that it would fit into [16]byte). How can I provide the appropriate interface such that the map type will allow []byte or [16]byte or some wrapper thereof to be used as a key?

Presently my use generates the following error:

dupes := make(map[[16]byte][]string)
finddups.go:55: invalid map key type [16]uint8

Update (Mar 2012): Go1 allows [16]byte as key type.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T12:04:19+00:00Added an answer on May 18, 2026 at 12:04 pm

    A string type represents the set of UTF-8 encoded string values. Strings behave like arrays of bytes. See rules 2 and 4 for byte slices in the Conversions to and from a string type topic in the Conversions section of The Go Language Specification.

    package main
    
    import "fmt"
    
    func main() {
        dupes := make(map[string][]string)
    
        hash := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}
        dupes[string(hash)] = []string{"a", "b"}
        hash[len(hash)-1]++
        dupes[string(hash)] = []string{"b", "c"}
    
        fmt.Println("len:", len(dupes))
        for k, v := range dupes {
            fmt.Println("key:", []byte(k), "value:", v)
        }
    }
    

    Output:

    len: 2
    key: [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 16] value: [b c]
    key: [0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15] value: [a b]
    

    Note: This algorithm merely takes advantage of the rules for string types and conversions given in The Go Language Specification, which all implementations must satisfy. It’s a “trick”, just like var i int = '7' - '0' (for ASCII, EBCDIC, Unicode, etc.) is a “trick” to convert a numeric character ‘7’ to an integer value 7, in Go and many other languages.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Paragraph 6.7.3.8 of the C99 spec states If the specification of an array type
While the C# spec does include a pre-processor and basic directives (#define, #if, etc),
Does the functional spec help or hinder your expectations? Do programmers who practice the
The C# 3.0 spec has the following code example in section 10.6.1.3 Output parameters:
I have a spec in my current project that requires us to advise the
Does anyone here use Spec# regularly? I would like to know if it is
Here is the spec: Multiple clients using a WPF winforms application on their local
The JDBC 3.0 spec talks about Connection (and Prepared Statement) pooling. We have several
I'm working on a spec for a piece of software for my company and
From my understanding of the CSS spec, a table above or below a paragraph

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.