id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
12,300
mattetti/audio
dsp/filters/sinc.go
LowPassCoefs
func (s *Sinc) LowPassCoefs() []float64 { if s == nil { return nil } if s._lowPassCoefs != nil && len(s._lowPassCoefs) > 0 { return s._lowPassCoefs } size := s.Taps + 1 // sample rate is 2 pi radians per second. // we get the cutt off frequency in radians per second b := (2 * math.Pi) * s.TransitionFreq() ...
go
func (s *Sinc) LowPassCoefs() []float64 { if s == nil { return nil } if s._lowPassCoefs != nil && len(s._lowPassCoefs) > 0 { return s._lowPassCoefs } size := s.Taps + 1 // sample rate is 2 pi radians per second. // we get the cutt off frequency in radians per second b := (2 * math.Pi) * s.TransitionFreq() ...
[ "func", "(", "s", "*", "Sinc", ")", "LowPassCoefs", "(", ")", "[", "]", "float64", "{", "if", "s", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "if", "s", ".", "_lowPassCoefs", "!=", "nil", "&&", "len", "(", "s", ".", "_lowPassCoefs", ")",...
// LowPassCoefs returns the coeficients to create a low pass filter
[ "LowPassCoefs", "returns", "the", "coeficients", "to", "create", "a", "low", "pass", "filter" ]
c6aebeb78429d88ff11f1468dac519ead57e7196
https://github.com/mattetti/audio/blob/c6aebeb78429d88ff11f1468dac519ead57e7196/dsp/filters/sinc.go#L28-L55
12,301
mattetti/audio
dsp/filters/sinc.go
HighPassCoefs
func (s *Sinc) HighPassCoefs() []float64 { if s == nil { return nil } if s._highPassCoefs != nil && len(s._highPassCoefs) > 0 { return s._highPassCoefs } // we take the low pass coesf and invert them size := s.Taps + 1 s._highPassCoefs = make([]float64, size) lowPassCoefs := s.LowPassCoefs() winData := s....
go
func (s *Sinc) HighPassCoefs() []float64 { if s == nil { return nil } if s._highPassCoefs != nil && len(s._highPassCoefs) > 0 { return s._highPassCoefs } // we take the low pass coesf and invert them size := s.Taps + 1 s._highPassCoefs = make([]float64, size) lowPassCoefs := s.LowPassCoefs() winData := s....
[ "func", "(", "s", "*", "Sinc", ")", "HighPassCoefs", "(", ")", "[", "]", "float64", "{", "if", "s", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "if", "s", ".", "_highPassCoefs", "!=", "nil", "&&", "len", "(", "s", ".", "_highPassCoefs", "...
// HighPassCoefs returns the coeficients to create a high pass filter
[ "HighPassCoefs", "returns", "the", "coeficients", "to", "create", "a", "high", "pass", "filter" ]
c6aebeb78429d88ff11f1468dac519ead57e7196
https://github.com/mattetti/audio/blob/c6aebeb78429d88ff11f1468dac519ead57e7196/dsp/filters/sinc.go#L58-L78
12,302
mattetti/audio
dsp/filters/sinc.go
TransitionFreq
func (s *Sinc) TransitionFreq() float64 { if s == nil { return 0 } return s.CutOffFreq / float64(s.SamplingFreq) }
go
func (s *Sinc) TransitionFreq() float64 { if s == nil { return 0 } return s.CutOffFreq / float64(s.SamplingFreq) }
[ "func", "(", "s", "*", "Sinc", ")", "TransitionFreq", "(", ")", "float64", "{", "if", "s", "==", "nil", "{", "return", "0", "\n", "}", "\n", "return", "s", ".", "CutOffFreq", "/", "float64", "(", "s", ".", "SamplingFreq", ")", "\n", "}" ]
// TransitionFreq returns a ratio of the cutoff frequency and the sample rate.
[ "TransitionFreq", "returns", "a", "ratio", "of", "the", "cutoff", "frequency", "and", "the", "sample", "rate", "." ]
c6aebeb78429d88ff11f1468dac519ead57e7196
https://github.com/mattetti/audio/blob/c6aebeb78429d88ff11f1468dac519ead57e7196/dsp/filters/sinc.go#L81-L86
12,303
mattetti/audio
midi/event.go
EndOfTrack
func EndOfTrack() *Event { return &Event{ MsgType: uint8(EventByteMap["Meta"]), MsgChan: uint8(15), Cmd: MetaByteMap["End of Track"], } }
go
func EndOfTrack() *Event { return &Event{ MsgType: uint8(EventByteMap["Meta"]), MsgChan: uint8(15), Cmd: MetaByteMap["End of Track"], } }
[ "func", "EndOfTrack", "(", ")", "*", "Event", "{", "return", "&", "Event", "{", "MsgType", ":", "uint8", "(", "EventByteMap", "[", "\"", "\"", "]", ")", ",", "MsgChan", ":", "uint8", "(", "15", ")", ",", "Cmd", ":", "MetaByteMap", "[", "\"", "\"", ...
// EndOfTrack indicates the end of the midi track. Note that this event is // automatically added when encoding a normal track.
[ "EndOfTrack", "indicates", "the", "end", "of", "the", "midi", "track", ".", "Note", "that", "this", "event", "is", "automatically", "added", "when", "encoding", "a", "normal", "track", "." ]
c6aebeb78429d88ff11f1468dac519ead57e7196
https://github.com/mattetti/audio/blob/c6aebeb78429d88ff11f1468dac519ead57e7196/midi/event.go#L33-L39
12,304
mattetti/audio
midi/event.go
Aftertouch
func Aftertouch(channel, key, vel int) *Event { return &Event{ MsgChan: uint8(channel), MsgType: uint8(EventByteMap["AfterTouch"]), Note: uint8(key), Velocity: uint8(vel), } }
go
func Aftertouch(channel, key, vel int) *Event { return &Event{ MsgChan: uint8(channel), MsgType: uint8(EventByteMap["AfterTouch"]), Note: uint8(key), Velocity: uint8(vel), } }
[ "func", "Aftertouch", "(", "channel", ",", "key", ",", "vel", "int", ")", "*", "Event", "{", "return", "&", "Event", "{", "MsgChan", ":", "uint8", "(", "channel", ")", ",", "MsgType", ":", "uint8", "(", "EventByteMap", "[", "\"", "\"", "]", ")", ",...
// AfterTouch returns a pointer to a new aftertouch event
[ "AfterTouch", "returns", "a", "pointer", "to", "a", "new", "aftertouch", "event" ]
c6aebeb78429d88ff11f1468dac519ead57e7196
https://github.com/mattetti/audio/blob/c6aebeb78429d88ff11f1468dac519ead57e7196/midi/event.go#L42-L49
12,305
mattetti/audio
midi/event.go
ControlChange
func ControlChange(channel, controller, newVal int) *Event { return &Event{ MsgChan: uint8(channel), MsgType: uint8(EventByteMap["ControlChange"]), Controller: uint8(controller), NewValue: uint8(newVal), } }
go
func ControlChange(channel, controller, newVal int) *Event { return &Event{ MsgChan: uint8(channel), MsgType: uint8(EventByteMap["ControlChange"]), Controller: uint8(controller), NewValue: uint8(newVal), } }
[ "func", "ControlChange", "(", "channel", ",", "controller", ",", "newVal", "int", ")", "*", "Event", "{", "return", "&", "Event", "{", "MsgChan", ":", "uint8", "(", "channel", ")", ",", "MsgType", ":", "uint8", "(", "EventByteMap", "[", "\"", "\"", "]"...
// ControlChange sets a new value for a given controller // The controller number is between 0-119. // The new controller value is between 0-127.
[ "ControlChange", "sets", "a", "new", "value", "for", "a", "given", "controller", "The", "controller", "number", "is", "between", "0", "-", "119", ".", "The", "new", "controller", "value", "is", "between", "0", "-", "127", "." ]
c6aebeb78429d88ff11f1468dac519ead57e7196
https://github.com/mattetti/audio/blob/c6aebeb78429d88ff11f1468dac519ead57e7196/midi/event.go#L54-L61
12,306
mattetti/audio
midi/event.go
ChannelAfterTouch
func ChannelAfterTouch(channel, vel int) *Event { return &Event{ MsgChan: uint8(channel), MsgType: uint8(EventByteMap["ChannelAfterTouch"]), Pressure: uint8(vel), } }
go
func ChannelAfterTouch(channel, vel int) *Event { return &Event{ MsgChan: uint8(channel), MsgType: uint8(EventByteMap["ChannelAfterTouch"]), Pressure: uint8(vel), } }
[ "func", "ChannelAfterTouch", "(", "channel", ",", "vel", "int", ")", "*", "Event", "{", "return", "&", "Event", "{", "MsgChan", ":", "uint8", "(", "channel", ")", ",", "MsgType", ":", "uint8", "(", "EventByteMap", "[", "\"", "\"", "]", ")", ",", "Pre...
// ChannelAfterTouch is a global aftertouch with a value from 0 to 127
[ "ChannelAfterTouch", "is", "a", "global", "aftertouch", "with", "a", "value", "from", "0", "to", "127" ]
c6aebeb78429d88ff11f1468dac519ead57e7196
https://github.com/mattetti/audio/blob/c6aebeb78429d88ff11f1468dac519ead57e7196/midi/event.go#L75-L81
12,307
mattetti/audio
midi/event.go
PitchWheelChange
func PitchWheelChange(channel, int, val int) *Event { return &Event{ MsgChan: uint8(channel), MsgType: uint8(EventByteMap["PitchWheelChange"]), AbsPitchBend: uint16(val), } }
go
func PitchWheelChange(channel, int, val int) *Event { return &Event{ MsgChan: uint8(channel), MsgType: uint8(EventByteMap["PitchWheelChange"]), AbsPitchBend: uint16(val), } }
[ "func", "PitchWheelChange", "(", "channel", ",", "int", ",", "val", "int", ")", "*", "Event", "{", "return", "&", "Event", "{", "MsgChan", ":", "uint8", "(", "channel", ")", ",", "MsgType", ":", "uint8", "(", "EventByteMap", "[", "\"", "\"", "]", ")"...
// PitchWheelChange is sent to indicate a change in the pitch bender. // The possible value goes between 0 and 16383 where 8192 is the center.
[ "PitchWheelChange", "is", "sent", "to", "indicate", "a", "change", "in", "the", "pitch", "bender", ".", "The", "possible", "value", "goes", "between", "0", "and", "16383", "where", "8192", "is", "the", "center", "." ]
c6aebeb78429d88ff11f1468dac519ead57e7196
https://github.com/mattetti/audio/blob/c6aebeb78429d88ff11f1468dac519ead57e7196/midi/event.go#L85-L91
12,308
mattetti/audio
midi/event.go
CopyrightEvent
func CopyrightEvent(txt string) *Event { return &Event{ MsgType: uint8(EventByteMap["Meta"]), Cmd: uint8(MetaByteMap["Copyright"]), Copyright: txt, } }
go
func CopyrightEvent(txt string) *Event { return &Event{ MsgType: uint8(EventByteMap["Meta"]), Cmd: uint8(MetaByteMap["Copyright"]), Copyright: txt, } }
[ "func", "CopyrightEvent", "(", "txt", "string", ")", "*", "Event", "{", "return", "&", "Event", "{", "MsgType", ":", "uint8", "(", "EventByteMap", "[", "\"", "\"", "]", ")", ",", "Cmd", ":", "uint8", "(", "MetaByteMap", "[", "\"", "\"", "]", ")", "...
// CopyrightEvent returns a copyright event with the passed string in it.
[ "CopyrightEvent", "returns", "a", "copyright", "event", "with", "the", "passed", "string", "in", "it", "." ]
c6aebeb78429d88ff11f1468dac519ead57e7196
https://github.com/mattetti/audio/blob/c6aebeb78429d88ff11f1468dac519ead57e7196/midi/event.go#L94-L100
12,309
mattetti/audio
midi/event.go
TempoEvent
func TempoEvent(bpmF float64) *Event { ms := uint32(60000000 / bpmF) // bpm is expressed in in microseconds per MIDI quarter-note // This event indicates a tempo change. Another way of putting // "microseconds per quarter-note" is "24ths of a microsecond per MIDI // clock". Representing tempos as time per beat ...
go
func TempoEvent(bpmF float64) *Event { ms := uint32(60000000 / bpmF) // bpm is expressed in in microseconds per MIDI quarter-note // This event indicates a tempo change. Another way of putting // "microseconds per quarter-note" is "24ths of a microsecond per MIDI // clock". Representing tempos as time per beat ...
[ "func", "TempoEvent", "(", "bpmF", "float64", ")", "*", "Event", "{", "ms", ":=", "uint32", "(", "60000000", "/", "bpmF", ")", "\n\n", "// bpm is expressed in in microseconds per MIDI quarter-note", "// This event indicates a tempo change. Another way of putting", "// \"micr...
// TempoEvent returns a new tempo event of the passed value.
[ "TempoEvent", "returns", "a", "new", "tempo", "event", "of", "the", "passed", "value", "." ]
c6aebeb78429d88ff11f1468dac519ead57e7196
https://github.com/mattetti/audio/blob/c6aebeb78429d88ff11f1468dac519ead57e7196/midi/event.go#L103-L124
12,310
mattetti/audio
midi/event.go
Copy
func (e *Event) Copy() *Event { newEv := &Event{ TimeDelta: e.TimeDelta, MsgType: e.MsgType, MsgChan: e.MsgChan, Note: e.Note, Velocity: e.Velocity, Pressure: e.Pressure, Controller: e.Controller, NewValue: e.NewValue, NewProgram: e.NewProgram, Channel: e.C...
go
func (e *Event) Copy() *Event { newEv := &Event{ TimeDelta: e.TimeDelta, MsgType: e.MsgType, MsgChan: e.MsgChan, Note: e.Note, Velocity: e.Velocity, Pressure: e.Pressure, Controller: e.Controller, NewValue: e.NewValue, NewProgram: e.NewProgram, Channel: e.C...
[ "func", "(", "e", "*", "Event", ")", "Copy", "(", ")", "*", "Event", "{", "newEv", ":=", "&", "Event", "{", "TimeDelta", ":", "e", ".", "TimeDelta", ",", "MsgType", ":", "e", ".", "MsgType", ",", "MsgChan", ":", "e", ".", "MsgChan", ",", "Note", ...
// Copy returns an exact copy of the event
[ "Copy", "returns", "an", "exact", "copy", "of", "the", "event" ]
c6aebeb78429d88ff11f1468dac519ead57e7196
https://github.com/mattetti/audio/blob/c6aebeb78429d88ff11f1468dac519ead57e7196/midi/event.go#L176-L223
12,311
mattetti/audio
midi/event.go
Encode
func (e *Event) Encode() []byte { buff := bytes.NewBuffer(nil) buff.Write(EncodeVarint(e.TimeDelta)) // msg type and chan are stored together msgData := []byte{(e.MsgType << 4) | e.MsgChan} if e.MsgType == EventByteMap["Meta"] { msgData = []byte{0xFF} } buff.Write(msgData) switch e.MsgType { // unknown but ...
go
func (e *Event) Encode() []byte { buff := bytes.NewBuffer(nil) buff.Write(EncodeVarint(e.TimeDelta)) // msg type and chan are stored together msgData := []byte{(e.MsgType << 4) | e.MsgChan} if e.MsgType == EventByteMap["Meta"] { msgData = []byte{0xFF} } buff.Write(msgData) switch e.MsgType { // unknown but ...
[ "func", "(", "e", "*", "Event", ")", "Encode", "(", ")", "[", "]", "byte", "{", "buff", ":=", "bytes", ".", "NewBuffer", "(", "nil", ")", "\n", "buff", ".", "Write", "(", "EncodeVarint", "(", "e", ".", "TimeDelta", ")", ")", "\n\n", "// msg type an...
// Encode converts an Event into a slice of bytes ready to be written to a file.
[ "Encode", "converts", "an", "Event", "into", "a", "slice", "of", "bytes", "ready", "to", "be", "written", "to", "a", "file", "." ]
c6aebeb78429d88ff11f1468dac519ead57e7196
https://github.com/mattetti/audio/blob/c6aebeb78429d88ff11f1468dac519ead57e7196/midi/event.go#L260-L371
12,312
mattetti/audio
midi/event.go
Size
func (e *Event) Size() uint32 { switch e.MsgType { case 0x2, 0x3, 0x4, 0x5, 0x6, 0xC, 0xD: return 1 // Note Off, On, aftertouch, control change case 0x8, 0x9, 0xA, 0xB, 0xE: return 2 case 0xF: // meta event switch e.Cmd { // Copyright Notice case 0x02: copyright := []byte(e.Copyright) varintBytes...
go
func (e *Event) Size() uint32 { switch e.MsgType { case 0x2, 0x3, 0x4, 0x5, 0x6, 0xC, 0xD: return 1 // Note Off, On, aftertouch, control change case 0x8, 0x9, 0xA, 0xB, 0xE: return 2 case 0xF: // meta event switch e.Cmd { // Copyright Notice case 0x02: copyright := []byte(e.Copyright) varintBytes...
[ "func", "(", "e", "*", "Event", ")", "Size", "(", ")", "uint32", "{", "switch", "e", ".", "MsgType", "{", "case", "0x2", ",", "0x3", ",", "0x4", ",", "0x5", ",", "0x6", ",", "0xC", ",", "0xD", ":", "return", "1", "\n", "// Note Off, On, aftertouch,...
// Size represents the byte size to encode the event
[ "Size", "represents", "the", "byte", "size", "to", "encode", "the", "event" ]
c6aebeb78429d88ff11f1468dac519ead57e7196
https://github.com/mattetti/audio/blob/c6aebeb78429d88ff11f1468dac519ead57e7196/midi/event.go#L374-L400
12,313
mattetti/audio
mp3/id3v2/id3v2.go
ReadHeader
func (t *Tag) ReadHeader(th TagHeader) error { // id3 tag ID if !th.IsValidID() { return ErrInvalidTagHeader } // version t.Header = &Header{ Version: th.ReadVersion(), Flags: th.ReadFlags(), } size, err := th.ReadSize() if err != nil { return err } t.Header.Size = size return nil }
go
func (t *Tag) ReadHeader(th TagHeader) error { // id3 tag ID if !th.IsValidID() { return ErrInvalidTagHeader } // version t.Header = &Header{ Version: th.ReadVersion(), Flags: th.ReadFlags(), } size, err := th.ReadSize() if err != nil { return err } t.Header.Size = size return nil }
[ "func", "(", "t", "*", "Tag", ")", "ReadHeader", "(", "th", "TagHeader", ")", "error", "{", "// id3 tag ID", "if", "!", "th", ".", "IsValidID", "(", ")", "{", "return", "ErrInvalidTagHeader", "\n", "}", "\n", "// version", "t", ".", "Header", "=", "&",...
// ReadHeader reads the 10 bytes header and parses the data which gets stored in // the tag header.
[ "ReadHeader", "reads", "the", "10", "bytes", "header", "and", "parses", "the", "data", "which", "gets", "stored", "in", "the", "tag", "header", "." ]
c6aebeb78429d88ff11f1468dac519ead57e7196
https://github.com/mattetti/audio/blob/c6aebeb78429d88ff11f1468dac519ead57e7196/mp3/id3v2/id3v2.go#L47-L64
12,314
mattetti/audio
aiff/encoder.go
Close
func (e *Encoder) Close() error { // go back and write total size if _, err := e.w.Seek(4, 0); err != nil { return err } if err := e.AddBE(uint32(e.WrittenBytes) - 8); err != nil { return fmt.Errorf("%v when writing the total written bytes", err) } if _, err := e.w.Seek(22, 0); err != nil { return err } i...
go
func (e *Encoder) Close() error { // go back and write total size if _, err := e.w.Seek(4, 0); err != nil { return err } if err := e.AddBE(uint32(e.WrittenBytes) - 8); err != nil { return fmt.Errorf("%v when writing the total written bytes", err) } if _, err := e.w.Seek(22, 0); err != nil { return err } i...
[ "func", "(", "e", "*", "Encoder", ")", "Close", "(", ")", "error", "{", "// go back and write total size", "if", "_", ",", "err", ":=", "e", ".", "w", ".", "Seek", "(", "4", ",", "0", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}",...
// Close flushes the content to disk, make sure the headers are up to date // Note that the underlying writter is NOT being closed.
[ "Close", "flushes", "the", "content", "to", "disk", "make", "sure", "the", "headers", "are", "up", "to", "date", "Note", "that", "the", "underlying", "writter", "is", "NOT", "being", "closed", "." ]
c6aebeb78429d88ff11f1468dac519ead57e7196
https://github.com/mattetti/audio/blob/c6aebeb78429d88ff11f1468dac519ead57e7196/aiff/encoder.go#L170-L201
12,315
mattetti/audio
transforms/bit_crush.go
BitCrush
func BitCrush(buf *audio.PCMBuffer, factor float64) { buf.SwitchPrimaryType(audio.Float) stepSize := crusherStepSize * factor for i := 0; i < len(buf.Floats); i++ { frac, exp := math.Frexp(buf.Floats[i]) frac = signum(frac) * math.Floor(math.Abs(frac)/stepSize+0.5) * stepSize buf.Floats[i] = math.Ldexp(frac, e...
go
func BitCrush(buf *audio.PCMBuffer, factor float64) { buf.SwitchPrimaryType(audio.Float) stepSize := crusherStepSize * factor for i := 0; i < len(buf.Floats); i++ { frac, exp := math.Frexp(buf.Floats[i]) frac = signum(frac) * math.Floor(math.Abs(frac)/stepSize+0.5) * stepSize buf.Floats[i] = math.Ldexp(frac, e...
[ "func", "BitCrush", "(", "buf", "*", "audio", ".", "PCMBuffer", ",", "factor", "float64", ")", "{", "buf", ".", "SwitchPrimaryType", "(", "audio", ".", "Float", ")", "\n", "stepSize", ":=", "crusherStepSize", "*", "factor", "\n", "for", "i", ":=", "0", ...
// BitCrush reduces the resolution of the sample to the target bit depth // Note that bit crusher effects are usually made of this feature + a decimator
[ "BitCrush", "reduces", "the", "resolution", "of", "the", "sample", "to", "the", "target", "bit", "depth", "Note", "that", "bit", "crusher", "effects", "are", "usually", "made", "of", "this", "feature", "+", "a", "decimator" ]
c6aebeb78429d88ff11f1468dac519ead57e7196
https://github.com/mattetti/audio/blob/c6aebeb78429d88ff11f1468dac519ead57e7196/transforms/bit_crush.go#L17-L25
12,316
mattetti/audio
mp3/frame_header.go
IsValid
func (h FrameHeader) IsValid() bool { if len(h) < 4 { return false } return h[0] == 0xff && h[1]&0xE0 == 0xE0 && h.Version() <= MPEG1 && h.Layer() <= Layer1 }
go
func (h FrameHeader) IsValid() bool { if len(h) < 4 { return false } return h[0] == 0xff && h[1]&0xE0 == 0xE0 && h.Version() <= MPEG1 && h.Layer() <= Layer1 }
[ "func", "(", "h", "FrameHeader", ")", "IsValid", "(", ")", "bool", "{", "if", "len", "(", "h", ")", "<", "4", "{", "return", "false", "\n", "}", "\n", "return", "h", "[", "0", "]", "==", "0xff", "&&", "h", "[", "1", "]", "&", "0xE0", "==", ...
// IsValid tests the basic validity of the frame header by checking the sync word
[ "IsValid", "tests", "the", "basic", "validity", "of", "the", "frame", "header", "by", "checking", "the", "sync", "word" ]
c6aebeb78429d88ff11f1468dac519ead57e7196
https://github.com/mattetti/audio/blob/c6aebeb78429d88ff11f1468dac519ead57e7196/mp3/frame_header.go#L11-L16
12,317
mattetti/audio
mp3/frame_header.go
BitRate
func (h FrameHeader) BitRate() FrameBitRate { if len(h) < 4 { return 0 } bitrateIdx := (h[2] >> 4) & 0x0F if bitrateIdx == 0x0F { return ErrInvalidBitrate } br := bitrates[h.Version()][h.Layer()][bitrateIdx] * 1000 if br == 0 { return ErrInvalidBitrate } return FrameBitRate(br) }
go
func (h FrameHeader) BitRate() FrameBitRate { if len(h) < 4 { return 0 } bitrateIdx := (h[2] >> 4) & 0x0F if bitrateIdx == 0x0F { return ErrInvalidBitrate } br := bitrates[h.Version()][h.Layer()][bitrateIdx] * 1000 if br == 0 { return ErrInvalidBitrate } return FrameBitRate(br) }
[ "func", "(", "h", "FrameHeader", ")", "BitRate", "(", ")", "FrameBitRate", "{", "if", "len", "(", "h", ")", "<", "4", "{", "return", "0", "\n", "}", "\n", "bitrateIdx", ":=", "(", "h", "[", "2", "]", ">>", "4", ")", "&", "0x0F", "\n", "if", "...
// BitRate returns the calculated bit rate from the header
[ "BitRate", "returns", "the", "calculated", "bit", "rate", "from", "the", "header" ]
c6aebeb78429d88ff11f1468dac519ead57e7196
https://github.com/mattetti/audio/blob/c6aebeb78429d88ff11f1468dac519ead57e7196/mp3/frame_header.go#L43-L56
12,318
mattetti/audio
mp3/frame_header.go
SampleRate
func (h FrameHeader) SampleRate() FrameSampleRate { if len(h) < 4 { return 0 } sri := (h[2] >> 2) & 0x03 if sri == 0x03 { return ErrInvalidSampleRate } return FrameSampleRate(sampleRates[h.Version()][sri]) }
go
func (h FrameHeader) SampleRate() FrameSampleRate { if len(h) < 4 { return 0 } sri := (h[2] >> 2) & 0x03 if sri == 0x03 { return ErrInvalidSampleRate } return FrameSampleRate(sampleRates[h.Version()][sri]) }
[ "func", "(", "h", "FrameHeader", ")", "SampleRate", "(", ")", "FrameSampleRate", "{", "if", "len", "(", "h", ")", "<", "4", "{", "return", "0", "\n", "}", "\n", "sri", ":=", "(", "h", "[", "2", "]", ">>", "2", ")", "&", "0x03", "\n", "if", "s...
// SampleRate returns the samplerate from the header
[ "SampleRate", "returns", "the", "samplerate", "from", "the", "header" ]
c6aebeb78429d88ff11f1468dac519ead57e7196
https://github.com/mattetti/audio/blob/c6aebeb78429d88ff11f1468dac519ead57e7196/mp3/frame_header.go#L59-L68
12,319
mattetti/audio
mp3/frame_header.go
String
func (h FrameHeader) String() string { str := "" str += fmt.Sprintf(" Layer: %v\n", h.Layer()) str += fmt.Sprintf(" Version: %v\n", h.Version()) str += fmt.Sprintf(" Protection: %v\n", h.Protection()) str += fmt.Sprintf(" BitRate: %v\n", h.BitRate()) str += fmt.Sprintf(" SampleRate: %v\n", h.SampleRate()) str +=...
go
func (h FrameHeader) String() string { str := "" str += fmt.Sprintf(" Layer: %v\n", h.Layer()) str += fmt.Sprintf(" Version: %v\n", h.Version()) str += fmt.Sprintf(" Protection: %v\n", h.Protection()) str += fmt.Sprintf(" BitRate: %v\n", h.BitRate()) str += fmt.Sprintf(" SampleRate: %v\n", h.SampleRate()) str +=...
[ "func", "(", "h", "FrameHeader", ")", "String", "(", ")", "string", "{", "str", ":=", "\"", "\"", "\n", "str", "+=", "fmt", ".", "Sprintf", "(", "\"", "\\n", "\"", ",", "h", ".", "Layer", "(", ")", ")", "\n", "str", "+=", "fmt", ".", "Sprintf",...
// String dumps the frame header as a string for display purposes
[ "String", "dumps", "the", "frame", "header", "as", "a", "string", "for", "display", "purposes" ]
c6aebeb78429d88ff11f1468dac519ead57e7196
https://github.com/mattetti/audio/blob/c6aebeb78429d88ff11f1468dac519ead57e7196/mp3/frame_header.go#L120-L136
12,320
mattetti/audio
mp3/frame_header.go
Samples
func (h FrameHeader) Samples() int { if len(h) < 4 { return 0 } ftype, ok := samplesPerFrame[h.Version()] if !ok { return 0 } return ftype[h.Layer()] }
go
func (h FrameHeader) Samples() int { if len(h) < 4 { return 0 } ftype, ok := samplesPerFrame[h.Version()] if !ok { return 0 } return ftype[h.Layer()] }
[ "func", "(", "h", "FrameHeader", ")", "Samples", "(", ")", "int", "{", "if", "len", "(", "h", ")", "<", "4", "{", "return", "0", "\n", "}", "\n", "ftype", ",", "ok", ":=", "samplesPerFrame", "[", "h", ".", "Version", "(", ")", "]", "\n", "if", ...
// Samples is the number of samples contained in this frame
[ "Samples", "is", "the", "number", "of", "samples", "contained", "in", "this", "frame" ]
c6aebeb78429d88ff11f1468dac519ead57e7196
https://github.com/mattetti/audio/blob/c6aebeb78429d88ff11f1468dac519ead57e7196/mp3/frame_header.go#L139-L148
12,321
templexxx/xor
nosimd.go
bytesNoSIMD
func bytesNoSIMD(dst, a, b []byte, size int) { if supportsUnaligned { fastXORBytes(dst, a, b, size) } else { // TODO(hanwen): if (dst, a, b) have common alignment // we could still try fastXORBytes. It is not clear // how often this happens, and it's only worth it if // the block encryption itself is hardwa...
go
func bytesNoSIMD(dst, a, b []byte, size int) { if supportsUnaligned { fastXORBytes(dst, a, b, size) } else { // TODO(hanwen): if (dst, a, b) have common alignment // we could still try fastXORBytes. It is not clear // how often this happens, and it's only worth it if // the block encryption itself is hardwa...
[ "func", "bytesNoSIMD", "(", "dst", ",", "a", ",", "b", "[", "]", "byte", ",", "size", "int", ")", "{", "if", "supportsUnaligned", "{", "fastXORBytes", "(", "dst", ",", "a", ",", "b", ",", "size", ")", "\n", "}", "else", "{", "// TODO(hanwen): if (dst...
// xor the bytes in a and b. The destination is assumed to have enough space.
[ "xor", "the", "bytes", "in", "a", "and", "b", ".", "The", "destination", "is", "assumed", "to", "have", "enough", "space", "." ]
4e92f724b73b7aaf61869bb1ae5817822e738430
https://github.com/templexxx/xor/blob/4e92f724b73b7aaf61869bb1ae5817822e738430/nosimd.go#L16-L27
12,322
templexxx/xor
nosimd.go
partNoSIMD
func partNoSIMD(start, end int, dst []byte, src [][]byte) { bytesNoSIMD(dst[start:end], src[0][start:end], src[1][start:end], end-start) for i := 2; i < len(src); i++ { bytesNoSIMD(dst[start:end], dst[start:end], src[i][start:end], end-start) } }
go
func partNoSIMD(start, end int, dst []byte, src [][]byte) { bytesNoSIMD(dst[start:end], src[0][start:end], src[1][start:end], end-start) for i := 2; i < len(src); i++ { bytesNoSIMD(dst[start:end], dst[start:end], src[i][start:end], end-start) } }
[ "func", "partNoSIMD", "(", "start", ",", "end", "int", ",", "dst", "[", "]", "byte", ",", "src", "[", "]", "[", "]", "byte", ")", "{", "bytesNoSIMD", "(", "dst", "[", "start", ":", "end", "]", ",", "src", "[", "0", "]", "[", "start", ":", "en...
// split vect will improve performance with big data by reducing cache pollution
[ "split", "vect", "will", "improve", "performance", "with", "big", "data", "by", "reducing", "cache", "pollution" ]
4e92f724b73b7aaf61869bb1ae5817822e738430
https://github.com/templexxx/xor/blob/4e92f724b73b7aaf61869bb1ae5817822e738430/nosimd.go#L49-L54
12,323
smotes/purse
purse.go
New
func New(dir string) (*MemoryPurse, error) { dir = filepath.Clean(dir) + string(os.PathSeparator) f, err := os.Open(dir) if err != nil { return nil, err } defer f.Close() fis, err := f.Readdir(-1) if err != nil { return nil, err } p := &MemoryPurse{files: make(map[string]string, 0)} for _, fi := range ...
go
func New(dir string) (*MemoryPurse, error) { dir = filepath.Clean(dir) + string(os.PathSeparator) f, err := os.Open(dir) if err != nil { return nil, err } defer f.Close() fis, err := f.Readdir(-1) if err != nil { return nil, err } p := &MemoryPurse{files: make(map[string]string, 0)} for _, fi := range ...
[ "func", "New", "(", "dir", "string", ")", "(", "*", "MemoryPurse", ",", "error", ")", "{", "dir", "=", "filepath", ".", "Clean", "(", "dir", ")", "+", "string", "(", "os", ".", "PathSeparator", ")", "\n", "f", ",", "err", ":=", "os", ".", "Open",...
// New loads SQL files' contents in the specified directory dir into memory. // A file's contents can be accessed with the Get method. // // New returns an error if the directory does not exist or is not a directory.
[ "New", "loads", "SQL", "files", "contents", "in", "the", "specified", "directory", "dir", "into", "memory", ".", "A", "file", "s", "contents", "can", "be", "accessed", "with", "the", "Get", "method", ".", "New", "returns", "an", "error", "if", "the", "di...
9ce9ed34191cbabb61a4dd1d5623e69a3b95cdda
https://github.com/smotes/purse/blob/9ce9ed34191cbabb61a4dd1d5623e69a3b95cdda/purse.go#L36-L72
12,324
smotes/purse
purse.go
Get
func (p *MemoryPurse) Get(filename string) (v string, ok bool) { p.mu.RLock() v, ok = p.files[filename] p.mu.RUnlock() return }
go
func (p *MemoryPurse) Get(filename string) (v string, ok bool) { p.mu.RLock() v, ok = p.files[filename] p.mu.RUnlock() return }
[ "func", "(", "p", "*", "MemoryPurse", ")", "Get", "(", "filename", "string", ")", "(", "v", "string", ",", "ok", "bool", ")", "{", "p", ".", "mu", ".", "RLock", "(", ")", "\n", "v", ",", "ok", "=", "p", ".", "files", "[", "filename", "]", "\n...
// Get returns a SQL file's contents as a string. // If the file does not exist or does exists but had a read error, // then v == "" and ok == false.
[ "Get", "returns", "a", "SQL", "file", "s", "contents", "as", "a", "string", ".", "If", "the", "file", "does", "not", "exist", "or", "does", "exists", "but", "had", "a", "read", "error", "then", "v", "==", "and", "ok", "==", "false", "." ]
9ce9ed34191cbabb61a4dd1d5623e69a3b95cdda
https://github.com/smotes/purse/blob/9ce9ed34191cbabb61a4dd1d5623e69a3b95cdda/purse.go#L77-L82
12,325
smotes/purse
purse.go
Files
func (p *MemoryPurse) Files() []string { fs := make([]string, len(p.files)) i := 0 for k, _ := range p.files { fs[i] = k i++ } return fs }
go
func (p *MemoryPurse) Files() []string { fs := make([]string, len(p.files)) i := 0 for k, _ := range p.files { fs[i] = k i++ } return fs }
[ "func", "(", "p", "*", "MemoryPurse", ")", "Files", "(", ")", "[", "]", "string", "{", "fs", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "p", ".", "files", ")", ")", "\n", "i", ":=", "0", "\n", "for", "k", ",", "_", ":=", "range...
// Files returns a slice of filenames for all loaded SQL files.
[ "Files", "returns", "a", "slice", "of", "filenames", "for", "all", "loaded", "SQL", "files", "." ]
9ce9ed34191cbabb61a4dd1d5623e69a3b95cdda
https://github.com/smotes/purse/blob/9ce9ed34191cbabb61a4dd1d5623e69a3b95cdda/purse.go#L85-L93
12,326
smotes/purse
purse.go
addToPurse
func addToPurse(purse *MemoryPurse, name, path string) error { f, err := os.Open(path) if err != nil { return err } defer f.Close() b, err := ioutil.ReadAll(f) if err != nil { return err } purse.files[name] = string(b) return nil }
go
func addToPurse(purse *MemoryPurse, name, path string) error { f, err := os.Open(path) if err != nil { return err } defer f.Close() b, err := ioutil.ReadAll(f) if err != nil { return err } purse.files[name] = string(b) return nil }
[ "func", "addToPurse", "(", "purse", "*", "MemoryPurse", ",", "name", ",", "path", "string", ")", "error", "{", "f", ",", "err", ":=", "os", ".", "Open", "(", "path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "def...
// addToPurse adds a file to the specified purse with the given name.
[ "addToPurse", "adds", "a", "file", "to", "the", "specified", "purse", "with", "the", "given", "name", "." ]
9ce9ed34191cbabb61a4dd1d5623e69a3b95cdda
https://github.com/smotes/purse/blob/9ce9ed34191cbabb61a4dd1d5623e69a3b95cdda/purse.go#L96-L108
12,327
myesui/uuid
saver.go
String
func (o Store) String() string { return fmt.Sprintf("Timestamp[%s]-Sequence[%d]-Node[%x]", o.Timestamp, o.Sequence, o.Node) }
go
func (o Store) String() string { return fmt.Sprintf("Timestamp[%s]-Sequence[%d]-Node[%x]", o.Timestamp, o.Sequence, o.Node) }
[ "func", "(", "o", "Store", ")", "String", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "o", ".", "Timestamp", ",", "o", ".", "Sequence", ",", "o", ".", "Node", ")", "\n", "}" ]
// String returns a string representation of the Store.
[ "String", "returns", "a", "string", "representation", "of", "the", "Store", "." ]
835a10bbd6bce40820349a68b1368a62c3c5617c
https://github.com/myesui/uuid/blob/835a10bbd6bce40820349a68b1368a62c3c5617c/saver.go#L24-L26
12,328
myesui/uuid
types.go
MarshalText
func (o UUID) MarshalText() ([]byte, error) { f := FormatCanonical if defaultFormats[printFormat] { f = printFormat } return []byte(formatUuid(o.Bytes(), f)), nil }
go
func (o UUID) MarshalText() ([]byte, error) { f := FormatCanonical if defaultFormats[printFormat] { f = printFormat } return []byte(formatUuid(o.Bytes(), f)), nil }
[ "func", "(", "o", "UUID", ")", "MarshalText", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "f", ":=", "FormatCanonical", "\n", "if", "defaultFormats", "[", "printFormat", "]", "{", "f", "=", "printFormat", "\n", "}", "\n", "return", "[", ...
// MarshalText implements the encoding.TextMarshaler interface. It will marshal // text into one of the known formats, if you have changed to a custom Format // the text be output in canonical format.
[ "MarshalText", "implements", "the", "encoding", ".", "TextMarshaler", "interface", ".", "It", "will", "marshal", "text", "into", "one", "of", "the", "known", "formats", "if", "you", "have", "changed", "to", "a", "custom", "Format", "the", "text", "be", "outp...
835a10bbd6bce40820349a68b1368a62c3c5617c
https://github.com/myesui/uuid/blob/835a10bbd6bce40820349a68b1368a62c3c5617c/types.go#L83-L89
12,329
myesui/uuid
types.go
UnmarshalText
func (o *UUID) UnmarshalText(uuid []byte) error { id, err := parse(string(uuid)) if err == nil { o.UnmarshalBinary(id) } return err }
go
func (o *UUID) UnmarshalText(uuid []byte) error { id, err := parse(string(uuid)) if err == nil { o.UnmarshalBinary(id) } return err }
[ "func", "(", "o", "*", "UUID", ")", "UnmarshalText", "(", "uuid", "[", "]", "byte", ")", "error", "{", "id", ",", "err", ":=", "parse", "(", "string", "(", "uuid", ")", ")", "\n", "if", "err", "==", "nil", "{", "o", ".", "UnmarshalBinary", "(", ...
// UnmarshalText implements the encoding.TextUnmarshaler interface. It will // support any text that MarshalText can produce.
[ "UnmarshalText", "implements", "the", "encoding", ".", "TextUnmarshaler", "interface", ".", "It", "will", "support", "any", "text", "that", "MarshalText", "can", "produce", "." ]
835a10bbd6bce40820349a68b1368a62c3c5617c
https://github.com/myesui/uuid/blob/835a10bbd6bce40820349a68b1368a62c3c5617c/types.go#L93-L99
12,330
myesui/uuid
types.go
Value
func (o UUID) Value() (value driver.Value, err error) { if IsNil(o) { value, err = nil, nil return } value, err = o.MarshalText() return }
go
func (o UUID) Value() (value driver.Value, err error) { if IsNil(o) { value, err = nil, nil return } value, err = o.MarshalText() return }
[ "func", "(", "o", "UUID", ")", "Value", "(", ")", "(", "value", "driver", ".", "Value", ",", "err", "error", ")", "{", "if", "IsNil", "(", "o", ")", "{", "value", ",", "err", "=", "nil", ",", "nil", "\n", "return", "\n", "}", "\n", "value", "...
// Value implements the driver.Valuer interface
[ "Value", "implements", "the", "driver", ".", "Valuer", "interface" ]
835a10bbd6bce40820349a68b1368a62c3c5617c
https://github.com/myesui/uuid/blob/835a10bbd6bce40820349a68b1368a62c3c5617c/types.go#L102-L109
12,331
myesui/uuid
types.go
Scan
func (o *UUID) Scan(src interface{}) error { if src == nil { return nil } if src == "" { return nil } switch src := src.(type) { case string: return o.UnmarshalText([]byte(src)) case []byte: if len(src) == length { return o.UnmarshalBinary(src) } else { return o.UnmarshalText(src) } default...
go
func (o *UUID) Scan(src interface{}) error { if src == nil { return nil } if src == "" { return nil } switch src := src.(type) { case string: return o.UnmarshalText([]byte(src)) case []byte: if len(src) == length { return o.UnmarshalBinary(src) } else { return o.UnmarshalText(src) } default...
[ "func", "(", "o", "*", "UUID", ")", "Scan", "(", "src", "interface", "{", "}", ")", "error", "{", "if", "src", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "if", "src", "==", "\"", "\"", "{", "return", "nil", "\n", "}", "\n", "switch", ...
// Scan implements the sql.Scanner interface
[ "Scan", "implements", "the", "sql", ".", "Scanner", "interface" ]
835a10bbd6bce40820349a68b1368a62c3c5617c
https://github.com/myesui/uuid/blob/835a10bbd6bce40820349a68b1368a62c3c5617c/types.go#L112-L134
12,332
myesui/uuid
types.go
UUID
func (o Immutable) UUID() UUID { id := UUID{} id.unmarshal(o.Bytes()) return id }
go
func (o Immutable) UUID() UUID { id := UUID{} id.unmarshal(o.Bytes()) return id }
[ "func", "(", "o", "Immutable", ")", "UUID", "(", ")", "UUID", "{", "id", ":=", "UUID", "{", "}", "\n", "id", ".", "unmarshal", "(", "o", ".", "Bytes", "(", ")", ")", "\n", "return", "id", "\n", "}" ]
// UUID converts this implementation to the default type uuid.UUID
[ "UUID", "converts", "this", "implementation", "to", "the", "default", "type", "uuid", ".", "UUID" ]
835a10bbd6bce40820349a68b1368a62c3c5617c
https://github.com/myesui/uuid/blob/835a10bbd6bce40820349a68b1368a62c3c5617c/types.go#L171-L175
12,333
myesui/uuid
savers/filesystem.go
Save
func (o *FileSystemSaver) Save(store uuid.Store) { if store.Timestamp >= o.Timestamp { err := o.openAndDo(o.encode, &store) if err == nil { if o.Report { o.Println("file system saver saved", store) } } o.Timestamp = store.Add(o.Duration) } }
go
func (o *FileSystemSaver) Save(store uuid.Store) { if store.Timestamp >= o.Timestamp { err := o.openAndDo(o.encode, &store) if err == nil { if o.Report { o.Println("file system saver saved", store) } } o.Timestamp = store.Add(o.Duration) } }
[ "func", "(", "o", "*", "FileSystemSaver", ")", "Save", "(", "store", "uuid", ".", "Store", ")", "{", "if", "store", ".", "Timestamp", ">=", "o", ".", "Timestamp", "{", "err", ":=", "o", ".", "openAndDo", "(", "o", ".", "encode", ",", "&", "store", ...
// Save saves the given store to the filesystem.
[ "Save", "saves", "the", "given", "store", "to", "the", "filesystem", "." ]
835a10bbd6bce40820349a68b1368a62c3c5617c
https://github.com/myesui/uuid/blob/835a10bbd6bce40820349a68b1368a62c3c5617c/savers/filesystem.go#L49-L60
12,334
myesui/uuid
savers/filesystem.go
Read
func (o *FileSystemSaver) Read() (store uuid.Store, err error) { store = uuid.Store{} _, err = os.Stat(o.Path); if err != nil { if os.IsNotExist(err) { dir, file := path.Split(o.Path) if dir == "" || dir == "/" { dir = os.TempDir() } o.Path = path.Join(dir, file) err = os.MkdirAll(dir, os.ModeD...
go
func (o *FileSystemSaver) Read() (store uuid.Store, err error) { store = uuid.Store{} _, err = os.Stat(o.Path); if err != nil { if os.IsNotExist(err) { dir, file := path.Split(o.Path) if dir == "" || dir == "/" { dir = os.TempDir() } o.Path = path.Join(dir, file) err = os.MkdirAll(dir, os.ModeD...
[ "func", "(", "o", "*", "FileSystemSaver", ")", "Read", "(", ")", "(", "store", "uuid", ".", "Store", ",", "err", "error", ")", "{", "store", "=", "uuid", ".", "Store", "{", "}", "\n", "_", ",", "err", "=", "os", ".", "Stat", "(", "o", ".", "P...
// Read reads and loads the Store from the filesystem.
[ "Read", "reads", "and", "loads", "the", "Store", "from", "the", "filesystem", "." ]
835a10bbd6bce40820349a68b1368a62c3c5617c
https://github.com/myesui/uuid/blob/835a10bbd6bce40820349a68b1368a62c3c5617c/savers/filesystem.go#L63-L93
12,335
myesui/uuid
generator.go
RegisterGenerator
func RegisterGenerator(config *GeneratorConfig) (err error) { notOnce := true once.Do(func() { generator, err = NewGenerator(config) notOnce = false return }) if notOnce { panic("uuid: Register* methods cannot be called more than once.") } return }
go
func RegisterGenerator(config *GeneratorConfig) (err error) { notOnce := true once.Do(func() { generator, err = NewGenerator(config) notOnce = false return }) if notOnce { panic("uuid: Register* methods cannot be called more than once.") } return }
[ "func", "RegisterGenerator", "(", "config", "*", "GeneratorConfig", ")", "(", "err", "error", ")", "{", "notOnce", ":=", "true", "\n", "once", ".", "Do", "(", "func", "(", ")", "{", "generator", ",", "err", "=", "NewGenerator", "(", "config", ")", "\n"...
// RegisterGenerator will set the package generator with the given configuration // Like uuid.Init this can only be called once. Any subsequent calls will have no // effect. If you call this you do not need to call uuid.Init.
[ "RegisterGenerator", "will", "set", "the", "package", "generator", "with", "the", "given", "configuration", "Like", "uuid", ".", "Init", "this", "can", "only", "be", "called", "once", ".", "Any", "subsequent", "calls", "will", "have", "no", "effect", ".", "I...
835a10bbd6bce40820349a68b1368a62c3c5617c
https://github.com/myesui/uuid/blob/835a10bbd6bce40820349a68b1368a62c3c5617c/generator.go#L191-L202
12,336
myesui/uuid
generator.go
NewV1
func (o *Generator) NewV1() UUID { o.read() id := UUID{} makeUuid(&id, uint32(o.Timestamp), uint16(o.Timestamp>>32), uint16(o.Timestamp>>48), uint16(o.Sequence), o.Node) id.setRFC4122Version(VersionOne) return id }
go
func (o *Generator) NewV1() UUID { o.read() id := UUID{} makeUuid(&id, uint32(o.Timestamp), uint16(o.Timestamp>>32), uint16(o.Timestamp>>48), uint16(o.Sequence), o.Node) id.setRFC4122Version(VersionOne) return id }
[ "func", "(", "o", "*", "Generator", ")", "NewV1", "(", ")", "UUID", "{", "o", ".", "read", "(", ")", "\n", "id", ":=", "UUID", "{", "}", "\n\n", "makeUuid", "(", "&", "id", ",", "uint32", "(", "o", ".", "Timestamp", ")", ",", "uint16", "(", "...
// NewV1 generates a new RFC4122 version 1 UUID based on a 60 bit timestamp and // node id.
[ "NewV1", "generates", "a", "new", "RFC4122", "version", "1", "UUID", "based", "on", "a", "60", "bit", "timestamp", "and", "node", "id", "." ]
835a10bbd6bce40820349a68b1368a62c3c5617c
https://github.com/myesui/uuid/blob/835a10bbd6bce40820349a68b1368a62c3c5617c/generator.go#L329-L342
12,337
myesui/uuid
generator.go
ReadV1
func (o *Generator) ReadV1(ids []UUID) { for i := range ids { ids[i] = o.NewV1() } }
go
func (o *Generator) ReadV1(ids []UUID) { for i := range ids { ids[i] = o.NewV1() } }
[ "func", "(", "o", "*", "Generator", ")", "ReadV1", "(", "ids", "[", "]", "UUID", ")", "{", "for", "i", ":=", "range", "ids", "{", "ids", "[", "i", "]", "=", "o", ".", "NewV1", "(", ")", "\n", "}", "\n", "}" ]
// ReadV1 will read a slice of UUIDs. Be careful with the set amount.
[ "ReadV1", "will", "read", "a", "slice", "of", "UUIDs", ".", "Be", "careful", "with", "the", "set", "amount", "." ]
835a10bbd6bce40820349a68b1368a62c3c5617c
https://github.com/myesui/uuid/blob/835a10bbd6bce40820349a68b1368a62c3c5617c/generator.go#L345-L349
12,338
myesui/uuid
generator.go
BulkV1
func (o *Generator) BulkV1(amount int) []UUID { ids := make([]UUID, amount) o.ReadV1(ids) return ids }
go
func (o *Generator) BulkV1(amount int) []UUID { ids := make([]UUID, amount) o.ReadV1(ids) return ids }
[ "func", "(", "o", "*", "Generator", ")", "BulkV1", "(", "amount", "int", ")", "[", "]", "UUID", "{", "ids", ":=", "make", "(", "[", "]", "UUID", ",", "amount", ")", "\n", "o", ".", "ReadV1", "(", "ids", ")", "\n", "return", "ids", "\n", "}" ]
// BulkV1 will return a slice of V1 UUIDs. Be careful with the set amount.
[ "BulkV1", "will", "return", "a", "slice", "of", "V1", "UUIDs", ".", "Be", "careful", "with", "the", "set", "amount", "." ]
835a10bbd6bce40820349a68b1368a62c3c5617c
https://github.com/myesui/uuid/blob/835a10bbd6bce40820349a68b1368a62c3c5617c/generator.go#L352-L356
12,339
myesui/uuid
generator.go
NewV2
func (o *Generator) NewV2(idType SystemId) UUID { o.read() id := UUID{} var osId uint32 switch idType { case SystemIdUser: osId = uint32(os.Getuid()) case SystemIdGroup: osId = uint32(os.Getgid()) case SystemIdEffectiveUser: osId = uint32(os.Geteuid()) case SystemIdEffectiveGroup: osId = uint32(os.Ge...
go
func (o *Generator) NewV2(idType SystemId) UUID { o.read() id := UUID{} var osId uint32 switch idType { case SystemIdUser: osId = uint32(os.Getuid()) case SystemIdGroup: osId = uint32(os.Getgid()) case SystemIdEffectiveUser: osId = uint32(os.Geteuid()) case SystemIdEffectiveGroup: osId = uint32(os.Ge...
[ "func", "(", "o", "*", "Generator", ")", "NewV2", "(", "idType", "SystemId", ")", "UUID", "{", "o", ".", "read", "(", ")", "\n\n", "id", ":=", "UUID", "{", "}", "\n\n", "var", "osId", "uint32", "\n\n", "switch", "idType", "{", "case", "SystemIdUser",...
// NewV2 generates a new DCE version 2 UUID based on a 60 bit timestamp, node id // and the id of the given Id type.
[ "NewV2", "generates", "a", "new", "DCE", "version", "2", "UUID", "based", "on", "a", "60", "bit", "timestamp", "node", "id", "and", "the", "id", "of", "the", "given", "Id", "type", "." ]
835a10bbd6bce40820349a68b1368a62c3c5617c
https://github.com/myesui/uuid/blob/835a10bbd6bce40820349a68b1368a62c3c5617c/generator.go#L360-L392
12,340
myesui/uuid
generator.go
NewV3
func (o *Generator) NewV3(namespace Implementation, names ...interface{}) UUID { id := UUID{} id.unmarshal(digest(md5.New(), namespace.Bytes(), names...)) id.setRFC4122Version(VersionThree) return id }
go
func (o *Generator) NewV3(namespace Implementation, names ...interface{}) UUID { id := UUID{} id.unmarshal(digest(md5.New(), namespace.Bytes(), names...)) id.setRFC4122Version(VersionThree) return id }
[ "func", "(", "o", "*", "Generator", ")", "NewV3", "(", "namespace", "Implementation", ",", "names", "...", "interface", "{", "}", ")", "UUID", "{", "id", ":=", "UUID", "{", "}", "\n", "id", ".", "unmarshal", "(", "digest", "(", "md5", ".", "New", "...
// NewV3 generates a new RFC4122 version 3 UUID based on the MD5 hash of a // namespace UUID namespace Implementation UUID and one or more unique names.
[ "NewV3", "generates", "a", "new", "RFC4122", "version", "3", "UUID", "based", "on", "the", "MD5", "hash", "of", "a", "namespace", "UUID", "namespace", "Implementation", "UUID", "and", "one", "or", "more", "unique", "names", "." ]
835a10bbd6bce40820349a68b1368a62c3c5617c
https://github.com/myesui/uuid/blob/835a10bbd6bce40820349a68b1368a62c3c5617c/generator.go#L396-L401
12,341
myesui/uuid
generator.go
NewV5
func (o *Generator) NewV5(namespace Implementation, names ...interface{}) UUID { id := UUID{} id.unmarshal(digest(sha1.New(), namespace.Bytes(), names...)) id.setRFC4122Version(VersionFive) return id }
go
func (o *Generator) NewV5(namespace Implementation, names ...interface{}) UUID { id := UUID{} id.unmarshal(digest(sha1.New(), namespace.Bytes(), names...)) id.setRFC4122Version(VersionFive) return id }
[ "func", "(", "o", "*", "Generator", ")", "NewV5", "(", "namespace", "Implementation", ",", "names", "...", "interface", "{", "}", ")", "UUID", "{", "id", ":=", "UUID", "{", "}", "\n", "id", ".", "unmarshal", "(", "digest", "(", "sha1", ".", "New", ...
// NewV5 generates an RFC4122 version 5 UUID based on the SHA-1 hash of a // namespace Implementation UUID and one or more unique names.
[ "NewV5", "generates", "an", "RFC4122", "version", "5", "UUID", "based", "on", "the", "SHA", "-", "1", "hash", "of", "a", "namespace", "Implementation", "UUID", "and", "one", "or", "more", "unique", "names", "." ]
835a10bbd6bce40820349a68b1368a62c3c5617c
https://github.com/myesui/uuid/blob/835a10bbd6bce40820349a68b1368a62c3c5617c/generator.go#L469-L474
12,342
myesui/uuid
timestamp.go
Time
func (o Timestamp) Time() time.Time { return time.Unix(0, int64((o-gregorianToUNIXOffset)*100)).UTC() }
go
func (o Timestamp) Time() time.Time { return time.Unix(0, int64((o-gregorianToUNIXOffset)*100)).UTC() }
[ "func", "(", "o", "Timestamp", ")", "Time", "(", ")", "time", ".", "Time", "{", "return", "time", ".", "Unix", "(", "0", ",", "int64", "(", "(", "o", "-", "gregorianToUNIXOffset", ")", "*", "100", ")", ")", ".", "UTC", "(", ")", "\n", "}" ]
// Time converts UUID Timestamp to UTC time.Time // Note some higher clock resolutions will lose accuracy if above 100 ns ticks
[ "Time", "converts", "UUID", "Timestamp", "to", "UTC", "time", ".", "Time", "Note", "some", "higher", "clock", "resolutions", "will", "lose", "accuracy", "if", "above", "100", "ns", "ticks" ]
835a10bbd6bce40820349a68b1368a62c3c5617c
https://github.com/myesui/uuid/blob/835a10bbd6bce40820349a68b1368a62c3c5617c/timestamp.go#L46-L48
12,343
myesui/uuid
timestamp.go
Add
func (o Timestamp) Add(duration time.Duration) Timestamp { return o + Timestamp(duration/100) }
go
func (o Timestamp) Add(duration time.Duration) Timestamp { return o + Timestamp(duration/100) }
[ "func", "(", "o", "Timestamp", ")", "Add", "(", "duration", "time", ".", "Duration", ")", "Timestamp", "{", "return", "o", "+", "Timestamp", "(", "duration", "/", "100", ")", "\n", "}" ]
// Add returns the timestamp as modified by the duration
[ "Add", "returns", "the", "timestamp", "as", "modified", "by", "the", "duration" ]
835a10bbd6bce40820349a68b1368a62c3c5617c
https://github.com/myesui/uuid/blob/835a10bbd6bce40820349a68b1368a62c3c5617c/timestamp.go#L51-L53
12,344
myesui/uuid
timestamp.go
Sub
func (o Timestamp) Sub(duration time.Duration) Timestamp { return o - Timestamp(duration/100) }
go
func (o Timestamp) Sub(duration time.Duration) Timestamp { return o - Timestamp(duration/100) }
[ "func", "(", "o", "Timestamp", ")", "Sub", "(", "duration", "time", ".", "Duration", ")", "Timestamp", "{", "return", "o", "-", "Timestamp", "(", "duration", "/", "100", ")", "\n", "}" ]
// Sub returns the timestamp as modified by the duration
[ "Sub", "returns", "the", "timestamp", "as", "modified", "by", "the", "duration" ]
835a10bbd6bce40820349a68b1368a62c3c5617c
https://github.com/myesui/uuid/blob/835a10bbd6bce40820349a68b1368a62c3c5617c/timestamp.go#L56-L58
12,345
myesui/uuid
uuid.go
New
func New(data []byte) UUID { o := UUID{} o.unmarshal(data) return o }
go
func New(data []byte) UUID { o := UUID{} o.unmarshal(data) return o }
[ "func", "New", "(", "data", "[", "]", "byte", ")", "UUID", "{", "o", ":=", "UUID", "{", "}", "\n", "o", ".", "unmarshal", "(", "data", ")", "\n", "return", "o", "\n", "}" ]
// New creates a UUID from a slice of bytes.
[ "New", "creates", "a", "UUID", "from", "a", "slice", "of", "bytes", "." ]
835a10bbd6bce40820349a68b1368a62c3c5617c
https://github.com/myesui/uuid/blob/835a10bbd6bce40820349a68b1368a62c3c5617c/uuid.go#L75-L79
12,346
myesui/uuid
uuid.go
NewHex
func NewHex(uuid string) UUID { o := UUID{} o.unmarshal(fromHex(uuid)) return o }
go
func NewHex(uuid string) UUID { o := UUID{} o.unmarshal(fromHex(uuid)) return o }
[ "func", "NewHex", "(", "uuid", "string", ")", "UUID", "{", "o", ":=", "UUID", "{", "}", "\n", "o", ".", "unmarshal", "(", "fromHex", "(", "uuid", ")", ")", "\n", "return", "o", "\n", "}" ]
// NewHex creates a UUID from a hex string. // Will panic if hex string is invalid use Parse otherwise.
[ "NewHex", "creates", "a", "UUID", "from", "a", "hex", "string", ".", "Will", "panic", "if", "hex", "string", "is", "invalid", "use", "Parse", "otherwise", "." ]
835a10bbd6bce40820349a68b1368a62c3c5617c
https://github.com/myesui/uuid/blob/835a10bbd6bce40820349a68b1368a62c3c5617c/uuid.go#L83-L87
12,347
myesui/uuid
uuid.go
Equal
func Equal(p1, p2 Implementation) bool { return bytes.Equal(p1.Bytes(), p2.Bytes()) }
go
func Equal(p1, p2 Implementation) bool { return bytes.Equal(p1.Bytes(), p2.Bytes()) }
[ "func", "Equal", "(", "p1", ",", "p2", "Implementation", ")", "bool", "{", "return", "bytes", ".", "Equal", "(", "p1", ".", "Bytes", "(", ")", ",", "p2", ".", "Bytes", "(", ")", ")", "\n", "}" ]
// Equal compares whether each Implementation UUID is the same
[ "Equal", "compares", "whether", "each", "Implementation", "UUID", "is", "the", "same" ]
835a10bbd6bce40820349a68b1368a62c3c5617c
https://github.com/myesui/uuid/blob/835a10bbd6bce40820349a68b1368a62c3c5617c/uuid.go#L252-L254
12,348
myesui/uuid
uuid.go
IsNil
func IsNil(uuid Implementation) bool { if uuid == nil { return true } for _, v := range uuid.Bytes() { if v != 0 { return false } } return true }
go
func IsNil(uuid Implementation) bool { if uuid == nil { return true } for _, v := range uuid.Bytes() { if v != 0 { return false } } return true }
[ "func", "IsNil", "(", "uuid", "Implementation", ")", "bool", "{", "if", "uuid", "==", "nil", "{", "return", "true", "\n", "}", "\n", "for", "_", ",", "v", ":=", "range", "uuid", ".", "Bytes", "(", ")", "{", "if", "v", "!=", "0", "{", "return", ...
// IsNil returns true if Implementation UUID is all zeros?
[ "IsNil", "returns", "true", "if", "Implementation", "UUID", "is", "all", "zeros?" ]
835a10bbd6bce40820349a68b1368a62c3c5617c
https://github.com/myesui/uuid/blob/835a10bbd6bce40820349a68b1368a62c3c5617c/uuid.go#L257-L267
12,349
myesui/uuid
version.go
String
func (o Version) String() string { switch o { case VersionOne: return "Version 1: Based on a 60 Bit Timestamp." case VersionTwo: return "Version 2: Based on DCE security domain and 60 bit timestamp." case VersionThree: return "Version 3: Namespace UUID and unique names hashed by MD5." case VersionFour: ret...
go
func (o Version) String() string { switch o { case VersionOne: return "Version 1: Based on a 60 Bit Timestamp." case VersionTwo: return "Version 2: Based on DCE security domain and 60 bit timestamp." case VersionThree: return "Version 3: Namespace UUID and unique names hashed by MD5." case VersionFour: ret...
[ "func", "(", "o", "Version", ")", "String", "(", ")", "string", "{", "switch", "o", "{", "case", "VersionOne", ":", "return", "\"", "\"", "\n", "case", "VersionTwo", ":", "return", "\"", "\"", "\n", "case", "VersionThree", ":", "return", "\"", "\"", ...
// String returns English description of version.
[ "String", "returns", "English", "description", "of", "version", "." ]
835a10bbd6bce40820349a68b1368a62c3c5617c
https://github.com/myesui/uuid/blob/835a10bbd6bce40820349a68b1368a62c3c5617c/version.go#L35-L50
12,350
bluele/mecab-golang
node.go
Next
func (node *Node) Next() error { node.current = node.current.next if node.current == nil { return StopIteration } return nil }
go
func (node *Node) Next() error { node.current = node.current.next if node.current == nil { return StopIteration } return nil }
[ "func", "(", "node", "*", "Node", ")", "Next", "(", ")", "error", "{", "node", ".", "current", "=", "node", ".", "current", ".", "next", "\n", "if", "node", ".", "current", "==", "nil", "{", "return", "StopIteration", "\n", "}", "\n", "return", "ni...
// proceed to the next node. // if current node is last, this method returns StopIteration error.
[ "proceed", "to", "the", "next", "node", ".", "if", "current", "node", "is", "last", "this", "method", "returns", "StopIteration", "error", "." ]
c8cfe04e87f99006004f2bb27f101a96b2f7f28b
https://github.com/bluele/mecab-golang/blob/c8cfe04e87f99006004f2bb27f101a96b2f7f28b/node.go#L24-L30
12,351
bluele/mecab-golang
node.go
StartPos
func (node *Node) StartPos() int { pFirstNode, _ := strconv.Atoi(fmt.Sprintf("%d", node.head.surface)) pCurrentNode, _ := strconv.Atoi(fmt.Sprintf("%d", node.current.surface)) return utf8.RuneCountInString(C.GoStringN(node.head.surface, C.int(pCurrentNode-pFirstNode))) }
go
func (node *Node) StartPos() int { pFirstNode, _ := strconv.Atoi(fmt.Sprintf("%d", node.head.surface)) pCurrentNode, _ := strconv.Atoi(fmt.Sprintf("%d", node.current.surface)) return utf8.RuneCountInString(C.GoStringN(node.head.surface, C.int(pCurrentNode-pFirstNode))) }
[ "func", "(", "node", "*", "Node", ")", "StartPos", "(", ")", "int", "{", "pFirstNode", ",", "_", ":=", "strconv", ".", "Atoi", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "node", ".", "head", ".", "surface", ")", ")", "\n", "pCurrentNode", ...
// start pos in the text.
[ "start", "pos", "in", "the", "text", "." ]
c8cfe04e87f99006004f2bb27f101a96b2f7f28b
https://github.com/bluele/mecab-golang/blob/c8cfe04e87f99006004f2bb27f101a96b2f7f28b/node.go#L114-L118
12,352
aclements/go-moremath
scale/linear.go
ebase
func (s Linear) ebase() int { if s.Base == 0 { return 10 } else if s.Base == 1 { panic("scale.Linear cannot have a base of 1") } else if s.Base < 0 { panic("scale.Linear cannot have a negative base") } return s.Base }
go
func (s Linear) ebase() int { if s.Base == 0 { return 10 } else if s.Base == 1 { panic("scale.Linear cannot have a base of 1") } else if s.Base < 0 { panic("scale.Linear cannot have a negative base") } return s.Base }
[ "func", "(", "s", "Linear", ")", "ebase", "(", ")", "int", "{", "if", "s", ".", "Base", "==", "0", "{", "return", "10", "\n", "}", "else", "if", "s", ".", "Base", "==", "1", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "else", "if", "s", ...
// ebase sanity checks and returns the "effective base" of this scale. // If s.Base is 0, it returns 10. If s.Base is 1 or negative, it // panics.
[ "ebase", "sanity", "checks", "and", "returns", "the", "effective", "base", "of", "this", "scale", ".", "If", "s", ".", "Base", "is", "0", "it", "returns", "10", ".", "If", "s", ".", "Base", "is", "1", "or", "negative", "it", "panics", "." ]
b1aff36309c727972dd8b46fcc93f88763a62348
https://github.com/aclements/go-moremath/blob/b1aff36309c727972dd8b46fcc93f88763a62348/scale/linear.go#L55-L64
12,353
aclements/go-moremath
scale/interface.go
Map
func (q QQ) Map(x float64) float64 { return q.Dest.Unmap(q.Src.Map(x)) }
go
func (q QQ) Map(x float64) float64 { return q.Dest.Unmap(q.Src.Map(x)) }
[ "func", "(", "q", "QQ", ")", "Map", "(", "x", "float64", ")", "float64", "{", "return", "q", ".", "Dest", ".", "Unmap", "(", "q", ".", "Src", ".", "Map", "(", "x", ")", ")", "\n", "}" ]
// Map maps from a value x in the source scale's input domain to a // value y in the destination scale's input domain.
[ "Map", "maps", "from", "a", "value", "x", "in", "the", "source", "scale", "s", "input", "domain", "to", "a", "value", "y", "in", "the", "destination", "scale", "s", "input", "domain", "." ]
b1aff36309c727972dd8b46fcc93f88763a62348
https://github.com/aclements/go-moremath/blob/b1aff36309c727972dd8b46fcc93f88763a62348/scale/interface.go#L49-L51
12,354
aclements/go-moremath
stats/stream.go
Add
func (s *StreamStats) Add(x float64) { s.Total += x if s.Count == 0 { s.Min, s.Max = x, x } else { if x < s.Min { s.Min = x } if x > s.Max { s.Max = x } } s.Count++ // Update online mean, mean of squares, and variance. Online // variance based on Wikipedia's presentation ("Algorithms for // ca...
go
func (s *StreamStats) Add(x float64) { s.Total += x if s.Count == 0 { s.Min, s.Max = x, x } else { if x < s.Min { s.Min = x } if x > s.Max { s.Max = x } } s.Count++ // Update online mean, mean of squares, and variance. Online // variance based on Wikipedia's presentation ("Algorithms for // ca...
[ "func", "(", "s", "*", "StreamStats", ")", "Add", "(", "x", "float64", ")", "{", "s", ".", "Total", "+=", "x", "\n", "if", "s", ".", "Count", "==", "0", "{", "s", ".", "Min", ",", "s", ".", "Max", "=", "x", ",", "x", "\n", "}", "else", "{...
// Add updates s's statistics with sample value x.
[ "Add", "updates", "s", "s", "statistics", "with", "sample", "value", "x", "." ]
b1aff36309c727972dd8b46fcc93f88763a62348
https://github.com/aclements/go-moremath/blob/b1aff36309c727972dd8b46fcc93f88763a62348/stats/stream.go#L31-L53
12,355
aclements/go-moremath
stats/stream.go
Combine
func (s *StreamStats) Combine(o *StreamStats) { count := s.Count + o.Count // Compute combined online variance statistics delta := o.mean - s.mean mean := s.mean + delta*float64(o.Count)/float64(count) vM2 := s.vM2 + o.vM2 + delta*delta*float64(s.Count)*float64(o.Count)/float64(count) s.Count = count s.Total +...
go
func (s *StreamStats) Combine(o *StreamStats) { count := s.Count + o.Count // Compute combined online variance statistics delta := o.mean - s.mean mean := s.mean + delta*float64(o.Count)/float64(count) vM2 := s.vM2 + o.vM2 + delta*delta*float64(s.Count)*float64(o.Count)/float64(count) s.Count = count s.Total +...
[ "func", "(", "s", "*", "StreamStats", ")", "Combine", "(", "o", "*", "StreamStats", ")", "{", "count", ":=", "s", ".", "Count", "+", "o", ".", "Count", "\n\n", "// Compute combined online variance statistics", "delta", ":=", "o", ".", "mean", "-", "s", "...
// Combine updates s's statistics as if all samples added to o were // added to s.
[ "Combine", "updates", "s", "s", "statistics", "as", "if", "all", "samples", "added", "to", "o", "were", "added", "to", "s", "." ]
b1aff36309c727972dd8b46fcc93f88763a62348
https://github.com/aclements/go-moremath/blob/b1aff36309c727972dd8b46fcc93f88763a62348/stats/stream.go#L77-L96
12,356
aclements/go-moremath
stats/udist.go
hasTies
func (d UDist) hasTies() bool { for _, t := range d.T { if t > 1 { return true } } return false }
go
func (d UDist) hasTies() bool { for _, t := range d.T { if t > 1 { return true } } return false }
[ "func", "(", "d", "UDist", ")", "hasTies", "(", ")", "bool", "{", "for", "_", ",", "t", ":=", "range", "d", ".", "T", "{", "if", "t", ">", "1", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// hasTies returns true if d has any tied samples.
[ "hasTies", "returns", "true", "if", "d", "has", "any", "tied", "samples", "." ]
b1aff36309c727972dd8b46fcc93f88763a62348
https://github.com/aclements/go-moremath/blob/b1aff36309c727972dd8b46fcc93f88763a62348/stats/udist.go#L40-L47
12,357
aclements/go-moremath
mathx/choose.go
Choose
func Choose(n, k int) float64 { if k == 0 || k == n { return 1 } if k < 0 || n < k { return 0 } if n <= smallFactLimit { // Implies k <= smallFactLimit // It's faster to do several integer multiplications // than it is to do an extra integer division. // Remarkably, this is also faster than pre-computing...
go
func Choose(n, k int) float64 { if k == 0 || k == n { return 1 } if k < 0 || n < k { return 0 } if n <= smallFactLimit { // Implies k <= smallFactLimit // It's faster to do several integer multiplications // than it is to do an extra integer division. // Remarkably, this is also faster than pre-computing...
[ "func", "Choose", "(", "n", ",", "k", "int", ")", "float64", "{", "if", "k", "==", "0", "||", "k", "==", "n", "{", "return", "1", "\n", "}", "\n", "if", "k", "<", "0", "||", "n", "<", "k", "{", "return", "0", "\n", "}", "\n", "if", "n", ...
// Choose returns the binomial coefficient of n and k.
[ "Choose", "returns", "the", "binomial", "coefficient", "of", "n", "and", "k", "." ]
b1aff36309c727972dd8b46fcc93f88763a62348
https://github.com/aclements/go-moremath/blob/b1aff36309c727972dd8b46fcc93f88763a62348/mathx/choose.go#L22-L44
12,358
aclements/go-moremath
stats/sample.go
Bounds
func Bounds(xs []float64) (min float64, max float64) { if len(xs) == 0 { return math.NaN(), math.NaN() } min, max = xs[0], xs[0] for _, x := range xs { if x < min { min = x } if x > max { max = x } } return }
go
func Bounds(xs []float64) (min float64, max float64) { if len(xs) == 0 { return math.NaN(), math.NaN() } min, max = xs[0], xs[0] for _, x := range xs { if x < min { min = x } if x > max { max = x } } return }
[ "func", "Bounds", "(", "xs", "[", "]", "float64", ")", "(", "min", "float64", ",", "max", "float64", ")", "{", "if", "len", "(", "xs", ")", "==", "0", "{", "return", "math", ".", "NaN", "(", ")", ",", "math", ".", "NaN", "(", ")", "\n", "}", ...
// Bounds returns the minimum and maximum values of xs.
[ "Bounds", "returns", "the", "minimum", "and", "maximum", "values", "of", "xs", "." ]
b1aff36309c727972dd8b46fcc93f88763a62348
https://github.com/aclements/go-moremath/blob/b1aff36309c727972dd8b46fcc93f88763a62348/stats/sample.go#L29-L43
12,359
aclements/go-moremath
stats/sample.go
Bounds
func (s Sample) Bounds() (min float64, max float64) { if len(s.Xs) == 0 || (!s.Sorted && s.Weights == nil) { return Bounds(s.Xs) } if s.Sorted { if s.Weights == nil { return s.Xs[0], s.Xs[len(s.Xs)-1] } min, max = math.NaN(), math.NaN() for i, w := range s.Weights { if w != 0 { min = s.Xs[i] ...
go
func (s Sample) Bounds() (min float64, max float64) { if len(s.Xs) == 0 || (!s.Sorted && s.Weights == nil) { return Bounds(s.Xs) } if s.Sorted { if s.Weights == nil { return s.Xs[0], s.Xs[len(s.Xs)-1] } min, max = math.NaN(), math.NaN() for i, w := range s.Weights { if w != 0 { min = s.Xs[i] ...
[ "func", "(", "s", "Sample", ")", "Bounds", "(", ")", "(", "min", "float64", ",", "max", "float64", ")", "{", "if", "len", "(", "s", ".", "Xs", ")", "==", "0", "||", "(", "!", "s", ".", "Sorted", "&&", "s", ".", "Weights", "==", "nil", ")", ...
// Bounds returns the minimum and maximum values of the Sample. // // If the Sample is weighted, this ignores samples with zero weight. // // This is constant time if s.Sorted and there are no zero-weighted // values.
[ "Bounds", "returns", "the", "minimum", "and", "maximum", "values", "of", "the", "Sample", ".", "If", "the", "Sample", "is", "weighted", "this", "ignores", "samples", "with", "zero", "weight", ".", "This", "is", "constant", "time", "if", "s", ".", "Sorted",...
b1aff36309c727972dd8b46fcc93f88763a62348
https://github.com/aclements/go-moremath/blob/b1aff36309c727972dd8b46fcc93f88763a62348/stats/sample.go#L51-L92
12,360
aclements/go-moremath
stats/sample.go
Weight
func (s Sample) Weight() float64 { if s.Weights == nil { return float64(len(s.Xs)) } return vec.Sum(s.Weights) }
go
func (s Sample) Weight() float64 { if s.Weights == nil { return float64(len(s.Xs)) } return vec.Sum(s.Weights) }
[ "func", "(", "s", "Sample", ")", "Weight", "(", ")", "float64", "{", "if", "s", ".", "Weights", "==", "nil", "{", "return", "float64", "(", "len", "(", "s", ".", "Xs", ")", ")", "\n", "}", "\n", "return", "vec", ".", "Sum", "(", "s", ".", "We...
// Weight returns the total weight of the Sasmple.
[ "Weight", "returns", "the", "total", "weight", "of", "the", "Sasmple", "." ]
b1aff36309c727972dd8b46fcc93f88763a62348
https://github.com/aclements/go-moremath/blob/b1aff36309c727972dd8b46fcc93f88763a62348/stats/sample.go#L107-L112
12,361
aclements/go-moremath
stats/sample.go
Mean
func Mean(xs []float64) float64 { if len(xs) == 0 { return math.NaN() } m := 0.0 for i, x := range xs { m += (x - m) / float64(i+1) } return m }
go
func Mean(xs []float64) float64 { if len(xs) == 0 { return math.NaN() } m := 0.0 for i, x := range xs { m += (x - m) / float64(i+1) } return m }
[ "func", "Mean", "(", "xs", "[", "]", "float64", ")", "float64", "{", "if", "len", "(", "xs", ")", "==", "0", "{", "return", "math", ".", "NaN", "(", ")", "\n", "}", "\n", "m", ":=", "0.0", "\n", "for", "i", ",", "x", ":=", "range", "xs", "{...
// Mean returns the arithmetic mean of xs.
[ "Mean", "returns", "the", "arithmetic", "mean", "of", "xs", "." ]
b1aff36309c727972dd8b46fcc93f88763a62348
https://github.com/aclements/go-moremath/blob/b1aff36309c727972dd8b46fcc93f88763a62348/stats/sample.go#L115-L124
12,362
aclements/go-moremath
stats/sample.go
Mean
func (s Sample) Mean() float64 { if len(s.Xs) == 0 || s.Weights == nil { return Mean(s.Xs) } m, wsum := 0.0, 0.0 for i, x := range s.Xs { // Use weighted incremental mean: // m_i = (1 - w_i/wsum_i) * m_(i-1) + (w_i/wsum_i) * x_i // = m_(i-1) + (x_i - m_(i-1)) * (w_i/wsum_i) w := s.Weights[i] ws...
go
func (s Sample) Mean() float64 { if len(s.Xs) == 0 || s.Weights == nil { return Mean(s.Xs) } m, wsum := 0.0, 0.0 for i, x := range s.Xs { // Use weighted incremental mean: // m_i = (1 - w_i/wsum_i) * m_(i-1) + (w_i/wsum_i) * x_i // = m_(i-1) + (x_i - m_(i-1)) * (w_i/wsum_i) w := s.Weights[i] ws...
[ "func", "(", "s", "Sample", ")", "Mean", "(", ")", "float64", "{", "if", "len", "(", "s", ".", "Xs", ")", "==", "0", "||", "s", ".", "Weights", "==", "nil", "{", "return", "Mean", "(", "s", ".", "Xs", ")", "\n", "}", "\n\n", "m", ",", "wsum...
// Mean returns the arithmetic mean of the Sample.
[ "Mean", "returns", "the", "arithmetic", "mean", "of", "the", "Sample", "." ]
b1aff36309c727972dd8b46fcc93f88763a62348
https://github.com/aclements/go-moremath/blob/b1aff36309c727972dd8b46fcc93f88763a62348/stats/sample.go#L127-L142
12,363
aclements/go-moremath
stats/sample.go
GeoMean
func GeoMean(xs []float64) float64 { if len(xs) == 0 { return math.NaN() } m := 0.0 for i, x := range xs { if x <= 0 { return math.NaN() } lx := math.Log(x) m += (lx - m) / float64(i+1) } return math.Exp(m) }
go
func GeoMean(xs []float64) float64 { if len(xs) == 0 { return math.NaN() } m := 0.0 for i, x := range xs { if x <= 0 { return math.NaN() } lx := math.Log(x) m += (lx - m) / float64(i+1) } return math.Exp(m) }
[ "func", "GeoMean", "(", "xs", "[", "]", "float64", ")", "float64", "{", "if", "len", "(", "xs", ")", "==", "0", "{", "return", "math", ".", "NaN", "(", ")", "\n", "}", "\n", "m", ":=", "0.0", "\n", "for", "i", ",", "x", ":=", "range", "xs", ...
// GeoMean returns the geometric mean of xs. xs must be positive.
[ "GeoMean", "returns", "the", "geometric", "mean", "of", "xs", ".", "xs", "must", "be", "positive", "." ]
b1aff36309c727972dd8b46fcc93f88763a62348
https://github.com/aclements/go-moremath/blob/b1aff36309c727972dd8b46fcc93f88763a62348/stats/sample.go#L145-L158
12,364
aclements/go-moremath
stats/sample.go
GeoMean
func (s Sample) GeoMean() float64 { if len(s.Xs) == 0 || s.Weights == nil { return GeoMean(s.Xs) } m, wsum := 0.0, 0.0 for i, x := range s.Xs { w := s.Weights[i] wsum += w lx := math.Log(x) m += (lx - m) * w / wsum } return math.Exp(m) }
go
func (s Sample) GeoMean() float64 { if len(s.Xs) == 0 || s.Weights == nil { return GeoMean(s.Xs) } m, wsum := 0.0, 0.0 for i, x := range s.Xs { w := s.Weights[i] wsum += w lx := math.Log(x) m += (lx - m) * w / wsum } return math.Exp(m) }
[ "func", "(", "s", "Sample", ")", "GeoMean", "(", ")", "float64", "{", "if", "len", "(", "s", ".", "Xs", ")", "==", "0", "||", "s", ".", "Weights", "==", "nil", "{", "return", "GeoMean", "(", "s", ".", "Xs", ")", "\n", "}", "\n\n", "m", ",", ...
// GeoMean returns the geometric mean of the Sample. All samples // values must be positive.
[ "GeoMean", "returns", "the", "geometric", "mean", "of", "the", "Sample", ".", "All", "samples", "values", "must", "be", "positive", "." ]
b1aff36309c727972dd8b46fcc93f88763a62348
https://github.com/aclements/go-moremath/blob/b1aff36309c727972dd8b46fcc93f88763a62348/stats/sample.go#L162-L175
12,365
aclements/go-moremath
stats/sample.go
Variance
func Variance(xs []float64) float64 { if len(xs) == 0 { return math.NaN() } else if len(xs) <= 1 { return 0 } // Based on Wikipedia's presentation of Welford 1962 // (http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Online_algorithm). // This is more numerically stable than the standard two-p...
go
func Variance(xs []float64) float64 { if len(xs) == 0 { return math.NaN() } else if len(xs) <= 1 { return 0 } // Based on Wikipedia's presentation of Welford 1962 // (http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Online_algorithm). // This is more numerically stable than the standard two-p...
[ "func", "Variance", "(", "xs", "[", "]", "float64", ")", "float64", "{", "if", "len", "(", "xs", ")", "==", "0", "{", "return", "math", ".", "NaN", "(", ")", "\n", "}", "else", "if", "len", "(", "xs", ")", "<=", "1", "{", "return", "0", "\n",...
// Variance returns the sample variance of xs.
[ "Variance", "returns", "the", "sample", "variance", "of", "xs", "." ]
b1aff36309c727972dd8b46fcc93f88763a62348
https://github.com/aclements/go-moremath/blob/b1aff36309c727972dd8b46fcc93f88763a62348/stats/sample.go#L178-L196
12,366
aclements/go-moremath
stats/sample.go
StdDev
func (s Sample) StdDev() float64 { if len(s.Xs) == 0 || s.Weights == nil { return StdDev(s.Xs) } // TODO(austin) panic("Weighted StdDev not implemented") }
go
func (s Sample) StdDev() float64 { if len(s.Xs) == 0 || s.Weights == nil { return StdDev(s.Xs) } // TODO(austin) panic("Weighted StdDev not implemented") }
[ "func", "(", "s", "Sample", ")", "StdDev", "(", ")", "float64", "{", "if", "len", "(", "s", ".", "Xs", ")", "==", "0", "||", "s", ".", "Weights", "==", "nil", "{", "return", "StdDev", "(", "s", ".", "Xs", ")", "\n", "}", "\n", "// TODO(austin)"...
// StdDev returns the sample standard deviation of the Sample.
[ "StdDev", "returns", "the", "sample", "standard", "deviation", "of", "the", "Sample", "." ]
b1aff36309c727972dd8b46fcc93f88763a62348
https://github.com/aclements/go-moremath/blob/b1aff36309c727972dd8b46fcc93f88763a62348/stats/sample.go#L212-L218
12,367
aclements/go-moremath
stats/sample.go
IQR
func (s Sample) IQR() float64 { if !s.Sorted { s = *s.Copy().Sort() } return s.Quantile(0.75) - s.Quantile(0.25) }
go
func (s Sample) IQR() float64 { if !s.Sorted { s = *s.Copy().Sort() } return s.Quantile(0.75) - s.Quantile(0.25) }
[ "func", "(", "s", "Sample", ")", "IQR", "(", ")", "float64", "{", "if", "!", "s", ".", "Sorted", "{", "s", "=", "*", "s", ".", "Copy", "(", ")", ".", "Sort", "(", ")", "\n", "}", "\n", "return", "s", ".", "Quantile", "(", "0.75", ")", "-", ...
// IQR returns the interquartile range of the Sample. // // This is constant time if s.Sorted and s.Weights == nil.
[ "IQR", "returns", "the", "interquartile", "range", "of", "the", "Sample", ".", "This", "is", "constant", "time", "if", "s", ".", "Sorted", "and", "s", ".", "Weights", "==", "nil", "." ]
b1aff36309c727972dd8b46fcc93f88763a62348
https://github.com/aclements/go-moremath/blob/b1aff36309c727972dd8b46fcc93f88763a62348/stats/sample.go#L280-L285
12,368
aclements/go-moremath
stats/sample.go
Sort
func (s *Sample) Sort() *Sample { if s.Sorted || sort.Float64sAreSorted(s.Xs) { // All set } else if s.Weights == nil { sort.Float64s(s.Xs) } else { sort.Sort(&sampleSorter{s.Xs, s.Weights}) } s.Sorted = true return s }
go
func (s *Sample) Sort() *Sample { if s.Sorted || sort.Float64sAreSorted(s.Xs) { // All set } else if s.Weights == nil { sort.Float64s(s.Xs) } else { sort.Sort(&sampleSorter{s.Xs, s.Weights}) } s.Sorted = true return s }
[ "func", "(", "s", "*", "Sample", ")", "Sort", "(", ")", "*", "Sample", "{", "if", "s", ".", "Sorted", "||", "sort", ".", "Float64sAreSorted", "(", "s", ".", "Xs", ")", "{", "// All set", "}", "else", "if", "s", ".", "Weights", "==", "nil", "{", ...
// Sort sorts the samples in place in s and returns s. // // A sorted sample improves the performance of some algorithms.
[ "Sort", "sorts", "the", "samples", "in", "place", "in", "s", "and", "returns", "s", ".", "A", "sorted", "sample", "improves", "the", "performance", "of", "some", "algorithms", "." ]
b1aff36309c727972dd8b46fcc93f88763a62348
https://github.com/aclements/go-moremath/blob/b1aff36309c727972dd8b46fcc93f88763a62348/stats/sample.go#L308-L318
12,369
aclements/go-moremath
scale/log.go
NewLog
func NewLog(min, max float64, base int) (Log, error) { if min > max { min, max = max, min } if base <= 1 { return Log{}, RangeErr("Log scale base must be 2 or more") } if min <= 0 && max >= 0 { return Log{}, RangeErr("Log scale range cannot include 0") } return Log{Min: min, Max: max, Base: base}, nil }
go
func NewLog(min, max float64, base int) (Log, error) { if min > max { min, max = max, min } if base <= 1 { return Log{}, RangeErr("Log scale base must be 2 or more") } if min <= 0 && max >= 0 { return Log{}, RangeErr("Log scale range cannot include 0") } return Log{Min: min, Max: max, Base: base}, nil }
[ "func", "NewLog", "(", "min", ",", "max", "float64", ",", "base", "int", ")", "(", "Log", ",", "error", ")", "{", "if", "min", ">", "max", "{", "min", ",", "max", "=", "max", ",", "min", "\n", "}", "\n\n", "if", "base", "<=", "1", "{", "retur...
// NewLog constructs a Log scale. If the arguments are out of range, // it returns a RangeErr.
[ "NewLog", "constructs", "a", "Log", "scale", ".", "If", "the", "arguments", "are", "out", "of", "range", "it", "returns", "a", "RangeErr", "." ]
b1aff36309c727972dd8b46fcc93f88763a62348
https://github.com/aclements/go-moremath/blob/b1aff36309c727972dd8b46fcc93f88763a62348/scale/log.go#L36-L49
12,370
aclements/go-moremath
fit/lsquares.go
PolynomialRegression
func PolynomialRegression(xs, ys, weights []float64, degree int) PolynomialRegressionResult { terms := make([]func(xs, termOut []float64), degree+1) terms[0] = func(xs, termsOut []float64) { for i := range termsOut { termsOut[i] = 1 } } if degree >= 1 { terms[1] = func(xs, termOut []float64) { copy(term...
go
func PolynomialRegression(xs, ys, weights []float64, degree int) PolynomialRegressionResult { terms := make([]func(xs, termOut []float64), degree+1) terms[0] = func(xs, termsOut []float64) { for i := range termsOut { termsOut[i] = 1 } } if degree >= 1 { terms[1] = func(xs, termOut []float64) { copy(term...
[ "func", "PolynomialRegression", "(", "xs", ",", "ys", ",", "weights", "[", "]", "float64", ",", "degree", "int", ")", "PolynomialRegressionResult", "{", "terms", ":=", "make", "(", "[", "]", "func", "(", "xs", ",", "termOut", "[", "]", "float64", ")", ...
// PolynomialRegression performs a least squares regression with a // polynomial of the given degree. If weights is non-nil, it is used // to weight the residuals.
[ "PolynomialRegression", "performs", "a", "least", "squares", "regression", "with", "a", "polynomial", "of", "the", "given", "degree", ".", "If", "weights", "is", "non", "-", "nil", "it", "is", "used", "to", "weight", "the", "residuals", "." ]
b1aff36309c727972dd8b46fcc93f88763a62348
https://github.com/aclements/go-moremath/blob/b1aff36309c727972dd8b46fcc93f88763a62348/fit/lsquares.go#L135-L174
12,371
aclements/go-moremath
vec/vec.go
Linspace
func Linspace(lo, hi float64, num int) []float64 { res := make([]float64, num) if num == 1 { res[0] = lo return res } for i := 0; i < num; i++ { res[i] = lo + float64(i)*(hi-lo)/float64(num-1) } return res }
go
func Linspace(lo, hi float64, num int) []float64 { res := make([]float64, num) if num == 1 { res[0] = lo return res } for i := 0; i < num; i++ { res[i] = lo + float64(i)*(hi-lo)/float64(num-1) } return res }
[ "func", "Linspace", "(", "lo", ",", "hi", "float64", ",", "num", "int", ")", "[", "]", "float64", "{", "res", ":=", "make", "(", "[", "]", "float64", ",", "num", ")", "\n", "if", "num", "==", "1", "{", "res", "[", "0", "]", "=", "lo", "\n", ...
// Linspace returns num values spaced evenly between lo and hi, // inclusive. If num is 1, this returns an array consisting of lo.
[ "Linspace", "returns", "num", "values", "spaced", "evenly", "between", "lo", "and", "hi", "inclusive", ".", "If", "num", "is", "1", "this", "returns", "an", "array", "consisting", "of", "lo", "." ]
b1aff36309c727972dd8b46fcc93f88763a62348
https://github.com/aclements/go-moremath/blob/b1aff36309c727972dd8b46fcc93f88763a62348/vec/vec.go#L32-L42
12,372
aclements/go-moremath
vec/vec.go
Sum
func Sum(xs []float64) float64 { sum := 0.0 for _, x := range xs { sum += x } return sum }
go
func Sum(xs []float64) float64 { sum := 0.0 for _, x := range xs { sum += x } return sum }
[ "func", "Sum", "(", "xs", "[", "]", "float64", ")", "float64", "{", "sum", ":=", "0.0", "\n", "for", "_", ",", "x", ":=", "range", "xs", "{", "sum", "+=", "x", "\n", "}", "\n", "return", "sum", "\n", "}" ]
// Sum returns the sum of xs.
[ "Sum", "returns", "the", "sum", "of", "xs", "." ]
b1aff36309c727972dd8b46fcc93f88763a62348
https://github.com/aclements/go-moremath/blob/b1aff36309c727972dd8b46fcc93f88763a62348/vec/vec.go#L55-L61
12,373
aclements/go-moremath
vec/vec.go
Concat
func Concat(xss ...[]float64) []float64 { total := 0 for _, xs := range xss { total += len(xs) } out := make([]float64, total) pos := 0 for _, xs := range xss { pos += copy(out[pos:], xs) } return out }
go
func Concat(xss ...[]float64) []float64 { total := 0 for _, xs := range xss { total += len(xs) } out := make([]float64, total) pos := 0 for _, xs := range xss { pos += copy(out[pos:], xs) } return out }
[ "func", "Concat", "(", "xss", "...", "[", "]", "float64", ")", "[", "]", "float64", "{", "total", ":=", "0", "\n", "for", "_", ",", "xs", ":=", "range", "xss", "{", "total", "+=", "len", "(", "xs", ")", "\n", "}", "\n", "out", ":=", "make", "...
// Concat returns the concatenation of its arguments. It does not // modify its inputs.
[ "Concat", "returns", "the", "concatenation", "of", "its", "arguments", ".", "It", "does", "not", "modify", "its", "inputs", "." ]
b1aff36309c727972dd8b46fcc93f88763a62348
https://github.com/aclements/go-moremath/blob/b1aff36309c727972dd8b46fcc93f88763a62348/vec/vec.go#L65-L76
12,374
aclements/go-moremath
cmd/dist/plot.go
FprintCDF
func FprintCDF(w io.Writer, dists ...stats.Dist) error { xscale, xs := commonScale(dists...) for _, d := range dists { if err := fprintFn(w, d.CDF, xscale, xs); err != nil { return err } } return fprintScale(w, xscale) }
go
func FprintCDF(w io.Writer, dists ...stats.Dist) error { xscale, xs := commonScale(dists...) for _, d := range dists { if err := fprintFn(w, d.CDF, xscale, xs); err != nil { return err } } return fprintScale(w, xscale) }
[ "func", "FprintCDF", "(", "w", "io", ".", "Writer", ",", "dists", "...", "stats", ".", "Dist", ")", "error", "{", "xscale", ",", "xs", ":=", "commonScale", "(", "dists", "...", ")", "\n", "for", "_", ",", "d", ":=", "range", "dists", "{", "if", "...
// FprintCDF is equivalent to FprintPDF, but prints the CDF of each // distribution.
[ "FprintCDF", "is", "equivalent", "to", "FprintPDF", "but", "prints", "the", "CDF", "of", "each", "distribution", "." ]
b1aff36309c727972dd8b46fcc93f88763a62348
https://github.com/aclements/go-moremath/blob/b1aff36309c727972dd8b46fcc93f88763a62348/cmd/dist/plot.go#L48-L56
12,375
aclements/go-moremath
cmd/dist/plot.go
makeScale
func makeScale(x1, x2 float64, y1, y2 int) scale.QQ { return scale.QQ{ Src: &scale.Linear{Min: x1, Max: x2, Clamp: true}, Dest: &scale.Linear{Min: float64(y1), Max: float64(y2) - 1e-10}, } }
go
func makeScale(x1, x2 float64, y1, y2 int) scale.QQ { return scale.QQ{ Src: &scale.Linear{Min: x1, Max: x2, Clamp: true}, Dest: &scale.Linear{Min: float64(y1), Max: float64(y2) - 1e-10}, } }
[ "func", "makeScale", "(", "x1", ",", "x2", "float64", ",", "y1", ",", "y2", "int", ")", "scale", ".", "QQ", "{", "return", "scale", ".", "QQ", "{", "Src", ":", "&", "scale", ".", "Linear", "{", "Min", ":", "x1", ",", "Max", ":", "x2", ",", "C...
// makeScale creates a linear scale from [x1, x2) to [y1, y2).
[ "makeScale", "creates", "a", "linear", "scale", "from", "[", "x1", "x2", ")", "to", "[", "y1", "y2", ")", "." ]
b1aff36309c727972dd8b46fcc93f88763a62348
https://github.com/aclements/go-moremath/blob/b1aff36309c727972dd8b46fcc93f88763a62348/cmd/dist/plot.go#L59-L64
12,376
mikioh/ipaddr
prefix.go
Contains
func (p *Prefix) Contains(q *Prefix) bool { if p.IP.To4() != nil { return p.containsIPv4(q) } if p.IP.To16() != nil && p.IP.To4() == nil { return p.containsIPv6(q) } return false }
go
func (p *Prefix) Contains(q *Prefix) bool { if p.IP.To4() != nil { return p.containsIPv4(q) } if p.IP.To16() != nil && p.IP.To4() == nil { return p.containsIPv6(q) } return false }
[ "func", "(", "p", "*", "Prefix", ")", "Contains", "(", "q", "*", "Prefix", ")", "bool", "{", "if", "p", ".", "IP", ".", "To4", "(", ")", "!=", "nil", "{", "return", "p", ".", "containsIPv4", "(", "q", ")", "\n", "}", "\n", "if", "p", ".", "...
// Contains reports whether q is a subnetwork of p.
[ "Contains", "reports", "whether", "q", "is", "a", "subnetwork", "of", "p", "." ]
d465c8ab672111787b24b8f03326449059a4aa33
https://github.com/mikioh/ipaddr/blob/d465c8ab672111787b24b8f03326449059a4aa33/prefix.go#L56-L64
12,377
mikioh/ipaddr
prefix.go
Exclude
func (p *Prefix) Exclude(q *Prefix) []Prefix { if !p.IPNet.Contains(q.IP) { return nil } if p.Equal(q) { return []Prefix{*q} } subsFn := subnetsIPv6 if p.IP.To4() != nil { subsFn = subnetsIPv4 } var ps []Prefix l, r := subsFn(p, false) for !l.Equal(q) && !r.Equal(q) { if l.IPNet.Contains(q.IP) { ps...
go
func (p *Prefix) Exclude(q *Prefix) []Prefix { if !p.IPNet.Contains(q.IP) { return nil } if p.Equal(q) { return []Prefix{*q} } subsFn := subnetsIPv6 if p.IP.To4() != nil { subsFn = subnetsIPv4 } var ps []Prefix l, r := subsFn(p, false) for !l.Equal(q) && !r.Equal(q) { if l.IPNet.Contains(q.IP) { ps...
[ "func", "(", "p", "*", "Prefix", ")", "Exclude", "(", "q", "*", "Prefix", ")", "[", "]", "Prefix", "{", "if", "!", "p", ".", "IPNet", ".", "Contains", "(", "q", ".", "IP", ")", "{", "return", "nil", "\n", "}", "\n", "if", "p", ".", "Equal", ...
// Exclude returns a list of prefixes that do not contain q.
[ "Exclude", "returns", "a", "list", "of", "prefixes", "that", "do", "not", "contain", "q", "." ]
d465c8ab672111787b24b8f03326449059a4aa33
https://github.com/mikioh/ipaddr/blob/d465c8ab672111787b24b8f03326449059a4aa33/prefix.go#L111-L139
12,378
mikioh/ipaddr
prefix.go
Last
func (p *Prefix) Last() net.IP { if p.IP.To4() != nil { i := p.lastIPv4Int() return i.ip() } if p.IP.To16() != nil && p.IP.To4() == nil { i := p.lastIPv6Int() return i.ip() } return nil }
go
func (p *Prefix) Last() net.IP { if p.IP.To4() != nil { i := p.lastIPv4Int() return i.ip() } if p.IP.To16() != nil && p.IP.To4() == nil { i := p.lastIPv6Int() return i.ip() } return nil }
[ "func", "(", "p", "*", "Prefix", ")", "Last", "(", ")", "net", ".", "IP", "{", "if", "p", ".", "IP", ".", "To4", "(", ")", "!=", "nil", "{", "i", ":=", "p", ".", "lastIPv4Int", "(", ")", "\n", "return", "i", ".", "ip", "(", ")", "\n", "}"...
// Last returns the last IP in the address range of p. // It returns the address of p when p contains only one address.
[ "Last", "returns", "the", "last", "IP", "in", "the", "address", "range", "of", "p", ".", "It", "returns", "the", "address", "of", "p", "when", "p", "contains", "only", "one", "address", "." ]
d465c8ab672111787b24b8f03326449059a4aa33
https://github.com/mikioh/ipaddr/blob/d465c8ab672111787b24b8f03326449059a4aa33/prefix.go#L178-L188
12,379
mikioh/ipaddr
prefix.go
Len
func (p *Prefix) Len() int { l, _ := p.Mask.Size() return l }
go
func (p *Prefix) Len() int { l, _ := p.Mask.Size() return l }
[ "func", "(", "p", "*", "Prefix", ")", "Len", "(", ")", "int", "{", "l", ",", "_", ":=", "p", ".", "Mask", ".", "Size", "(", ")", "\n", "return", "l", "\n", "}" ]
// Len returns the length of p in bits.
[ "Len", "returns", "the", "length", "of", "p", "in", "bits", "." ]
d465c8ab672111787b24b8f03326449059a4aa33
https://github.com/mikioh/ipaddr/blob/d465c8ab672111787b24b8f03326449059a4aa33/prefix.go#L191-L194
12,380
mikioh/ipaddr
prefix.go
MarshalBinary
func (p *Prefix) MarshalBinary() ([]byte, error) { ip := p.IP if p.IP.To4() != nil { ip = p.IP.To4() } var b [1 + net.IPv6len]byte n := p.Len() l := ((n + 8 - 1) &^ (8 - 1)) / 8 b[0] = byte(n) l++ copy(b[1:l], ip) return b[:l], nil }
go
func (p *Prefix) MarshalBinary() ([]byte, error) { ip := p.IP if p.IP.To4() != nil { ip = p.IP.To4() } var b [1 + net.IPv6len]byte n := p.Len() l := ((n + 8 - 1) &^ (8 - 1)) / 8 b[0] = byte(n) l++ copy(b[1:l], ip) return b[:l], nil }
[ "func", "(", "p", "*", "Prefix", ")", "MarshalBinary", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "ip", ":=", "p", ".", "IP", "\n", "if", "p", ".", "IP", ".", "To4", "(", ")", "!=", "nil", "{", "ip", "=", "p", ".", "IP", "."...
// MarshalBinary returns a BGP NLRI binary form of p.
[ "MarshalBinary", "returns", "a", "BGP", "NLRI", "binary", "form", "of", "p", "." ]
d465c8ab672111787b24b8f03326449059a4aa33
https://github.com/mikioh/ipaddr/blob/d465c8ab672111787b24b8f03326449059a4aa33/prefix.go#L197-L209
12,381
mikioh/ipaddr
prefix.go
NumNodes
func (p *Prefix) NumNodes() *big.Int { i := new(big.Int).SetBytes(invert(p.Mask)) return i.Add(i, big.NewInt(1)) }
go
func (p *Prefix) NumNodes() *big.Int { i := new(big.Int).SetBytes(invert(p.Mask)) return i.Add(i, big.NewInt(1)) }
[ "func", "(", "p", "*", "Prefix", ")", "NumNodes", "(", ")", "*", "big", ".", "Int", "{", "i", ":=", "new", "(", "big", ".", "Int", ")", ".", "SetBytes", "(", "invert", "(", "p", ".", "Mask", ")", ")", "\n", "return", "i", ".", "Add", "(", "...
// NumNodes returns the number of IP node addresses in p.
[ "NumNodes", "returns", "the", "number", "of", "IP", "node", "addresses", "in", "p", "." ]
d465c8ab672111787b24b8f03326449059a4aa33
https://github.com/mikioh/ipaddr/blob/d465c8ab672111787b24b8f03326449059a4aa33/prefix.go#L217-L220
12,382
mikioh/ipaddr
prefix.go
Overlaps
func (p *Prefix) Overlaps(q *Prefix) bool { return p.Contains(q) || q.Contains(p) || p.Equal(q) }
go
func (p *Prefix) Overlaps(q *Prefix) bool { return p.Contains(q) || q.Contains(p) || p.Equal(q) }
[ "func", "(", "p", "*", "Prefix", ")", "Overlaps", "(", "q", "*", "Prefix", ")", "bool", "{", "return", "p", ".", "Contains", "(", "q", ")", "||", "q", ".", "Contains", "(", "p", ")", "||", "p", ".", "Equal", "(", "q", ")", "\n", "}" ]
// Overlaps reports whether p overlaps with q.
[ "Overlaps", "reports", "whether", "p", "overlaps", "with", "q", "." ]
d465c8ab672111787b24b8f03326449059a4aa33
https://github.com/mikioh/ipaddr/blob/d465c8ab672111787b24b8f03326449059a4aa33/prefix.go#L223-L225
12,383
mikioh/ipaddr
prefix.go
Subnets
func (p *Prefix) Subnets(n int) []Prefix { if 0 > n || n > 17 { // don't bother runtime.makeslice by big numbers return nil } ps := make([]Prefix, 1<<uint(n)) if p.IP.To4() != nil { x := ipToIPv4Int(p.IP) off := uint(IPv4PrefixLen - p.Len() - n) for i := range ps { ii := x | ipv4Int(i<<off) ps[i] = *i...
go
func (p *Prefix) Subnets(n int) []Prefix { if 0 > n || n > 17 { // don't bother runtime.makeslice by big numbers return nil } ps := make([]Prefix, 1<<uint(n)) if p.IP.To4() != nil { x := ipToIPv4Int(p.IP) off := uint(IPv4PrefixLen - p.Len() - n) for i := range ps { ii := x | ipv4Int(i<<off) ps[i] = *i...
[ "func", "(", "p", "*", "Prefix", ")", "Subnets", "(", "n", "int", ")", "[", "]", "Prefix", "{", "if", "0", ">", "n", "||", "n", ">", "17", "{", "// don't bother runtime.makeslice by big numbers", "return", "nil", "\n", "}", "\n", "ps", ":=", "make", ...
// Subnets returns a list of prefixes that are split from p, into // small address blocks by n which represents a number of subnetworks // in the power of 2 notation.
[ "Subnets", "returns", "a", "list", "of", "prefixes", "that", "are", "split", "from", "p", "into", "small", "address", "blocks", "by", "n", "which", "represents", "a", "number", "of", "subnetworks", "in", "the", "power", "of", "2", "notation", "." ]
d465c8ab672111787b24b8f03326449059a4aa33
https://github.com/mikioh/ipaddr/blob/d465c8ab672111787b24b8f03326449059a4aa33/prefix.go#L234-L257
12,384
mikioh/ipaddr
prefix.go
UnmarshalBinary
func (p *Prefix) UnmarshalBinary(b []byte) error { if p.IP.To4() != nil { binary.BigEndian.PutUint32(p.Mask, mask32(int(b[0]))) copy(p.IP, net.IPv4zero) copy(p.IP.To4(), b[1:]) } if p.IP.To16() != nil && p.IP.To4() == nil { var m ipv6Int m.mask(int(b[0])) binary.BigEndian.PutUint64(p.Mask[:8], m[0]) bi...
go
func (p *Prefix) UnmarshalBinary(b []byte) error { if p.IP.To4() != nil { binary.BigEndian.PutUint32(p.Mask, mask32(int(b[0]))) copy(p.IP, net.IPv4zero) copy(p.IP.To4(), b[1:]) } if p.IP.To16() != nil && p.IP.To4() == nil { var m ipv6Int m.mask(int(b[0])) binary.BigEndian.PutUint64(p.Mask[:8], m[0]) bi...
[ "func", "(", "p", "*", "Prefix", ")", "UnmarshalBinary", "(", "b", "[", "]", "byte", ")", "error", "{", "if", "p", ".", "IP", ".", "To4", "(", ")", "!=", "nil", "{", "binary", ".", "BigEndian", ".", "PutUint32", "(", "p", ".", "Mask", ",", "mas...
// UnmarshalBinary replaces p with the BGP NLRI binary form b.
[ "UnmarshalBinary", "replaces", "p", "with", "the", "BGP", "NLRI", "binary", "form", "b", "." ]
d465c8ab672111787b24b8f03326449059a4aa33
https://github.com/mikioh/ipaddr/blob/d465c8ab672111787b24b8f03326449059a4aa33/prefix.go#L260-L275
12,385
mikioh/ipaddr
prefix.go
UnmarshalText
func (p *Prefix) UnmarshalText(txt []byte) error { _, n, err := net.ParseCIDR(string(txt)) if err != nil { return err } copy(p.IP.To16(), n.IP.To16()) copy(p.Mask, n.Mask) return nil }
go
func (p *Prefix) UnmarshalText(txt []byte) error { _, n, err := net.ParseCIDR(string(txt)) if err != nil { return err } copy(p.IP.To16(), n.IP.To16()) copy(p.Mask, n.Mask) return nil }
[ "func", "(", "p", "*", "Prefix", ")", "UnmarshalText", "(", "txt", "[", "]", "byte", ")", "error", "{", "_", ",", "n", ",", "err", ":=", "net", ".", "ParseCIDR", "(", "string", "(", "txt", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return"...
// UnmarshalText replaces p with txt.
[ "UnmarshalText", "replaces", "p", "with", "txt", "." ]
d465c8ab672111787b24b8f03326449059a4aa33
https://github.com/mikioh/ipaddr/blob/d465c8ab672111787b24b8f03326449059a4aa33/prefix.go#L278-L286
12,386
mikioh/ipaddr
prefix.go
Aggregate
func Aggregate(ps []Prefix) []Prefix { ps = newSortedPrefixes(ps, sortAscending, true) sortByDescending(ps) switch len(ps) { case 0: return nil case 1: return ps[:1] } bfFn, superFn := branchingFactorIPv6, supernetIPv6 if ps[0].IP.To4() != nil { bfFn, superFn = branchingFactorIPv4, supernetIPv4 } ps = a...
go
func Aggregate(ps []Prefix) []Prefix { ps = newSortedPrefixes(ps, sortAscending, true) sortByDescending(ps) switch len(ps) { case 0: return nil case 1: return ps[:1] } bfFn, superFn := branchingFactorIPv6, supernetIPv6 if ps[0].IP.To4() != nil { bfFn, superFn = branchingFactorIPv4, supernetIPv4 } ps = a...
[ "func", "Aggregate", "(", "ps", "[", "]", "Prefix", ")", "[", "]", "Prefix", "{", "ps", "=", "newSortedPrefixes", "(", "ps", ",", "sortAscending", ",", "true", ")", "\n", "sortByDescending", "(", "ps", ")", "\n", "switch", "len", "(", "ps", ")", "{",...
// Aggregate aggregates ps and returns a list of aggregated prefixes.
[ "Aggregate", "aggregates", "ps", "and", "returns", "a", "list", "of", "aggregated", "prefixes", "." ]
d465c8ab672111787b24b8f03326449059a4aa33
https://github.com/mikioh/ipaddr/blob/d465c8ab672111787b24b8f03326449059a4aa33/prefix.go#L289-L305
12,387
mikioh/ipaddr
prefix.go
NewPrefix
func NewPrefix(n *net.IPNet) *Prefix { n.IP = n.IP.To16() return &Prefix{IPNet: *n} }
go
func NewPrefix(n *net.IPNet) *Prefix { n.IP = n.IP.To16() return &Prefix{IPNet: *n} }
[ "func", "NewPrefix", "(", "n", "*", "net", ".", "IPNet", ")", "*", "Prefix", "{", "n", ".", "IP", "=", "n", ".", "IP", ".", "To16", "(", ")", "\n", "return", "&", "Prefix", "{", "IPNet", ":", "*", "n", "}", "\n", "}" ]
// NewPrefix returns a new prefix.
[ "NewPrefix", "returns", "a", "new", "prefix", "." ]
d465c8ab672111787b24b8f03326449059a4aa33
https://github.com/mikioh/ipaddr/blob/d465c8ab672111787b24b8f03326449059a4aa33/prefix.go#L430-L433
12,388
mikioh/ipaddr
prefix.go
Summarize
func Summarize(first, last net.IP) []Prefix { if fip := first.To4(); fip != nil { lip := last.To4() if lip == nil { return nil } return summarizeIPv4(fip, lip) } if fip := first.To16(); fip != nil && fip.To4() == nil { lip := last.To16() if lip == nil || last.To4() != nil { return nil } return ...
go
func Summarize(first, last net.IP) []Prefix { if fip := first.To4(); fip != nil { lip := last.To4() if lip == nil { return nil } return summarizeIPv4(fip, lip) } if fip := first.To16(); fip != nil && fip.To4() == nil { lip := last.To16() if lip == nil || last.To4() != nil { return nil } return ...
[ "func", "Summarize", "(", "first", ",", "last", "net", ".", "IP", ")", "[", "]", "Prefix", "{", "if", "fip", ":=", "first", ".", "To4", "(", ")", ";", "fip", "!=", "nil", "{", "lip", ":=", "last", ".", "To4", "(", ")", "\n", "if", "lip", "=="...
// Summarize summarizes the address range from first to last and // returns a list of prefixes.
[ "Summarize", "summarizes", "the", "address", "range", "from", "first", "to", "last", "and", "returns", "a", "list", "of", "prefixes", "." ]
d465c8ab672111787b24b8f03326449059a4aa33
https://github.com/mikioh/ipaddr/blob/d465c8ab672111787b24b8f03326449059a4aa33/prefix.go#L437-L453
12,389
mikioh/ipaddr
prefix.go
Supernet
func Supernet(ps []Prefix) *Prefix { if len(ps) == 0 { return nil } if ps[0].IP.To4() != nil { ps = byAddrFamily(ps).newIPv4Prefixes() } if ps[0].IP.To16() != nil && ps[0].IP.To4() == nil { ps = byAddrFamily(ps).newIPv6Prefixes() } switch len(ps) { case 0: return nil case 1: return &ps[0] } if ps[0...
go
func Supernet(ps []Prefix) *Prefix { if len(ps) == 0 { return nil } if ps[0].IP.To4() != nil { ps = byAddrFamily(ps).newIPv4Prefixes() } if ps[0].IP.To16() != nil && ps[0].IP.To4() == nil { ps = byAddrFamily(ps).newIPv6Prefixes() } switch len(ps) { case 0: return nil case 1: return &ps[0] } if ps[0...
[ "func", "Supernet", "(", "ps", "[", "]", "Prefix", ")", "*", "Prefix", "{", "if", "len", "(", "ps", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n", "if", "ps", "[", "0", "]", ".", "IP", ".", "To4", "(", ")", "!=", "nil", "{", "ps", ...
// Supernet finds out a shortest common prefix for ps. // It returns nil when no suitable prefix is found.
[ "Supernet", "finds", "out", "a", "shortest", "common", "prefix", "for", "ps", ".", "It", "returns", "nil", "when", "no", "suitable", "prefix", "is", "found", "." ]
d465c8ab672111787b24b8f03326449059a4aa33
https://github.com/mikioh/ipaddr/blob/d465c8ab672111787b24b8f03326449059a4aa33/prefix.go#L513-L536
12,390
mikioh/ipaddr
cursor.go
First
func (c *Cursor) First() *Position { return &Position{IP: c.ps[0].IP, Prefix: c.ps[0]} }
go
func (c *Cursor) First() *Position { return &Position{IP: c.ps[0].IP, Prefix: c.ps[0]} }
[ "func", "(", "c", "*", "Cursor", ")", "First", "(", ")", "*", "Position", "{", "return", "&", "Position", "{", "IP", ":", "c", ".", "ps", "[", "0", "]", ".", "IP", ",", "Prefix", ":", "c", ".", "ps", "[", "0", "]", "}", "\n", "}" ]
// First returns the start position on c.
[ "First", "returns", "the", "start", "position", "on", "c", "." ]
d465c8ab672111787b24b8f03326449059a4aa33
https://github.com/mikioh/ipaddr/blob/d465c8ab672111787b24b8f03326449059a4aa33/cursor.go#L33-L35
12,391
mikioh/ipaddr
cursor.go
Last
func (c *Cursor) Last() *Position { return &Position{IP: c.ps[len(c.ps)-1].Last(), Prefix: c.ps[len(c.ps)-1]} }
go
func (c *Cursor) Last() *Position { return &Position{IP: c.ps[len(c.ps)-1].Last(), Prefix: c.ps[len(c.ps)-1]} }
[ "func", "(", "c", "*", "Cursor", ")", "Last", "(", ")", "*", "Position", "{", "return", "&", "Position", "{", "IP", ":", "c", ".", "ps", "[", "len", "(", "c", ".", "ps", ")", "-", "1", "]", ".", "Last", "(", ")", ",", "Prefix", ":", "c", ...
// Last returns the end position on c.
[ "Last", "returns", "the", "end", "position", "on", "c", "." ]
d465c8ab672111787b24b8f03326449059a4aa33
https://github.com/mikioh/ipaddr/blob/d465c8ab672111787b24b8f03326449059a4aa33/cursor.go#L38-L40
12,392
mikioh/ipaddr
cursor.go
Next
func (c *Cursor) Next() *Position { n := c.curr.cmp(&c.end) if n == 0 { if c.pi == len(c.ps)-1 { return nil } c.pi++ c.curr = ipToIPv6Int(c.ps[c.pi].IP.To16()) c.start = c.curr if c.ps[c.pi].IP.To4() != nil { c.end = c.ps[c.pi].lastIPv4MappedIPv6Int() } if c.ps[c.pi].IP.To16() != nil && c.ps[c.p...
go
func (c *Cursor) Next() *Position { n := c.curr.cmp(&c.end) if n == 0 { if c.pi == len(c.ps)-1 { return nil } c.pi++ c.curr = ipToIPv6Int(c.ps[c.pi].IP.To16()) c.start = c.curr if c.ps[c.pi].IP.To4() != nil { c.end = c.ps[c.pi].lastIPv4MappedIPv6Int() } if c.ps[c.pi].IP.To16() != nil && c.ps[c.p...
[ "func", "(", "c", "*", "Cursor", ")", "Next", "(", ")", "*", "Position", "{", "n", ":=", "c", ".", "curr", ".", "cmp", "(", "&", "c", ".", "end", ")", "\n", "if", "n", "==", "0", "{", "if", "c", ".", "pi", "==", "len", "(", "c", ".", "p...
// Next turns to the next position on c. // It returns nil at the end on c.
[ "Next", "turns", "to", "the", "next", "position", "on", "c", ".", "It", "returns", "nil", "at", "the", "end", "on", "c", "." ]
d465c8ab672111787b24b8f03326449059a4aa33
https://github.com/mikioh/ipaddr/blob/d465c8ab672111787b24b8f03326449059a4aa33/cursor.go#L49-L68
12,393
mikioh/ipaddr
cursor.go
Pos
func (c *Cursor) Pos() *Position { return &Position{IP: c.curr.ip(), Prefix: c.ps[c.pi]} }
go
func (c *Cursor) Pos() *Position { return &Position{IP: c.curr.ip(), Prefix: c.ps[c.pi]} }
[ "func", "(", "c", "*", "Cursor", ")", "Pos", "(", ")", "*", "Position", "{", "return", "&", "Position", "{", "IP", ":", "c", ".", "curr", ".", "ip", "(", ")", ",", "Prefix", ":", "c", ".", "ps", "[", "c", ".", "pi", "]", "}", "\n", "}" ]
// Pos returns the current position on c.
[ "Pos", "returns", "the", "current", "position", "on", "c", "." ]
d465c8ab672111787b24b8f03326449059a4aa33
https://github.com/mikioh/ipaddr/blob/d465c8ab672111787b24b8f03326449059a4aa33/cursor.go#L71-L73
12,394
mikioh/ipaddr
cursor.go
Prev
func (c *Cursor) Prev() *Position { n := c.curr.cmp(&c.start) if n == 0 { if c.pi == 0 { return nil } c.pi-- if c.ps[c.pi].IP.To4() != nil { c.curr = c.ps[c.pi].lastIPv4MappedIPv6Int() c.end = c.curr } if c.ps[c.pi].IP.To16() != nil && c.ps[c.pi].IP.To4() == nil { c.curr = c.ps[c.pi].lastIPv6I...
go
func (c *Cursor) Prev() *Position { n := c.curr.cmp(&c.start) if n == 0 { if c.pi == 0 { return nil } c.pi-- if c.ps[c.pi].IP.To4() != nil { c.curr = c.ps[c.pi].lastIPv4MappedIPv6Int() c.end = c.curr } if c.ps[c.pi].IP.To16() != nil && c.ps[c.pi].IP.To4() == nil { c.curr = c.ps[c.pi].lastIPv6I...
[ "func", "(", "c", "*", "Cursor", ")", "Prev", "(", ")", "*", "Position", "{", "n", ":=", "c", ".", "curr", ".", "cmp", "(", "&", "c", ".", "start", ")", "\n", "if", "n", "==", "0", "{", "if", "c", ".", "pi", "==", "0", "{", "return", "nil...
// Prev turns to the previous position on c. // It returns nil at the start on c.
[ "Prev", "turns", "to", "the", "previous", "position", "on", "c", ".", "It", "returns", "nil", "at", "the", "start", "on", "c", "." ]
d465c8ab672111787b24b8f03326449059a4aa33
https://github.com/mikioh/ipaddr/blob/d465c8ab672111787b24b8f03326449059a4aa33/cursor.go#L77-L97
12,395
mikioh/ipaddr
cursor.go
Reset
func (c *Cursor) Reset(ps []Prefix) { ps = newSortedPrefixes(ps, sortAscending, false) if len(ps) > 0 { c.ps = ps } c.set(0, c.ps[0].IP.To16()) }
go
func (c *Cursor) Reset(ps []Prefix) { ps = newSortedPrefixes(ps, sortAscending, false) if len(ps) > 0 { c.ps = ps } c.set(0, c.ps[0].IP.To16()) }
[ "func", "(", "c", "*", "Cursor", ")", "Reset", "(", "ps", "[", "]", "Prefix", ")", "{", "ps", "=", "newSortedPrefixes", "(", "ps", ",", "sortAscending", ",", "false", ")", "\n", "if", "len", "(", "ps", ")", ">", "0", "{", "c", ".", "ps", "=", ...
// Reset resets all state and switches to ps. // It uses the existing prefixes when ps is nil.
[ "Reset", "resets", "all", "state", "and", "switches", "to", "ps", ".", "It", "uses", "the", "existing", "prefixes", "when", "ps", "is", "nil", "." ]
d465c8ab672111787b24b8f03326449059a4aa33
https://github.com/mikioh/ipaddr/blob/d465c8ab672111787b24b8f03326449059a4aa33/cursor.go#L101-L107
12,396
mikioh/ipaddr
cursor.go
Set
func (c *Cursor) Set(pos *Position) error { if pos == nil { return errors.New("invalid position") } pi := -1 for i, p := range c.ps { if p.Equal(&pos.Prefix) { pi = i break } } if pi == -1 || !c.ps[pi].IPNet.Contains(pos.IP) { return errors.New("position out of range") } c.set(pi, pos.IP.To16()) ...
go
func (c *Cursor) Set(pos *Position) error { if pos == nil { return errors.New("invalid position") } pi := -1 for i, p := range c.ps { if p.Equal(&pos.Prefix) { pi = i break } } if pi == -1 || !c.ps[pi].IPNet.Contains(pos.IP) { return errors.New("position out of range") } c.set(pi, pos.IP.To16()) ...
[ "func", "(", "c", "*", "Cursor", ")", "Set", "(", "pos", "*", "Position", ")", "error", "{", "if", "pos", "==", "nil", "{", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "pi", ":=", "-", "1", "\n", "for", "i", ",", ...
// Set sets the current position on c to pos.
[ "Set", "sets", "the", "current", "position", "on", "c", "to", "pos", "." ]
d465c8ab672111787b24b8f03326449059a4aa33
https://github.com/mikioh/ipaddr/blob/d465c8ab672111787b24b8f03326449059a4aa33/cursor.go#L110-L126
12,397
mikioh/ipaddr
cursor.go
NewCursor
func NewCursor(ps []Prefix) *Cursor { ps = newSortedPrefixes(ps, sortAscending, false) if len(ps) == 0 { return nil } c := &Cursor{ps: ps} c.set(0, c.ps[0].IP.To16()) return c }
go
func NewCursor(ps []Prefix) *Cursor { ps = newSortedPrefixes(ps, sortAscending, false) if len(ps) == 0 { return nil } c := &Cursor{ps: ps} c.set(0, c.ps[0].IP.To16()) return c }
[ "func", "NewCursor", "(", "ps", "[", "]", "Prefix", ")", "*", "Cursor", "{", "ps", "=", "newSortedPrefixes", "(", "ps", ",", "sortAscending", ",", "false", ")", "\n", "if", "len", "(", "ps", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n", ...
// NewCursor returns a new cursor.
[ "NewCursor", "returns", "a", "new", "cursor", "." ]
d465c8ab672111787b24b8f03326449059a4aa33
https://github.com/mikioh/ipaddr/blob/d465c8ab672111787b24b8f03326449059a4aa33/cursor.go#L129-L137
12,398
mikioh/ipaddr
position.go
IsBroadcast
func (p *Position) IsBroadcast() bool { return !p.IP.IsUnspecified() && !p.IP.IsMulticast() && p.IP.To4() != nil && (p.IP.Equal(net.IPv4bcast) || p.IP.Equal(p.Prefix.Last())) }
go
func (p *Position) IsBroadcast() bool { return !p.IP.IsUnspecified() && !p.IP.IsMulticast() && p.IP.To4() != nil && (p.IP.Equal(net.IPv4bcast) || p.IP.Equal(p.Prefix.Last())) }
[ "func", "(", "p", "*", "Position", ")", "IsBroadcast", "(", ")", "bool", "{", "return", "!", "p", ".", "IP", ".", "IsUnspecified", "(", ")", "&&", "!", "p", ".", "IP", ".", "IsMulticast", "(", ")", "&&", "p", ".", "IP", ".", "To4", "(", ")", ...
// IsBroadcast reports whether p is an IPv4 directed or limited // broadcast address.
[ "IsBroadcast", "reports", "whether", "p", "is", "an", "IPv4", "directed", "or", "limited", "broadcast", "address", "." ]
d465c8ab672111787b24b8f03326449059a4aa33
https://github.com/mikioh/ipaddr/blob/d465c8ab672111787b24b8f03326449059a4aa33/position.go#L17-L19
12,399
mikioh/ipaddr
position.go
IsSubnetRouterAnycast
func (p *Position) IsSubnetRouterAnycast() bool { return !p.IP.IsUnspecified() && !p.IP.IsLoopback() && !p.IP.IsMulticast() && p.IP.To16() != nil && p.IP.To4() == nil && p.IP.Equal(p.Prefix.IP) }
go
func (p *Position) IsSubnetRouterAnycast() bool { return !p.IP.IsUnspecified() && !p.IP.IsLoopback() && !p.IP.IsMulticast() && p.IP.To16() != nil && p.IP.To4() == nil && p.IP.Equal(p.Prefix.IP) }
[ "func", "(", "p", "*", "Position", ")", "IsSubnetRouterAnycast", "(", ")", "bool", "{", "return", "!", "p", ".", "IP", ".", "IsUnspecified", "(", ")", "&&", "!", "p", ".", "IP", ".", "IsLoopback", "(", ")", "&&", "!", "p", ".", "IP", ".", "IsMult...
// IsSubnetRouterAnycast reports whether p is an IPv6 subnet router // anycast address.
[ "IsSubnetRouterAnycast", "reports", "whether", "p", "is", "an", "IPv6", "subnet", "router", "anycast", "address", "." ]
d465c8ab672111787b24b8f03326449059a4aa33
https://github.com/mikioh/ipaddr/blob/d465c8ab672111787b24b8f03326449059a4aa33/position.go#L23-L25