<commit_before>/* Copyright (C) 2013 CompleteDB LLC.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with PubSubSQL.  If not, see <http://www.gnu.org/licenses/>.
 */

package server

import "strconv"

// link
type link struct {
	pubsub *pubsub
	tg     *tag
}

func (this *link) clear() {
	this.pubsub = nil
	this.tg = nil
}

// record
type record struct {
	values []string
	links  []link
	prev   *record
	next   *record
}

// record factory
func newRecord(columns int, id int) *record {
	rec := record{
		values: make([]string, columns, columns),
	}
	rec.setValue(0, strconv.Itoa(id))
	return &rec
}

func (this *record) free() {
	this.values = nil
	this.links = nil
	this.prev = nil
	this.next = nil
}

// Returns record index in a table.
func (r *record) id() int {
	id, err := strconv.Atoi(r.values[0])
	if err != nil {
		panic("record id can not be 0")
	}
	return id
}

// Returns record index in a table as string.
func (r *record) idAsString() string {
	return r.values[0]
}

// Returns value based on column ordinal.
// Empty string is returned for invalid ordinal.
func (this *record) getValue(ordinal int) string {
	if len(this.values) > ordinal {
		return this.values[ordinal]
	}
	return ""
}

// Sets value based on column ordinal.
// Automatically adjusts the record if ordinal is invalid.
func (this *record) setValue(ordinal int, val string) {
	l := len(this.values)
	if l <= ordinal {
		delta := ordinal - l + 1
		temp := make([]string, delta)
		this.values = append(this.values, temp...)
	}
	this.values[ordinal] = val
}

// addSubscription adds subscription to the record.
func (this *record) addSubscription(sub *subscription) {
	pubsb := &this.links[0].pubsub
	if *pubsb == nil {
		*pubsb = new(pubsub)
	}
	pubsb.add(sub)
}<commit_msg>calling a method on double pointer is not allowed since go1.4<commit_after>/* Copyright (C) 2013 CompleteDB LLC.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with PubSubSQL.  If not, see <http://www.gnu.org/licenses/>.
 */

package server

import "strconv"

// link
type link struct {
	pubsub *pubsub
	tg     *tag
}

func (this *link) clear() {
	this.pubsub = nil
	this.tg = nil
}

// record
type record struct {
	values []string
	links  []link
	prev   *record
	next   *record
}

// record factory
func newRecord(columns int, id int) *record {
	rec := record{
		values: make([]string, columns, columns),
	}
	rec.setValue(0, strconv.Itoa(id))
	return &rec
}

func (this *record) free() {
	this.values = nil
	this.links = nil
	this.prev = nil
	this.next = nil
}

// Returns record index in a table.
func (r *record) id() int {
	id, err := strconv.Atoi(r.values[0])
	if err != nil {
		panic("record id can not be 0")
	}
	return id
}

// Returns record index in a table as string.
func (r *record) idAsString() string {
	return r.values[0]
}

// Returns value based on column ordinal.
// Empty string is returned for invalid ordinal.
func (this *record) getValue(ordinal int) string {
	if len(this.values) > ordinal {
		return this.values[ordinal]
	}
	return ""
}

// Sets value based on column ordinal.
// Automatically adjusts the record if ordinal is invalid.
func (this *record) setValue(ordinal int, val string) {
	l := len(this.values)
	if l <= ordinal {
		delta := ordinal - l + 1
		temp := make([]string, delta)
		this.values = append(this.values, temp...)
	}
	this.values[ordinal] = val
}

// addSubscription adds subscription to the record.
func (this *record) addSubscription(sub *subscription) {
	pubsb := this.links[0].pubsub
	if pubsb == nil {
		this.links[0].pubsub = new(pubsub)
		pubsb = this.links[0].pubsub
	}
	pubsb.add(sub)
}
{'fraction_non_alphanumeric': 0.11134676564156946, 'fraction_numerical': 0.005514316012725344, 'mean_word_length': 3.4957102001906577, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3049916', 'n_tokens_mistral': 1540, 'n_tokens_neox': 1499, 'n_words': 594}