Debian Codegraph @

trees/binaryheap/serialization.go

raw symbols SCIP
1 // Copyright (c) 2015, Emir Pasic. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package binaryheap
6
7 import (
8 "github.com/emirpasic/gods/v2/containers"
9 )
10
11 // Assert Serialization implementation
12 var _ containers.JSONSerializer = (*Heap[int])(nil)
13 var _ containers.JSONDeserializer = (*Heap[int])(nil)
14
15 // ToJSON outputs the JSON representation of the heap.
16 func (heap *Heap[T]) ToJSON() ([]byte, error) {
17 return heap.list.ToJSON()
18 }
19
20 // FromJSON populates the heap from the input JSON representation.
21 func (heap *Heap[T]) FromJSON(data []byte) error {
22 return heap.list.FromJSON(data)
23 }
24
25 // UnmarshalJSON @implements json.Unmarshaler
26 func (heap *Heap[T]) UnmarshalJSON(bytes []byte) error {
27 return heap.FromJSON(bytes)
28 }
29
30 // MarshalJSON @implements json.Marshaler
31 func (heap *Heap[T]) MarshalJSON() ([]byte, error) {
32 return heap.ToJSON()
33 }