# RFC: hash table pattern matching

**URL:** <https://racket.discourse.group/t/rfc-hash-table-pattern-matching/1686>\
**Category:** General\
**Created:** [February 3, 2023, 10:00pm UTC](https://racket.discourse.group/t/rfc-hash-table-pattern-matching/1686 "2023-02-03T22:00:51Z")\
**Posts on this page:** 1\
**Showing post:** 16

<div class="post-metadata">

**Author:** ![sorawee](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@sorawee](https://racket.discourse.group/u/sorawee)\
**Post date:** [February 6, 2023, 12:02am UTC](https://racket.discourse.group/t/rfc-hash-table-pattern-matching/1686/16 "2023-02-06T00:02:16Z")

</div>

On second thought, I think I would prefer allowing duplicates, which makes partial matching significantly faster, while full matching is still as slow as it currently is.

In the current implementation of `hash*`, which disallows duplicates:

```scheme
"partial match"
cpu time: 2124 real time: 2218 gc time: 27
"full match"
cpu time: 2152 real time: 2255 gc time: 8
"hash-table, which is buggy, but it allows partial match and duplications"
cpu time: 1126 real time: 1220 gc time: 1

```

But if `hash*` allows duplicates:

```scheme
"partial match"
cpu time: 589 real time: 624 gc time: 22
"full match"
cpu time: 2052 real time: 2142 gc time: 7
"hash-table, which is buggy, but it allows partial match and duplications"
cpu time: 1096 real time: 1173 gc time: 0

```

Here’s the benchmark:

```scheme
#lang racket

(require "hash-pattern.rkt")

(define N 10000000)

(define (test h)
  (match h
    [(hash* [1 v] [2 v2] [3 v3])
     (list v v2 v3)]))

(define (test2 h)
  (match h
    [(hash* [1 v] [2 v2] [3 v3] #:full)
     (list v v2 v3)]))

(define (test3 h)
  (match h
    [(hash-table [1 v] [2 v2] [3 v3])
     (list v v2 v3)]))

(define h (hash 1 2 2 3 3 4))

"partial match"
(time (for ([i (in-range N)])
        (test h)))

"full match"
(time (for ([i (in-range N)])
        (test2 h)))

"hash-table, which is buggy, but it allows partial match and duplications"
(time (for ([i (in-range N)])
        (test3 h)))

```

---

_[View the full topic](https://racket.discourse.group/t/rfc-hash-table-pattern-matching/1686)._
