How to use timsort - 9 common examples

To help you get started, we’ve selected a few timsort examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fidelthomet / WHERE / where.js View on Github external
if (options.dist) {
		var user = turf.point(options.dist.split(","))
		filtered.forEach(function(feature) {
			if (feature.geometry.type == "Point") {
				// feature.properties.dist = getDistanceFromLatLonInM(feature.geometry.coordinates[0], feature.geometry.coordinates[1], user.geometry.coordinates[0], user.geometry.coordinates[1])
				feature.properties.dist = turf.distance(feature, user)
			}
		})
	}
	
	if (options.sortby) {
		// filtered.sort(h.propComparator(options));

		TimSort.sort(filtered, h.propComparator(options))
		// 
		
		// filtered = sort(filtered,options.sortby)
	}
	
	var total = filtered.length

	if (options.limit) {
		filtered = filtered.slice(options.page * options.limit, options.page * options.limit + parseInt(options.limit))
	}

	if (options.properties != -1) {
		if (!options.properties) {
			filtered.forEach(function(feature) {
				feature.properties = {}
			})
github visjs / vis-network / lib / network / modules / LayoutEngine.js View on Github external
let hubSizes = {};
    let nodeIds = this.body.nodeIndices;

    util.forEach(nodeIds, (nodeId) => { 
      let node = this.body.nodes[nodeId];
      let hubSize = this._getActiveEdges(node).length;
      hubSizes[hubSize] = true;
    });

    // Make an array of the size sorted descending
    let result = [];
    util.forEach(hubSizes, (size) => { 
      result.push(Number(size));
    });

    TimSort.sort(result, function(a, b) {
      return b - a;
    });

    return result;
  }
github lexicalunit / atom-notes / lib / notes-view-list.js View on Github external
filter (_, query) {
    let items = []
    if (!this.isLoaded()) return items
    if (query === undefined || query.length <= 0) {
      items = this.store.documents
      TimSort.sort(items, (lhs, rhs) => {
        if (lhs.modifiedAt > rhs.modifiedAt) return -1
        else if (lhs.modifiedAt < rhs.modifiedAt) return 1
        return 0
      })
    } else {
      items = this.store.search(query).filter(item => item !== undefined)

      if (atom.config.get('atom-notes.orderByFuzzyFileNameMatch')) {
        TimSort.sort(items, (lhs, rhs) => {
          if (query.length > 0) {
            const li = fp.score(lhs.title, query)
            const ri = fp.score(rhs.title, query)
            if (li > ri) return -1
            else if (li < ri) return 1
            return 0
          }
        })
      }
    }
    // docsearch returned nothing, fallback to fuzzy finder
    if (items.length <= 0) {
      return this.filteredItems
    }
    return items
  }
github visjs-community / visjs-network / lib / network / modules / components / DirectionStrategy.js View on Github external
sort(nodeArray) {
    TimSort.sort(nodeArray, function(a, b) {
      return a.x - b.x
    })
  }
github lexicalunit / atom-notes / lib / notes-view-list.js View on Github external
filter (_, query) {
    let items = []
    if (!this.isLoaded()) return items
    if (query === undefined || query.length <= 0) {
      items = this.store.documents
      TimSort.sort(items, (lhs, rhs) => {
        if (lhs.modifiedAt > rhs.modifiedAt) return -1
        else if (lhs.modifiedAt < rhs.modifiedAt) return 1
        return 0
      })
    } else {
      items = this.store.search(query).filter(item => item !== undefined)

      if (atom.config.get('atom-notes.orderByFuzzyFileNameMatch')) {
        TimSort.sort(items, (lhs, rhs) => {
          if (query.length > 0) {
            const li = fp.score(lhs.title, query)
            const ri = fp.score(rhs.title, query)
            if (li > ri) return -1
            else if (li < ri) return 1
            return 0
          }
github wazuh / wazuh-kibana-app / server / controllers / wazuh-reporting.js View on Github external
rowsparsed.length > 100 ? rowsparsed.slice(0, 99) : rowsparsed;
        this.dd.content.push({
          text: table.title,
          style: 'h3',
          pageBreak: 'before'
        });
        this.dd.content.push('\n');
        const full_body = [];
        const sortFunction = (a, b) =>
          parseInt(a[a.length - 1]) < parseInt(b[b.length - 1])
            ? 1
            : parseInt(a[a.length - 1]) > parseInt(b[b.length - 1])
            ? -1
            : 0;

        TimSort.sort(rows, sortFunction);

        const modifiedRows = [];
        for (const row of rows) {
          modifiedRows.push(
            row.map(cell => ({ text: cell || '-', style: 'standard' }))
          );
        }

        const widths = Array(table.columns.length - 1).fill('auto');
        widths.push('*');

        full_body.push(
          table.columns.map(col => ({
            text: col || '-',
            style: 'whiteColor',
            border: [0, 0, 0, 0]
github wazuh / wazuh-kibana-app / server / controllers / wazuh-reporting.js View on Github external
a.date < b.date ? 1 : a.date > b.date ? -1 : 0;
      fs.readdirSync(reportDir).forEach(file => {
        const stats = fs.statSync(reportDir + '/' + file);
        file = {
          name: file,
          size: stats.size,
          date: stats.birthtime
        };
        list.push(file);
      });
      log(
        'reporting:getReports',
        `Using TimSort for sorting ${list.length} items`,
        'debug'
      );
      TimSort.sort(list, sortFunction);
      log('reporting:getReports', `Total: ${list.length}`, 'debug');
      return { list };
    } catch (error) {
      log('reporting:getReports', error.message || error);
      return ErrorResponse(error.message || error, 5031, 500, reply);
    }
  }
github currency-cop / currency-cop / src / components / AppPortfolio / ItemList / index.js View on Github external
renderItems () {
    let items = this.props.items

    if (this.state.sort) {
      Timsort.sort(items, this.state.sort)
    }

    return items.map((details, index) => {
      return (
        
      )
    })
  }
}
github communitybridge / easycla / frontend-project-management-console / src / ionic / services / sort.service.ts View on Github external
toggleSort(config, prop, dataArray) {
    let current_sort = config[prop].sort;
    this.resetSort(config);
    if (current_sort == 'asc') {
      config[prop].sort = 'desc';
    } else {
      config[prop].sort = 'asc';
    }
    let sort = config[prop].sort;
    TimSort.sort(dataArray, this.sort(config[prop].arrayProp, config[prop].sortType, sort));
  }

timsort

TimSort: Fast Sorting for Node.js

MIT
Latest version published 8 years ago

Package Health Score

67 / 100
Full package analysis

Popular timsort functions